Some cleanup of clib

Removing unnecessary explicit char* to string conversions
This commit is contained in:
Ray Speth 2012-08-02 15:48:16 +00:00
parent 38fbe6781e
commit f2a1aa219b
8 changed files with 80 additions and 151 deletions

View file

@ -148,8 +148,7 @@ extern "C" {
size_t phase_elementIndex(int n, char* nm)
{
try {
string elnm = string(nm);
return ThermoCabinet::item(n).elementIndex(elnm);
return ThermoCabinet::item(n).elementIndex(nm);
} catch (...) {
return handleAllExceptions(npos, npos);
}
@ -158,8 +157,7 @@ extern "C" {
size_t phase_speciesIndex(int n, char* nm)
{
try {
string spnm = string(nm);
return ThermoCabinet::item(n).speciesIndex(spnm);
return ThermoCabinet::item(n).speciesIndex(nm);
} catch (...) {
return handleAllExceptions(npos, npos);
}
@ -232,7 +230,7 @@ extern "C" {
for (size_t n = 0; n < nsp; n++) {
xx[p.speciesName(n)] = -1;
}
parseCompString(string(x), xx);
parseCompString(x, xx);
p.setMoleFractionsByName(xx);
return 0;
} catch (...) {
@ -266,7 +264,7 @@ extern "C" {
for (size_t n = 0; n < nsp; n++) {
yy[p.speciesName(n)] = -1;
}
parseCompString(string(y), yy);
parseCompString(y, yy);
p.setMassFractionsByName(yy);
return 0;
} catch (...) {
@ -316,8 +314,7 @@ extern "C" {
int phase_setName(int n, const char* nm)
{
try {
string name = string(nm);
ThermoCabinet::item(n).setName(name);
ThermoCabinet::item(n).setName(nm);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -363,7 +360,7 @@ extern "C" {
int phase_addElement(int n, char* name, doublereal weight)
{
try {
ThermoCabinet::item(n).addElement(string(name),weight);
ThermoCabinet::item(n).addElement(name, weight);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -829,8 +826,7 @@ extern "C" {
try {
XML_Node& p = XmlCabinet::item(pxml);
Kinetics& k = KineticsCabinet::item(ikin);
string defphase = string(default_phase);
installReactionArrays(p, k, defphase);
installReactionArrays(p, k, default_phase);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -859,8 +855,7 @@ extern "C" {
size_t kin_speciesIndex(int n, const char* nm, const char* ph)
{
try {
return KineticsCabinet::item(n).kineticsSpeciesIndex(string(nm),
string(ph));
return KineticsCabinet::item(n).kineticsSpeciesIndex(nm, ph);
} catch (...) {
return handleAllExceptions(npos, npos);
}
@ -898,7 +893,7 @@ extern "C" {
size_t kin_phaseIndex(int n, char* ph)
{
try {
return KineticsCabinet::item(n).phaseIndex(string(ph));
return KineticsCabinet::item(n).phaseIndex(ph);
} catch (...) {
return handleAllExceptions(npos, npos);
}
@ -1011,12 +1006,8 @@ extern "C" {
{
try {
Kinetics& k = KineticsCabinet::item(n);
bool doirrev = false;
if (doIrreversible != 0) {
doirrev = true;
}
k.checkReactionArraySize(len);
k.getRevRateConstants(krev, doirrev);
k.getRevRateConstants(krev, doIrreversible != 0);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -1110,14 +1101,12 @@ extern "C" {
// @todo This function only works for single phase kinetics
Kinetics& k = KineticsCabinet::item(n);
ThermoPhase& p = k.thermo();
const vector_fp& mw = p.molecularWeights();
size_t nsp = mw.size();
double rrho = 1.0/p.density();
size_t nsp = p.nSpecies();
k.checkSpeciesArraySize(len);
k.checkSpeciesArraySize(nsp);
k.getNetProductionRates(ydot);
multiply_each(ydot, ydot + nsp, mw.begin());
scale(ydot, ydot + nsp, ydot, rrho);
multiply_each(ydot, ydot + nsp, p.molecularWeights().begin());
scale(ydot, ydot + nsp, ydot, 1.0/p.density());
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -1204,9 +1193,8 @@ extern "C" {
size_t newTransport(char* model, int ith, int loglevel)
{
try {
string mstr = string(model);
ThermoPhase& t = ThermoCabinet::item(ith);
Transport* tr = newTransportMgr(mstr, &t, loglevel);
Transport* tr = newTransportMgr(model, &ThermoCabinet::item(ith),
loglevel);
return TransportCabinet::add(tr);
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -1320,7 +1308,6 @@ extern "C" {
try {
ThermoPhase& thrm = ThermoCabinet::item(nth);
XML_Node& node = XmlCabinet::item(nxml);
string idstr = string(id);
importPhase(node, &thrm);
return 0;
} catch (...) {
@ -1337,7 +1324,6 @@ extern "C" {
}
XML_Node& node = XmlCabinet::item(nxml);
Kinetics& k = KineticsCabinet::item(nkin);
string idstr = string(id);
importKinetics(node, phases, &k);
return 0;
} catch (...) {
@ -1376,7 +1362,7 @@ extern "C" {
int write_HTML_log(const char* file)
{
try {
write_logfile(string(file));
write_logfile(file);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -1386,8 +1372,7 @@ extern "C" {
int getCanteraError(int buflen, char* buf)
{
try {
string e;
e = lastErrorMessage();
string e = lastErrorMessage();
if (buflen > 0) {
int n = min(static_cast<int>(e.size()), buflen-1);
copy(e.begin(), e.begin() + n, buf);
@ -1412,7 +1397,7 @@ extern "C" {
int addCanteraDirectory(size_t buflen, char* buf)
{
try {
addDirectory(string(buf));
addDirectory(buf);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -1504,12 +1489,11 @@ extern "C" {
ThermoPhase& t = ThermoCabinet::item(ith);
Kinetics& kin = KineticsCabinet::item(ikin);
XML_Node* x, *r=0;
XML_Node* r = 0;
if (root) {
r = &root->root();
}
x = get_XML_Node(string(src), r);
//x = find_XML(string(src), r, string(id), "", "phase");
XML_Node* x = get_XML_Node(src, r);
if (!x) {
return false;
}
@ -1545,7 +1529,7 @@ extern "C" {
int writelogfile(char* logfile)
{
try {
write_logfile(string(logfile));
write_logfile(logfile);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);

View file

@ -126,7 +126,7 @@ extern "C" {
int bndry_setxinbyname(int i, char* xin)
{
try {
BoundaryCabinet::item(i).setMoleFractions(string(xin));
BoundaryCabinet::item(i).setMoleFractions(xin);
} catch (...) {
return Cantera::handleAllExceptions(-1, ERR);
}

View file

@ -89,7 +89,7 @@ extern "C" {
size_t mix_elementIndex(int i, char* name)
{
try {
return mixCabinet::item(i).elementIndex(string(name));
return mixCabinet::item(i).elementIndex(name);
} catch (...) {
return handleAllExceptions(npos, npos);
}
@ -179,7 +179,7 @@ extern "C" {
int mix_setMolesByName(int i, char* n)
{
try {
mixCabinet::item(i).setMolesByName(string(n));
mixCabinet::item(i).setMolesByName(n);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);

View file

@ -101,7 +101,7 @@ extern "C" {
size_t domain_componentIndex(int i, char* name)
{
try {
return DomainCabinet::item(i).componentIndex(string(name));
return DomainCabinet::item(i).componentIndex(name);
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -200,8 +200,7 @@ extern "C" {
int domain_setID(int i, char* id)
{
try {
string s = string(id);
DomainCabinet::item(i).setID(s);
DomainCabinet::item(i).setID(id);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -212,8 +211,7 @@ extern "C" {
int domain_setDesc(int i, char* desc)
{
try {
string s = string(desc);
DomainCabinet::item(i).setDesc(s);
DomainCabinet::item(i).setDesc(desc);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -224,8 +222,7 @@ extern "C" {
int inlet_new()
{
try {
Inlet1D* i = new Inlet1D();
return DomainCabinet::add(i);
return DomainCabinet::add(new Inlet1D());
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -234,8 +231,7 @@ extern "C" {
int surf_new()
{
try {
Surf1D* i = new Surf1D();
return DomainCabinet::add(i);
return DomainCabinet::add(new Surf1D());
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -244,8 +240,7 @@ extern "C" {
int reactingsurf_new()
{
try {
Domain1D* i = new ReactingSurf1D();
return DomainCabinet::add(i);
return DomainCabinet::add(new ReactingSurf1D());
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -254,8 +249,7 @@ extern "C" {
int symm_new()
{
try {
Symm1D* i = new Symm1D();
return DomainCabinet::add(i);
return DomainCabinet::add(new Symm1D());
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -264,8 +258,7 @@ extern "C" {
int outlet_new()
{
try {
Outlet1D* i = new Outlet1D();
return DomainCabinet::add(i);
return DomainCabinet::add(new Outlet1D());
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -274,8 +267,7 @@ extern "C" {
int outletres_new()
{
try {
OutletRes1D* i = new OutletRes1D();
return DomainCabinet::add(i);
return DomainCabinet::add(new OutletRes1D());
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -304,7 +296,7 @@ extern "C" {
int bdry_setMoleFractions(int i, char* x)
{
try {
DomainCabinet::get<Bdry1D>(i).setMoleFractions(string(x));
DomainCabinet::get<Bdry1D>(i).setMoleFractions(x);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -341,8 +333,7 @@ extern "C" {
int reactingsurf_setkineticsmgr(int i, int j)
{
try {
InterfaceKinetics& k =
dynamic_cast<InterfaceKinetics&>(Cabinet<Kinetics>::item(j));
InterfaceKinetics& k = Cabinet<Kinetics>::get<InterfaceKinetics>(j);
DomainCabinet::get<ReactingSurf1D>(i).setKineticsMgr(&k);
return 0;
} catch (...) {
@ -375,7 +366,7 @@ extern "C" {
int stflow_new(int iph, int ikin, int itr, int itype)
{
try {
IdealGasPhase& ph = dynamic_cast<IdealGasPhase&>(ThermoCabinet::item(iph));
IdealGasPhase& ph = ThermoCabinet::get<IdealGasPhase>(iph);
if (itype == 1) {
AxiStagnFlow* x = new AxiStagnFlow(&ph, ph.nSpecies(), 2);
x->setKinetics(KineticsCabinet::item(ikin));
@ -398,10 +389,7 @@ extern "C" {
int stflow_setTransport(int i, int itr, int iSoret)
{
try {
bool withSoret = false;
if (iSoret > 0) {
withSoret = true;
}
bool withSoret = (iSoret > 0);
DomainCabinet::get<StFlow>(i).setTransport(TransportCabinet::item(itr), withSoret);
return 0;
} catch (...) {
@ -412,10 +400,7 @@ extern "C" {
int stflow_enableSoret(int i, int iSoret)
{
try {
bool withSoret = false;
if (iSoret > 0) {
withSoret = true;
}
bool withSoret = (iSoret > 0);
DomainCabinet::get<StFlow>(i).enableSoret(withSoret);
return 0;
} catch (...) {
@ -489,8 +474,7 @@ extern "C" {
for (size_t n = 0; n < nd; n++) {
d.push_back(&DomainCabinet::item(domains[n]));
}
Sim1D* s = new Sim1D(d);
return SimCabinet::add(s);
return SimCabinet::add(new Sim1D(d));
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -630,10 +614,7 @@ extern "C" {
int sim1D_save(int i, char* fname, char* id, char* desc)
{
try {
string sname = string(fname);
string sid = string(id);
string sdesc = string(desc);
SimCabinet::item(i).save(sname, sid, sdesc);
SimCabinet::item(i).save(fname, id, desc);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -643,9 +624,7 @@ extern "C" {
int sim1D_restore(int i, char* fname, char* id)
{
try {
string sname = string(fname);
string sid = string(id);
SimCabinet::item(i).restore(sname, sid);
SimCabinet::item(i).restore(fname, id);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -665,7 +644,7 @@ extern "C" {
int sim1D_domainIndex(int i, char* name)
{
try {
return (int) SimCabinet::item(i).domainIndex(string(name));
return (int) SimCabinet::item(i).domainIndex(name);
} catch (...) {
return handleAllExceptions(-1, ERR);
}

View file

@ -129,12 +129,8 @@ extern "C" {
int reactor_advance(int i, double t)
{
try {
try {
ReactorCabinet::item(i).advance(t);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
}
ReactorCabinet::item(i).advance(t);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -278,8 +274,7 @@ extern "C" {
int reactornet_new()
{
try {
ReactorNet* r = new ReactorNet();
return NetworkCabinet::add(r);
return NetworkCabinet::add(new ReactorNet());
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -520,11 +515,7 @@ extern "C" {
int flowdev_ready(int i)
{
try {
bool ok = FlowDeviceCabinet::item(i).ready();
if (ok) {
return 1;
}
return 0;
return int(FlowDeviceCabinet::item(i).ready());
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -537,9 +528,7 @@ extern "C" {
int wall_new(int type)
{
try {
Wall* r;
r = new Wall();
return WallCabinet::add(r);
return WallCabinet::add(new Wall());
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -588,14 +577,12 @@ extern "C" {
{
try {
Kinetics* left=0, *right=0;
if (n > 0)
if (KineticsCabinet::item(n).type() == cInterfaceKinetics) {
left = &KineticsCabinet::item(n);
}
if (m > 0)
if (KineticsCabinet::item(m).type() == cInterfaceKinetics) {
right = &KineticsCabinet::item(m);
}
if (n > 0 && KineticsCabinet::item(n).type() == cInterfaceKinetics) {
left = &KineticsCabinet::item(n);
}
if (m > 0 && KineticsCabinet::item(m).type() == cInterfaceKinetics) {
right = &KineticsCabinet::item(m);
}
WallCabinet::item(i).setKinetics(left, right);
return 0;
} catch (...) {
@ -703,11 +690,7 @@ extern "C" {
int wall_ready(int i)
{
try {
if (WallCabinet::item(i).ready()) {
return 1;
} else {
return 0;
}
return int(WallCabinet::item(i).ready());
} catch (...) {
return handleAllExceptions(-1, ERR);
}

View file

@ -93,7 +93,7 @@ extern "C" {
int rdiag_setBoldColor(int i, char* color)
{
try {
DiagramCabinet::item(i).bold_color = string(color);
DiagramCabinet::item(i).bold_color = color;
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -103,7 +103,7 @@ extern "C" {
int rdiag_setNormalColor(int i, char* color)
{
try {
DiagramCabinet::item(i).normal_color = string(color);
DiagramCabinet::item(i).normal_color = color;
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -113,7 +113,7 @@ extern "C" {
int rdiag_setDashedColor(int i, char* color)
{
try {
DiagramCabinet::item(i).dashed_color = string(color);
DiagramCabinet::item(i).dashed_color = color;
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -123,7 +123,7 @@ extern "C" {
int rdiag_setDotOptions(int i, char* opt)
{
try {
DiagramCabinet::item(i).dot_options = string(opt);
DiagramCabinet::item(i).dot_options = opt;
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -133,7 +133,7 @@ extern "C" {
int rdiag_setFont(int i, char* font)
{
try {
DiagramCabinet::item(i).setFont(string(font));
DiagramCabinet::item(i).setFont(font);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -207,7 +207,7 @@ extern "C" {
int rdiag_setTitle(int i, char* title)
{
try {
DiagramCabinet::item(i).title = string(title);
DiagramCabinet::item(i).title = title;
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -301,7 +301,7 @@ extern "C" {
if (iquiet > 0) {
quiet = true;
}
BuilderCabinet::item(i).build(KineticsCabinet::item(k), string(el), fdot,
BuilderCabinet::item(i).build(KineticsCabinet::item(k), el, fdot,
DiagramCabinet::item(idiag), quiet);
return 0;
} catch (...) {

View file

@ -50,7 +50,7 @@ extern "C" {
int surf_setcoveragesbyname(int i, char* c)
{
try {
ThermoCabinet::get<SurfPhase>(i).setCoveragesByName(string(c));
ThermoCabinet::get<SurfPhase>(i).setCoveragesByName(c);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);

View file

@ -38,7 +38,7 @@ extern "C" {
int xml_get_XML_File(const char* file, int debug)
{
try {
XML_Node* x = get_XML_File(std::string(file), debug);
XML_Node* x = get_XML_File(file, debug);
return XmlCabinet::add(x);
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -98,7 +98,7 @@ extern "C" {
{
try {
writelog("WARNING: xml_build called. Use get_XML_File instead.");
string path = findInputFile(string(file));
string path = findInputFile(file);
ifstream f(path.c_str());
if (!f) {
throw CanteraError("xml_build",
@ -115,7 +115,7 @@ extern "C" {
int xml_preprocess_and_build(int i, const char* file, int debug)
{
try {
get_CTML_Tree(&XmlCabinet::item(i), string(file), debug);
get_CTML_Tree(&XmlCabinet::item(i), file, debug);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -125,14 +125,13 @@ extern "C" {
int xml_attrib(int i, const char* key, char* value)
{
try {
string ky = string(key);
XML_Node& node = XmlCabinet::item(i);
if (node.hasAttrib(ky)) {
string v = node[ky];
if (node.hasAttrib(key)) {
string v = node[key];
strncpy(value, v.c_str(), 80);
} else
throw CanteraError("xml_attrib","node "
" has no attribute '"+ky+"'");
" has no attribute '"+string(key)+"'");
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -142,10 +141,7 @@ extern "C" {
int xml_addAttrib(int i, const char* key, const char* value)
{
try {
string ky = string(key);
string val = string(value);
XML_Node& node = XmlCabinet::item(i);
node.addAttribute(ky, val);
XmlCabinet::item(i).addAttribute(key, value);
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -155,9 +151,7 @@ extern "C" {
int xml_addComment(int i, const char* comment)
{
try {
string c = string(comment);
XML_Node& node = XmlCabinet::item(i);
node.addComment(c);
XmlCabinet::item(i).addComment(comment);
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -167,8 +161,7 @@ extern "C" {
int xml_tag(int i, char* tag)
{
try {
XML_Node& node = XmlCabinet::item(i);
const string v = node.name();
string v = XmlCabinet::item(i).name();
strncpy(tag, v.c_str(), 80);
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -179,8 +172,7 @@ extern "C" {
int xml_value(int i, char* value)
{
try {
XML_Node& node = XmlCabinet::item(i);
const string v = node.value();
string v = XmlCabinet::item(i).value();
strncpy(value, v.c_str(), 80);
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -191,8 +183,7 @@ extern "C" {
int xml_child(int i, const char* loc)
{
try {
XML_Node& node = XmlCabinet::item(i);
XML_Node& c = node.child(string(loc));
XML_Node& c = XmlCabinet::item(i).child(string(loc));
return XmlCabinet::add(&c);
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -203,8 +194,7 @@ extern "C" {
int xml_child_bynumber(int i, int m)
{
try {
XML_Node& node = XmlCabinet::item(i);
XML_Node& c = node.child(m);
XML_Node& c = XmlCabinet::item(i).child(m);
return XmlCabinet::add(&c);
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -215,8 +205,7 @@ extern "C" {
int xml_findID(int i, const char* id)
{
try {
XML_Node& node = XmlCabinet::item(i);
XML_Node* c = node.findID(string(id));
XML_Node* c = XmlCabinet::item(i).findID(id);
if (c) {
return XmlCabinet::add(c);
} else {
@ -231,8 +220,7 @@ extern "C" {
int xml_findByName(int i, const char* nm)
{
try {
XML_Node& node = XmlCabinet::item(i);
XML_Node* c = node.findByName(string(nm));
XML_Node* c = XmlCabinet::item(i).findByName(nm);
if (c) {
return XmlCabinet::add(c);
} else
@ -247,8 +235,7 @@ extern "C" {
int xml_nChildren(int i)
{
try {
XML_Node& node = XmlCabinet::item(i);
return (int) node.nChildren();
return (int) XmlCabinet::item(i).nChildren();
} catch (...) {
return handleAllExceptions(-1, ERR);
}
@ -257,8 +244,7 @@ extern "C" {
int xml_addChild(int i, const char* name, const char* value)
{
try {
XML_Node& node = XmlCabinet::item(i);
XML_Node& c = node.addChild(string(name),string(value));
XML_Node& c = XmlCabinet::item(i).addChild(name, value);
return XmlCabinet::add(&c);
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -269,9 +255,7 @@ extern "C" {
int xml_addChildNode(int i, int j)
{
try {
XML_Node& node = XmlCabinet::item(i);
XML_Node& chld = XmlCabinet::item(j);
XML_Node& c = node.addChild(chld);
XML_Node& c = XmlCabinet::item(i).addChild(XmlCabinet::item(j));
return XmlCabinet::add(&c);
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -284,8 +268,7 @@ extern "C" {
try {
ofstream f(file);
if (f) {
XML_Node& node = XmlCabinet::item(i);
node.write(f);
XmlCabinet::item(i).write(f);
} else {
throw CanteraError("xml_write",
"file "+string(file)+" not found.");