static_casts to eliminate VC++ warnings.

This commit is contained in:
Harry Moffat 2004-07-02 17:27:01 +00:00
parent 5e9865869a
commit bd33838de9

View file

@ -6,7 +6,10 @@
// Copyright 2001 California Institute of Technology // Copyright 2001 California Institute of Technology
// //
// $Log$ // $Log$
// Revision 1.6 2004-07-02 16:48:13 hkmoffa // Revision 1.7 2004-07-02 17:27:01 hkmoffa
// static_casts to eliminate VC++ warnings.
//
// Revision 1.6 2004/07/02 16:48:13 hkmoffa
// Moved CK_SyntaxError definition to the .h file. It's used in more // Moved CK_SyntaxError definition to the .h file. It's used in more
// than one .cpp file. // than one .cpp file.
// //
@ -89,7 +92,7 @@ namespace ckr {
static double getNumberFromString(string s) { static double getNumberFromString(string s) {
bool inexp = false; bool inexp = false;
removeWhiteSpace(s); removeWhiteSpace(s);
int sz = s.size(); int sz = static_cast<int>(s.size());
char ch; char ch;
for (int n = 0; n < sz; n++) { for (int n = 0; n < sz; n++) {
@ -304,7 +307,7 @@ namespace ckr {
if (ch == '\n' || ch == char10) break; if (ch == '\n' || ch == char10) break;
if (isprint(ch)) line += ch; if (isprint(ch)) line += ch;
} }
int icom = line.find(commentChar); string::size_type icom = line.find(commentChar);
// lines that begin with !% are not comments for Cantera // lines that begin with !% are not comments for Cantera
if (icom == 0 && line[1] == undoCommentChar) { if (icom == 0 && line[1] == undoCommentChar) {
@ -312,7 +315,7 @@ namespace ckr {
line[1] = ' '; line[1] = ' ';
icom = line.find(commentChar); icom = line.find(commentChar);
} }
int len = line.size(); int len = static_cast<int>(line.size());
for (int i = 0; i < len; i++) if (!isprint(line[i])) line[i] = ' '; for (int i = 0; i < len; i++) if (!isprint(line[i])) line[i] = ' ';
if (icom >= 0) { if (icom >= 0) {
@ -390,8 +393,8 @@ next:
while (1 > 0) { while (1 > 0) {
do { do {
getCKLine(s, comment); getCKLine(s, comment);
getTokens(s, s.size(), toks); getTokens(s, static_cast<int>(s.size()), toks);
ntok = toks.size(); ntok = static_cast<int>(toks.size());
} while (ntok == 0); } while (ntok == 0);
if (firsttok == 0 && isKeyword(toks[0])) { if (firsttok == 0 && isKeyword(toks[0])) {
@ -404,7 +407,7 @@ next:
Element el; Element el;
string wtstr; string wtstr;
el.comment = comment; el.comment = comment;
el.index = elements.size(); el.index = static_cast<int>(elements.size());
if (extractSlashData(toks[i], el.name, wtstr)) { if (extractSlashData(toks[i], el.name, wtstr)) {
el.atomicWeight = atof(wtstr.c_str()); el.atomicWeight = atof(wtstr.c_str());
el.weightFromDB = false; el.weightFromDB = false;
@ -463,8 +466,8 @@ next:
while (1 > 0) { while (1 > 0) {
do { do {
getCKLine(s, comment); getCKLine(s, comment);
getTokens(s, s.size(), toks); getTokens(s, static_cast<int>(s.size()), toks);
ntok = toks.size(); ntok = static_cast<int>(toks.size());
} while (ntok == 0); } while (ntok == 0);
if (firsttok == 0 && isKeyword(toks[0])) { if (firsttok == 0 && isKeyword(toks[0])) {
@ -527,7 +530,7 @@ next:
tmax = temp[2]; tmax = temp[2];
} }
int nsp = names.size(); int nsp = static_cast<int>(names.size());
string comment; string comment;
@ -544,7 +547,7 @@ next:
while (!match(s,"THER")); while (!match(s,"THER"));
// read the tokens on the THERMO line // read the tokens on the THERMO line
getTokens(s, s.size(), toks); getTokens(s, static_cast<int>(s.size()), toks);
m_nasafmt = false; m_nasafmt = false;
if (toks.size() >= 2) if (toks.size() >= 2)
{ {
@ -568,7 +571,7 @@ next:
if (optionFlag == NoThermoDatabase || optionFlag == HasTempRange) { if (optionFlag == NoThermoDatabase || optionFlag == HasTempRange) {
getCKLine(s, comment); getCKLine(s, comment);
getTokens(s, s.size(), toks); getTokens(s, static_cast<int>(s.size()), toks);
if (toks.size() >= 3) { if (toks.size() >= 3) {
tmin = atof(toks[0].c_str()); tmin = atof(toks[0].c_str());
tmid = atof(toks[1].c_str()); tmid = atof(toks[1].c_str());
@ -642,7 +645,7 @@ next:
checkTemps(log, spec.tlow, spec.tmid, spec.thigh); checkTemps(log, spec.tlow, spec.tmid, spec.thigh);
if (getAllSpecies) { if (getAllSpecies) {
names.push_back(spec.name); names.push_back(spec.name);
nsp = names.size(); nsp = static_cast<int>(names.size());
} }
else else
nsp--; nsp--;
@ -686,7 +689,7 @@ next:
// extract the species name and the id string (date) // extract the species name and the id string (date)
string nameid = s.substr(0,24); string nameid = s.substr(0,24);
vector<string> toks; vector<string> toks;
getTokens(nameid, nameid.size(), toks); getTokens(nameid, static_cast<int>(nameid.size()), toks);
sp.name = toks[0]; sp.name = toks[0];
sp.id = ""; sp.id = "";
unsigned int j; unsigned int j;
@ -804,7 +807,7 @@ next:
// look for units specifications // look for units specifications
getTokens(s, s.size(), toks); getTokens(s, static_cast<int>(s.size()), toks);
string tok; string tok;
units.ActEnergy = Cal_per_Mole; units.ActEnergy = Cal_per_Mole;
units.Quantity = Moles; units.Quantity = Moles;
@ -855,7 +858,7 @@ next:
} }
// rxn line // rxn line
int eqloc; string::size_type eqloc;
string sleft, sright; string sleft, sright;
bool auxDataLine, metaDataLine; bool auxDataLine, metaDataLine;
@ -880,7 +883,8 @@ next:
elementNames, rg); elementNames, rg);
ierp = getGroups(s.begin() + eqloc, s.end(), ierp = getGroups(s.begin() + eqloc, s.end(),
elementNames, pg); elementNames, pg);
unsigned int nr = rxn.reactants.size(); unsigned int nr =
static_cast<unsigned int>(rxn.reactants.size());
unsigned int nratoms = 0; unsigned int nratoms = 0;
for (unsigned int ij = 0; ij < nr; ij++) for (unsigned int ij = 0; ij < nr; ij++)
nratoms += int(rxn.reactants[ij].number); nratoms += int(rxn.reactants[ij].number);
@ -893,7 +897,7 @@ next:
for (unsigned int ir = 0; ir < nr; ir++) { for (unsigned int ir = 0; ir < nr; ir++) {
rxn.reactants[ir].groups = rg[ir]; rxn.reactants[ir].groups = rg[ir];
} }
unsigned int np = rxn.products.size(); unsigned int np = static_cast<unsigned int>(rxn.products.size());
unsigned int npatoms = 0; unsigned int npatoms = 0;
for (unsigned int ik = 0; ik < np; ik++) for (unsigned int ik = 0; ik < np; ik++)
npatoms += int(rxn.products[ik].number); npatoms += int(rxn.products[ik].number);
@ -948,7 +952,7 @@ next:
else throw CK_SyntaxError(*m_log, else throw CK_SyntaxError(*m_log,
"expected <=>, =>, or =", m_line); "expected <=>, =>, or =", m_line);
int mloc, mloc2; string::size_type mloc, mloc2;
// process reactants // process reactants
removeWhiteSpace(sleft); removeWhiteSpace(sleft);
@ -986,8 +990,9 @@ next:
} }
} }
getSpecies(sleft.c_str(),sleft.size(),rxn.reactants); getSpecies(sleft.c_str(),static_cast<int>(sleft.size()),
int ir = rxn.reactants.size(); rxn.reactants);
int ir = static_cast<int>(rxn.reactants.size());
for (int iir = 0; iir < ir; iir++) { for (int iir = 0; iir < ir; iir++) {
if (find(speciesNames.begin(), speciesNames.end(), if (find(speciesNames.begin(), speciesNames.end(),
rxn.reactants[iir].name) >= speciesNames.end()) rxn.reactants[iir].name) >= speciesNames.end())
@ -998,8 +1003,8 @@ next:
// process Arrhenius coefficients // process Arrhenius coefficients
getTokens(sright, sright.size(), toks); getTokens(sright, static_cast<int>(sright.size()), toks);
int ntoks = toks.size(); int ntoks = static_cast<int>(toks.size());
if (ntoks < 3) { if (ntoks < 3) {
throw CK_SyntaxError(*m_log, throw CK_SyntaxError(*m_log,
"expected 3 Arrhenius parameters", m_line); "expected 3 Arrhenius parameters", m_line);
@ -1059,8 +1064,9 @@ next:
sright = sright.substr(0, mloc); sright = sright.substr(0, mloc);
} }
} }
getSpecies(sright.c_str(),sright.size(),rxn.products); getSpecies(sright.c_str(),static_cast<int>(sright.size()),
int ip = rxn.products.size(); rxn.products);
int ip = static_cast<int>(rxn.products.size());
for (int iip = 0; iip < ip; iip++) { for (int iip = 0; iip < ip; iip++) {
if (find(speciesNames.begin(), speciesNames.end(), if (find(speciesNames.begin(), speciesNames.end(),
rxn.products[iip].name) >= speciesNames.end()) rxn.products[iip].name) >= speciesNames.end())
@ -1095,7 +1101,7 @@ next:
vector<string> klow; vector<string> klow;
rxn.type = Falloff; rxn.type = Falloff;
if (hasAuxData) { if (hasAuxData) {
getTokens(data, data.size(), klow); getTokens(data, static_cast<int>(data.size()), klow);
if (klow.size() != 3) { if (klow.size() != 3) {
throw CK_SyntaxError(*m_log, throw CK_SyntaxError(*m_log,
"expected 3 low-pressure Arrhenius parameters", m_line); "expected 3 low-pressure Arrhenius parameters", m_line);
@ -1120,8 +1126,8 @@ next:
} }
if (hasAuxData) { if (hasAuxData) {
getTokens(data, data.size(), falloff); getTokens(data, static_cast<int>(data.size()), falloff);
int nf = falloff.size(); int nf = static_cast<int>(falloff.size());
double ff; double ff;
rxn.falloffType = Troe; rxn.falloffType = Troe;
for (int jf = 0; jf < nf; jf++) { for (int jf = 0; jf < nf; jf++) {
@ -1140,8 +1146,8 @@ next:
"cannot specify both SRI and TROE", m_line); "cannot specify both SRI and TROE", m_line);
} }
if (hasAuxData) { if (hasAuxData) {
getTokens(data, data.size(), falloff); getTokens(data, static_cast<int>(data.size()), falloff);
int nf = falloff.size(); int nf = static_cast<int>(falloff.size());
rxn.falloffType = SRI; rxn.falloffType = SRI;
double ff; double ff;
for (int jf = 0; jf < nf; jf++) { for (int jf = 0; jf < nf; jf++) {
@ -1164,7 +1170,7 @@ next:
"specified for reversible reactions", m_line); "specified for reversible reactions", m_line);
} }
if (hasAuxData) { if (hasAuxData) {
getTokens(data, data.size(), krev); getTokens(data, static_cast<int>(data.size()), krev);
if (krev.size() != 3) { if (krev.size() != 3) {
throw CK_SyntaxError(*m_log, throw CK_SyntaxError(*m_log,
"expected 3 Arrhenius parameters", m_line); "expected 3 Arrhenius parameters", m_line);
@ -1194,7 +1200,7 @@ next:
vector<string> bc; vector<string> bc;
rxn.kf.type = LandauTeller; rxn.kf.type = LandauTeller;
if (hasAuxData) { if (hasAuxData) {
getTokens(data, data.size(), bc); getTokens(data, static_cast<int>(data.size()), bc);
rxn.kf.B = atof(bc[0].c_str()); rxn.kf.B = atof(bc[0].c_str());
rxn.kf.C = atof(bc[1].c_str()); rxn.kf.C = atof(bc[1].c_str());
} }
@ -1206,7 +1212,7 @@ next:
vector<string> bc; vector<string> bc;
rxn.krev.type = LandauTeller; rxn.krev.type = LandauTeller;
if (hasAuxData) { if (hasAuxData) {
getTokens(data, data.size(), bc); getTokens(data, static_cast<int>(data.size()), bc);
rxn.krev.B = atof(bc[0].c_str()); rxn.krev.B = atof(bc[0].c_str());
rxn.krev.C = atof(bc[1].c_str()); rxn.krev.C = atof(bc[1].c_str());
} }
@ -1220,7 +1226,7 @@ next:
vector<string> khigh; vector<string> khigh;
rxn.type = ChemAct; rxn.type = ChemAct;
if (hasAuxData) { if (hasAuxData) {
getTokens(data, data.size(), khigh); getTokens(data, static_cast<int>(data.size()), khigh);
rxn.kf_aux.A = atof(khigh[0].c_str()); rxn.kf_aux.A = atof(khigh[0].c_str());
rxn.kf_aux.n = atof(khigh[1].c_str()); rxn.kf_aux.n = atof(khigh[1].c_str());
rxn.kf_aux.E = atof(khigh[2].c_str()); rxn.kf_aux.E = atof(khigh[2].c_str());
@ -1255,8 +1261,8 @@ next:
else { else {
Reaction::auxdata vals; Reaction::auxdata vals;
vector<string> toks; vector<string> toks;
getTokens(data, data.size(), toks); getTokens(data, static_cast<int>(data.size()), toks);
int ntoks = toks.size(); int ntoks = static_cast<int>(toks.size());
for (int itok = 0; itok < ntoks; itok++) { for (int itok = 0; itok < ntoks; itok++) {
vals.push_back(atof(toks[itok].c_str())); vals.push_back(atof(toks[itok].c_str()));
} }
@ -1279,14 +1285,14 @@ next:
string::const_iterator begin = s.begin(); string::const_iterator begin = s.begin();
string::const_iterator end = s.end(); string::const_iterator end = s.end();
vector<string>::iterator e; vector<string>::iterator e;
result.resize(esyms.size(),0); result.resize(static_cast<ct::ctvector_int::size_t>(esyms.size()),0);
for (; begin != end; ++begin) { for (; begin != end; ++begin) {
// new element // new element
if (*begin == '-') { if (*begin == '-') {
e = find(esyms.begin(), esyms.end(), sym); e = find(esyms.begin(), esyms.end(), sym);
if (e == esyms.end()) return -1; if (e == esyms.end()) return -1;
eindx = e - esyms.begin(); eindx = static_cast<int>(e - esyms.begin());
if (num != "") if (num != "")
i = atoi(num.c_str()); i = atoi(num.c_str());
else else