diff --git a/src/base/application.cpp b/src/base/application.cpp index c6c60c7ce..8ede85fef 100644 --- a/src/base/application.cpp +++ b/src/base/application.cpp @@ -366,7 +366,7 @@ long int Application::readStringRegistryKey(const std::string& keyName, const st void Application::Messages::popError() { - if (static_cast(errorMessage.size()) > 0) { + if (!errorMessage.empty()) { errorRoutine.pop_back() ; errorMessage.pop_back() ; } @@ -374,7 +374,7 @@ void Application::Messages::popError() std::string Application::Messages::lastErrorMessage() { - if (static_cast(errorMessage.size()) > 0) { + if (!errorMessage.empty()) { string head = "\n\n************************************************\n" " Cantera Error! \n" @@ -388,7 +388,7 @@ std::string Application::Messages::lastErrorMessage() void Application::Messages::getErrors(std::ostream& f) { - int i = static_cast(errorMessage.size()); + size_t i = errorMessage.size(); if (i == 0) { return; } @@ -397,8 +397,7 @@ void Application::Messages::getErrors(std::ostream& f) f << " Cantera Error! " << endl; f << "************************************************" << endl << endl; - int j; - for (j = 0; j < i; j++) { + for (size_t j = 0; j < i; j++) { f << endl; f << "Procedure: " << errorRoutine[j] << endl; f << "Error: " << errorMessage[j] << endl; @@ -410,7 +409,7 @@ void Application::Messages::getErrors(std::ostream& f) void Application::Messages::logErrors() { - int i = static_cast(errorMessage.size()); + size_t i = errorMessage.size(); if (i == 0) { return; } @@ -418,8 +417,7 @@ void Application::Messages::logErrors() writelog("************************************************\n"); writelog(" Cantera Error! \n"); writelog("************************************************\n\n"); - int j; - for (j = 0; j < i; j++) { + for (size_t j = 0; j < i; j++) { writelog("\n"); writelog(string("Procedure: ")+ errorRoutine[j]+" \n"); writelog(string("Error: ")+ errorMessage[j]+" \n"); @@ -516,12 +514,10 @@ std::string Application::findInputFile(const std::string& name) string inname; std::vector& dirs = inputDirs; - int nd; if (islash == string::npos && ibslash == string::npos) { - nd = static_cast(dirs.size()); - int i; + size_t nd = dirs.size(); inname = ""; - for (i = 0; i < nd; i++) { + for (size_t i = 0; i < nd; i++) { inname = dirs[i] + "/" + name; std::ifstream fin(inname.c_str()); if (fin) { @@ -533,9 +529,9 @@ std::string Application::findInputFile(const std::string& name) msg = "\nInput file " + name + " not found in director"; msg += (nd == 1 ? "y " : "ies "); - for (i = 0; i < nd; i++) { + for (size_t i = 0; i < nd; i++) { msg += "\n'" + dirs[i] + "'"; - if (i < nd-1) { + if (i+1 < nd) { msg += ", "; } } diff --git a/src/base/ctml.cpp b/src/base/ctml.cpp index 8406349fc..fc988f8e2 100644 --- a/src/base/ctml.cpp +++ b/src/base/ctml.cpp @@ -209,10 +209,9 @@ void getIntegers(const Cantera::XML_Node& node, { std::vector f; node.getChildren("integer",f); - int n = static_cast(f.size()); integer x; std::string typ, title, vmin, vmax; - for (int i = 0; i < n; i++) { + for (size_t i = 0; i < f.size(); i++) { const XML_Node& fi = *(f[i]); x = atoi(fi().c_str()); title = fi["title"]; @@ -232,10 +231,9 @@ void getFloats(const Cantera::XML_Node& node, std::map& v, "To be removed in Cantera 2.2."); std::vector f; node.getChildren("float",f); - int n = static_cast(f.size()); doublereal x, x0, x1, fctr; std::string typ, title, units, vmin, vmax; - for (int i = 0; i < n; i++) { + for (size_t i = 0; i < f.size(); i++) { const XML_Node& fi = *(f[i]); x = fpValue(fi()); x0 = Undef; @@ -510,9 +508,8 @@ void getMap(const Cantera::XML_Node& node, std::map& m std::vector v; getStringArray(node, v); std::string key, val; - int n = static_cast(v.size()); string::size_type icolon; - for (int i = 0; i < n; i++) { + for (size_t i = 0; i < v.size(); i++) { icolon = v[i].find(":"); if (icolon == string::npos) { throw CanteraError("getMap","missing colon in map entry (" diff --git a/src/base/plots.cpp b/src/base/plots.cpp index 3fe978f4a..bf17c7955 100644 --- a/src/base/plots.cpp +++ b/src/base/plots.cpp @@ -36,23 +36,20 @@ void outputTEC(std::ostream& s, const std::string& title, const std::vector& names, const Array2D& data) { - int i,j; - int npts = static_cast(data.nColumns()); - int nv = static_cast(data.nRows()); s << "TITLE = \"" + title + "\"" << endl; s << "VARIABLES = " << endl; - for (i = 0; i < nv; i++) { + for (size_t i = 0; i < data.nRows(); i++) { s << "\"" << names[i] << "\"" << endl; } s << "ZONE T=\"zone1\"" << endl; - s << " I=" << npts << ",J=1,K=1,F=POINT" << endl; + s << " I=" << data.nColumns() << ",J=1,K=1,F=POINT" << endl; s << "DT=( "; - for (i = 0; i < nv; i++) { + for (size_t i = 0; i < data.nRows(); i++) { s << " SINGLE"; } s << " )" << endl; - for (i = 0; i < npts; i++) { - for (j = 0; j < nv; j++) { + for (size_t i = 0; i < data.nColumns(); i++) { + for (size_t j = 0; j < data.nRows(); j++) { s << data(j,i) << " "; } s << endl; @@ -63,21 +60,18 @@ void outputExcel(std::ostream& s, const std::string& title, const std::vector& names, const Array2D& data) { - int i,j; - int npts = static_cast(data.nColumns()); - int nv = static_cast(data.nRows()); s << title + "," << endl; - for (i = 0; i < nv; i++) { + for (size_t i = 0; i < data.nRows(); i++) { s << names[i]; - if (i != nv-1) { + if (i != data.nRows()-1) { s << ","; } } s << endl; - for (i = 0; i < npts; i++) { - for (j = 0; j < nv; j++) { + for (size_t i = 0; i < data.nColumns(); i++) { + for (size_t j = 0; j < data.nRows(); j++) { s << data(j,i); - if (j != nv-1) { + if (j != data.nRows()-1) { s << ","; } } diff --git a/src/base/stringUtils.cpp b/src/base/stringUtils.cpp index 21622f4f8..ab4e92349 100644 --- a/src/base/stringUtils.cpp +++ b/src/base/stringUtils.cpp @@ -57,9 +57,8 @@ std::string int2str(const size_t n) std::string lowercase(const std::string& s) { - int n = static_cast(s.size()); std::string lc(s); - for (int i = 0; i < n; i++) { + for (size_t i = 0; i < s.size(); i++) { lc[i] = (char) tolower(s[i]); } return lc; @@ -109,10 +108,8 @@ std::string stripws(const std::string& s) std::string stripnonprint(const std::string& s) { - int i; - int n = static_cast(s.size()); std::string ss = ""; - for (i = 0; i < n; i++) { + for (size_t i = 0; i < s.size(); i++) { if (isprint(s[i])) { ss += s[i]; } diff --git a/src/base/units.h b/src/base/units.h index b8d1e7aca..482a988cc 100644 --- a/src/base/units.h +++ b/src/base/units.h @@ -77,7 +77,6 @@ public: } doublereal f = 1.0, fctr; - int tsize; std::string u = units_, tok, tsub; std::string::size_type k; char action = '-'; @@ -92,7 +91,7 @@ public: } else { tok = u; } - tsize = static_cast(tok.size()); + size_t tsize = tok.size(); if (tsize == 0) { fctr = 1.0; } else if (tok[tsize - 1] == '2') { diff --git a/src/base/xml.cpp b/src/base/xml.cpp index e14d06cae..b6839f039 100644 --- a/src/base/xml.cpp +++ b/src/base/xml.cpp @@ -343,8 +343,7 @@ XML_Node::XML_Node(const XML_Node& right) : XML_Node& XML_Node::operator=(const XML_Node& right) { if (&right != this) { - int n = static_cast(m_children.size()); - for (int i = 0; i < n; i++) { + for (size_t i = 0; i < m_children.size(); i++) { if (m_children[i]) { if (m_children[i]->parent() == this) { delete m_children[i]; @@ -363,8 +362,7 @@ XML_Node::~XML_Node() if (m_locked) { writelog("XML_Node::~XML_Node: deleted a locked XML_Node: "+name()); } - int n = static_cast(m_children.size()); - for (int i = 0; i < n; i++) { + for (size_t i = 0; i < m_children.size(); i++) { if (m_children[i]) { if (m_children[i]->parent() == this) { delete m_children[i]; @@ -376,8 +374,7 @@ XML_Node::~XML_Node() void XML_Node::clear() { - int n = static_cast(m_children.size()); - for (int i = 0; i < n; i++) { + for (size_t i = 0; i < m_children.size(); i++) { if (m_children[i]) { if (m_children[i]->parent() == this) { delete m_children[i]; @@ -948,8 +945,7 @@ void XML_Node::write_int(std::ostream& s, int level, int numRecursivesAllowed) c s << " "; } s << m_value; - int ll = static_cast(m_value.size()) - 1; - if (! isspace(m_value[ll])) { + if (! isspace(m_value[m_value.size()-1])) { s << " "; } s << "-->"; @@ -987,10 +983,10 @@ void XML_Node::write_int(std::ostream& s, int level, int numRecursivesAllowed) c } vv = vv.substr(ieol+1); } else { - int lll = static_cast(vv.size()) - 1; - if (lll >= 0) { - int jf = lll; - for (int j = 0; j < lll; j++) { + size_t lll = vv.size() - 1; + if (lll != npos) { + size_t jf = lll; + for (size_t j = 0; j < lll; j++) { if (! isspace(vv[j])) { jf = j; break; @@ -1007,7 +1003,7 @@ void XML_Node::write_int(std::ostream& s, int level, int numRecursivesAllowed) c } else { bool doSpace = true; bool doNewLine = false; - int ll = static_cast(m_value.size()) - 1; + size_t ll = m_value.size() - 1; if (ll > 25) { doNewLine = true; } diff --git a/src/clib/Cabinet.h b/src/clib/Cabinet.h index 5618af6a1..c75db311f 100644 --- a/src/clib/Cabinet.h +++ b/src/clib/Cabinet.h @@ -118,8 +118,7 @@ public: */ static int clear() { dataRef data = getData(); - int n = static_cast(data.size()); - for (int i = 1; i < n; i++) { + for (size_t i = 1; i < data.size(); i++) { del(i); } if (canDelete) { diff --git a/src/kinetics/importKinetics.cpp b/src/kinetics/importKinetics.cpp index c67eb0c4e..f6bb14f78 100644 --- a/src/kinetics/importKinetics.cpp +++ b/src/kinetics/importKinetics.cpp @@ -402,8 +402,8 @@ static void getFalloff(const XML_Node& f, ReactionData& rdata) vector p; getStringArray(f,p); vector_fp c; - int np = static_cast(p.size()); - for (int n = 0; n < np; n++) { + size_t np = p.size(); + for (size_t n = 0; n < np; n++) { c.push_back(fpValue(p[n])); } if (type == "Troe") { @@ -825,12 +825,11 @@ bool installReactionArrays(const XML_Node& p, Kinetics& kin, * end result being purely additive. */ p.getChildren("reactionArray",rarrays); - int na = static_cast(rarrays.size()); - if (na == 0) { + if (rarrays.empty()) { kin.finalize(); return false; } - for (int n = 0; n < na; n++) { + for (size_t n = 0; n < rarrays.size(); n++) { /* * Go get a reference to the current xml element, * reactionArray. We will process this element now. @@ -868,7 +867,6 @@ bool installReactionArrays(const XML_Node& p, Kinetics& kin, rxnrule.skipUndeclaredThirdBodies = true; } } - int i, nrxns = 0; /* * Search for child elements called include. We only include * a reaction if it's tagged by one of the include fields. @@ -876,14 +874,12 @@ bool installReactionArrays(const XML_Node& p, Kinetics& kin, */ vector incl; rxns.getChildren("include",incl); - int ninc = static_cast(incl.size()); vector allrxns; rdata->getChildren("reaction",allrxns); - nrxns = static_cast(allrxns.size()); // if no 'include' directive, then include all reactions - if (ninc == 0) { - for (i = 0; i < nrxns; i++) { + if (incl.empty()) { + for (size_t i = 0; i < allrxns.size(); i++) { const XML_Node* r = allrxns[i]; if (r) { if (_rxns.installReaction(itot, *r, kin, @@ -893,7 +889,7 @@ bool installReactionArrays(const XML_Node& p, Kinetics& kin, } } } else { - for (int nii = 0; nii < ninc; nii++) { + for (size_t nii = 0; nii < incl.size(); nii++) { const XML_Node& ii = *incl[nii]; string imin = ii["min"]; string imax = ii["max"]; @@ -907,7 +903,7 @@ bool installReactionArrays(const XML_Node& p, Kinetics& kin, } } - for (i = 0; i < nrxns; i++) { + for (size_t i = 0; i < allrxns.size(); i++) { const XML_Node* r = allrxns[i]; string rxid; if (r) { diff --git a/src/oneD/StFlow.cpp b/src/oneD/StFlow.cpp index 624e440ee..6d9d3cb30 100644 --- a/src/oneD/StFlow.cpp +++ b/src/oneD/StFlow.cpp @@ -598,8 +598,7 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel) vector str; dom.getChildren("string",str); - int nstr = static_cast(str.size()); - for (int istr = 0; istr < nstr; istr++) { + for (size_t istr = 0; istr < str.size(); istr++) { const XML_Node& nd = *str[istr]; writelog(nd["title"]+": "+nd.value()+"\n"); } diff --git a/src/thermo/DebyeHuckel.cpp b/src/thermo/DebyeHuckel.cpp index a133e7ccb..8f862b455 100644 --- a/src/thermo/DebyeHuckel.cpp +++ b/src/thermo/DebyeHuckel.cpp @@ -705,8 +705,7 @@ initThermoXML(XML_Node& phaseNode, const std::string& id_) XML_Node& scNode = thermoNode.child("solvent"); vector nameSolventa; getStringArray(scNode, nameSolventa); - int nsp = static_cast(nameSolventa.size()); - if (nsp != 1) { + if (nameSolventa.size() != 1) { throw CanteraError("DebyeHuckel::initThermoXML", "badly formed solvent XML node"); } diff --git a/src/thermo/HMWSoln_input.cpp b/src/thermo/HMWSoln_input.cpp index 72f9388e2..994852351 100644 --- a/src/thermo/HMWSoln_input.cpp +++ b/src/thermo/HMWSoln_input.cpp @@ -1058,8 +1058,7 @@ void HMWSoln::constructPhaseXML(XML_Node& phaseNode, std::string id_) XML_Node& scNode = thermoNode.child("solvent"); vector nameSolventa; getStringArray(scNode, nameSolventa); - int nsp = static_cast(nameSolventa.size()); - if (nsp != 1) { + if (nameSolventa.size() != 1) { throw CanteraError("HMWSoln::constructPhaseXML", "badly formed solvent XML node"); } @@ -1243,8 +1242,7 @@ initThermoXML(XML_Node& phaseNode, const std::string& id_) XML_Node& scNode = thermoNode.child("solvent"); vector nameSolventa; getStringArray(scNode, nameSolventa); - int nsp = static_cast(nameSolventa.size()); - if (nsp != 1) { + if (nameSolventa.size() != 1) { throw CanteraError("HMWSoln::initThermoXML", "badly formed solvent XML node"); } diff --git a/src/thermo/IdealMolalSoln.cpp b/src/thermo/IdealMolalSoln.cpp index dfadb865d..715fb25a8 100644 --- a/src/thermo/IdealMolalSoln.cpp +++ b/src/thermo/IdealMolalSoln.cpp @@ -561,8 +561,7 @@ void IdealMolalSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_) XML_Node& scNode = thermoNode.child("solvent"); std::vector nameSolventa; getStringArray(scNode, nameSolventa); - int nsp = static_cast(nameSolventa.size()); - if (nsp != 1) { + if (nameSolventa.size() != 1) { throw CanteraError("IdealMolalSoln::initThermoXML", "badly formed solvent XML node"); } diff --git a/src/thermo/Phase.cpp b/src/thermo/Phase.cpp index 52c4dc3dc..ae77b5dbc 100644 --- a/src/thermo/Phase.cpp +++ b/src/thermo/Phase.cpp @@ -763,12 +763,8 @@ void Phase::addElementsFromXML(const XML_Node& phase) } } - int nel = static_cast(enames.size()); - int i; - string enm; - XML_Node* e = 0; - for (i = 0; i < nel; i++) { - e = 0; + for (size_t i = 0; i < enames.size(); i++) { + XML_Node* e = 0; if (local_db) { //writelog("looking in local database."); e = local_db->findByAttr("name",enames[i]); diff --git a/src/thermo/SpeciesThermoFactory.cpp b/src/thermo/SpeciesThermoFactory.cpp index 69788b56d..cc7788104 100644 --- a/src/thermo/SpeciesThermoFactory.cpp +++ b/src/thermo/SpeciesThermoFactory.cpp @@ -676,15 +676,13 @@ void SpeciesThermoFactory::installThermoForSpecies // These shouldn't interfere with the algorithm at any point. const std::vector& tpWC = thermo.children(); std::vector tp; - for (int i = 0; i < static_cast(tpWC.size()); i++) { + for (size_t i = 0; i < tpWC.size(); i++) { if (!(tpWC[i])->isComment()) { tp.push_back(tpWC[i]); } } - int nc = static_cast(tp.size()); - string mname = thermo["model"]; - if (mname == "MineralEQ3") { + if (thermo["model"] == "MineralEQ3") { const XML_Node* f = tp[0]; if (f->name() != "MinEQ3") { throw CanteraError("SpeciesThermoFactory::installThermoForSpecies", @@ -692,7 +690,7 @@ void SpeciesThermoFactory::installThermoForSpecies } installMinEQ3asShomateThermoFromXML(speciesNode["name"], th_ptr, spthermo, k, f); } else { - if (nc == 1) { + if (tp.size() == 1) { const XML_Node* f = tp[0]; if (f->name() == "Shomate") { installShomateThermoFromXML(speciesNode["name"], spthermo, k, f, 0); @@ -712,7 +710,7 @@ void SpeciesThermoFactory::installThermoForSpecies throw UnknownSpeciesThermoModel("installThermoForSpecies", speciesNode["name"], f->name()); } - } else if (nc == 2) { + } else if (tp.size() == 2) { const XML_Node* f0 = tp[0]; const XML_Node* f1 = tp[1]; if (f0->name() == "NASA" && f1->name() == "NASA") { @@ -727,7 +725,7 @@ void SpeciesThermoFactory::installThermoForSpecies throw UnknownSpeciesThermoModel("installThermoForSpecies", speciesNode["name"], f0->name() + " and " + f1->name()); } - } else if (nc > 2) { + } else if (tp.size() > 2) { const XML_Node* f0 = tp[0]; if (f0->name() == "NASA9") { installNasa9ThermoFromXML(speciesNode["name"], spthermo, k, tp); diff --git a/src/thermo/ThermoFactory.cpp b/src/thermo/ThermoFactory.cpp index a252ab64a..0c86e8c99 100644 --- a/src/thermo/ThermoFactory.cpp +++ b/src/thermo/ThermoFactory.cpp @@ -476,9 +476,8 @@ bool importPhase(XML_Node& phase, ThermoPhase* th, XML_Node* db = 0; vector sparrays; phase.getChildren("speciesArray", sparrays); - int jsp, nspa = static_cast(sparrays.size()); if (ssConvention != cSS_CONVENTION_SLAVE) { - if (nspa == 0) { + if (sparrays.empty()) { throw CanteraError("importPhase", "phase, " + th->id() + ", has zero \"speciesArray\" XML nodes.\n" + " There must be at least one speciesArray nodes " @@ -486,10 +485,10 @@ bool importPhase(XML_Node& phase, ThermoPhase* th, } } vector dbases; - vector_int sprule(nspa,0); + vector_int sprule(sparrays.size(),0); // loop over the speciesArray elements - for (jsp = 0; jsp < nspa; jsp++) { + for (size_t jsp = 0; jsp < sparrays.size(); jsp++) { const XML_Node& speciesArray = *sparrays[jsp]; diff --git a/src/zeroD/ReactorBase.cpp b/src/zeroD/ReactorBase.cpp index 0187fb20a..47dc0f06b 100644 --- a/src/zeroD/ReactorBase.cpp +++ b/src/zeroD/ReactorBase.cpp @@ -86,9 +86,8 @@ void ReactorBase::setNetwork(ReactorNet* net) doublereal ReactorBase::residenceTime() { - int nout = static_cast(m_outlet.size()); doublereal mout = 0.0; - for (int i = 0; i < nout; i++) { + for (size_t i = 0; i < m_outlet.size(); i++) { mout += m_outlet[i]->massFlowRate(); } return mass()/mout;