Remove unnecessary use of static_cast<int>

This commit is contained in:
Ray Speth 2014-01-31 23:15:09 +00:00
parent 3dc335565c
commit d516d46f33
16 changed files with 60 additions and 99 deletions

View file

@ -366,7 +366,7 @@ long int Application::readStringRegistryKey(const std::string& keyName, const st
void Application::Messages::popError()
{
if (static_cast<int>(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<int>(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<int>(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<int>(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<string>& dirs = inputDirs;
int nd;
if (islash == string::npos && ibslash == string::npos) {
nd = static_cast<int>(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 += ", ";
}
}

View file

@ -209,10 +209,9 @@ void getIntegers(const Cantera::XML_Node& node,
{
std::vector<XML_Node*> f;
node.getChildren("integer",f);
int n = static_cast<int>(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<std::string, double>& v,
"To be removed in Cantera 2.2.");
std::vector<XML_Node*> f;
node.getChildren("float",f);
int n = static_cast<int>(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<std::string, std::string>& m
std::vector<std::string> v;
getStringArray(node, v);
std::string key, val;
int n = static_cast<int>(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 ("

View file

@ -36,23 +36,20 @@ void outputTEC(std::ostream& s, const std::string& title,
const std::vector<std::string>& names,
const Array2D& data)
{
int i,j;
int npts = static_cast<int>(data.nColumns());
int nv = static_cast<int>(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<std::string>& names,
const Array2D& data)
{
int i,j;
int npts = static_cast<int>(data.nColumns());
int nv = static_cast<int>(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 << ",";
}
}

View file

@ -57,9 +57,8 @@ std::string int2str(const size_t n)
std::string lowercase(const std::string& s)
{
int n = static_cast<int>(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<int>(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];
}

View file

@ -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<int>(tok.size());
size_t tsize = tok.size();
if (tsize == 0) {
fctr = 1.0;
} else if (tok[tsize - 1] == '2') {

View file

@ -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<int>(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<int>(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<int>(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<int>(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<int>(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<int>(m_value.size()) - 1;
size_t ll = m_value.size() - 1;
if (ll > 25) {
doNewLine = true;
}

View file

@ -118,8 +118,7 @@ public:
*/
static int clear() {
dataRef data = getData();
int n = static_cast<int>(data.size());
for (int i = 1; i < n; i++) {
for (size_t i = 1; i < data.size(); i++) {
del(i);
}
if (canDelete) {

View file

@ -402,8 +402,8 @@ static void getFalloff(const XML_Node& f, ReactionData& rdata)
vector<string> p;
getStringArray(f,p);
vector_fp c;
int np = static_cast<int>(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<int>(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<XML_Node*> incl;
rxns.getChildren("include",incl);
int ninc = static_cast<int>(incl.size());
vector<XML_Node*> allrxns;
rdata->getChildren("reaction",allrxns);
nrxns = static_cast<int>(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) {

View file

@ -598,8 +598,7 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel)
vector<XML_Node*> str;
dom.getChildren("string",str);
int nstr = static_cast<int>(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");
}

View file

@ -705,8 +705,7 @@ initThermoXML(XML_Node& phaseNode, const std::string& id_)
XML_Node& scNode = thermoNode.child("solvent");
vector<std::string> nameSolventa;
getStringArray(scNode, nameSolventa);
int nsp = static_cast<int>(nameSolventa.size());
if (nsp != 1) {
if (nameSolventa.size() != 1) {
throw CanteraError("DebyeHuckel::initThermoXML",
"badly formed solvent XML node");
}

View file

@ -1058,8 +1058,7 @@ void HMWSoln::constructPhaseXML(XML_Node& phaseNode, std::string id_)
XML_Node& scNode = thermoNode.child("solvent");
vector<string> nameSolventa;
getStringArray(scNode, nameSolventa);
int nsp = static_cast<int>(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<string> nameSolventa;
getStringArray(scNode, nameSolventa);
int nsp = static_cast<int>(nameSolventa.size());
if (nsp != 1) {
if (nameSolventa.size() != 1) {
throw CanteraError("HMWSoln::initThermoXML",
"badly formed solvent XML node");
}

View file

@ -561,8 +561,7 @@ void IdealMolalSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_)
XML_Node& scNode = thermoNode.child("solvent");
std::vector<std::string> nameSolventa;
getStringArray(scNode, nameSolventa);
int nsp = static_cast<int>(nameSolventa.size());
if (nsp != 1) {
if (nameSolventa.size() != 1) {
throw CanteraError("IdealMolalSoln::initThermoXML",
"badly formed solvent XML node");
}

View file

@ -763,12 +763,8 @@ void Phase::addElementsFromXML(const XML_Node& phase)
}
}
int nel = static_cast<int>(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]);

View file

@ -676,15 +676,13 @@ void SpeciesThermoFactory::installThermoForSpecies
// These shouldn't interfere with the algorithm at any point.
const std::vector<XML_Node*>& tpWC = thermo.children();
std::vector<XML_Node*> tp;
for (int i = 0; i < static_cast<int>(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<int>(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);

View file

@ -476,9 +476,8 @@ bool importPhase(XML_Node& phase, ThermoPhase* th,
XML_Node* db = 0;
vector<XML_Node*> sparrays;
phase.getChildren("speciesArray", sparrays);
int jsp, nspa = static_cast<int>(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<XML_Node*> 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];

View file

@ -86,9 +86,8 @@ void ReactorBase::setNetwork(ReactorNet* net)
doublereal ReactorBase::residenceTime()
{
int nout = static_cast<int>(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;