Changed one of the getString() functions to getChildValue(),

to get rid of some unnecessary overloading.
This commit is contained in:
Harry Moffat 2009-01-02 22:34:41 +00:00
parent 09236f42f8
commit 51aa98675e
8 changed files with 144 additions and 29 deletions

View file

@ -30,7 +30,7 @@ using namespace Cantera;
namespace ctml {
static doublereal fpValue(string val) {
static doublereal fpValue(std::string val) {
return atof(stripws(val).c_str());
}
@ -161,26 +161,82 @@ namespace ctml {
if (s->parent() == &node) return s;
else return 0;
}
string getString(const XML_Node& parent, string name) {
if (!parent.hasChild(name)) return "";
return parent(name);
// This function reads a child node with the name string and returns
// its xml value as the return string
/*
* If the child XML_node named "name" doesn't exist, the empty string is returned.
*
* Code snipet:
* @verbatum
const XML_Node &parent;
string name = "vacency_species";
string valueString = getChildValue(parent, name
std::string typeString);
@endverbatum
*
* returns valueString = "O(V)"
*
* from the following the snippet in the XML file:
*
* @verbatum
<vacencySpecies>
O(V)
<\vancencySpecies>
@endverbatum
*
* @param parent parent reference to the XML_Node object of the parent XML element
* @param name Name of the childe XML_Node to read the value from.
*
* @return String value of the child XML_Node
*/
std::string getChildValue(const XML_Node& parent, const std::string &nameString) {
if (!parent.hasChild(nameString)) return "";
return parent(nameString);
}
void getString(XML_Node& node, string title, string& val,
string& type) {
val = "";
type = "";
XML_Node* s = getByTitle(node, title);
if (s)
if (s->name() == "string") {
val = (*s).value();
type = (*s)["type"];
return;
}
}
void getIntegers(const XML_Node& node, map<string,int>& v) {
// This function reads a child node with the name, "string", with a specific
// title attribute named "titleString"
/*
* This function will read a child node to the current XML node, with the
* name "string". It must have a title attribute, named titleString, and the body
* of the XML node will be read into the valueString output argument.
*
* Example:
*
* Code snipet:
* @verbatum
const XML_Node &node;
getString(XML_Node& node, std::string titleString, std::string valueString,
std::string typeString);
@endverbatum
*
* Reads the following the snippet in the XML file:
* @verbatum
<string title="titleString" type="typeString">
valueString
<\string>
@endverbatum
*
* @param node reference to the XML_Node object of the parent XML element
* @param titleString String name of the title attribute of the child node
* @param valueString Value string that is found in the child node. output variable
* @param typeString String type. This is an optional output variable
*/
void getString(XML_Node& node, const std::string &titleString, std::string& valueString,
std::string& typeString) {
valueString = "";
typeString = "";
XML_Node* s = getByTitle(node, titleString);
if (s)
if (s->name() == "string") {
valueString = (*s).value();
typeString = (*s)["type"];
return;
}
}
void getIntegers(const XML_Node& node, map<string,int>& v) {
vector<XML_Node*> f;
node.getChildren("integer",f);
int n = static_cast<int>(f.size());

View file

@ -246,10 +246,69 @@ namespace ctml {
void getFunction(const Cantera::XML_Node& node, std::string& type,
doublereal& xmin, doublereal& xmax, Cantera::vector_fp& coeffs);
Cantera::XML_Node* getByTitle(Cantera::XML_Node& node, std::string title);
void getString(Cantera::XML_Node& node, std::string title,
std::string& val, std::string& type);
std::string getString(const Cantera::XML_Node& parent, std::string name);
//! This function reads a child node with the name string with a specific
//! title attribute named titleString
/*!
* This function will read a child node to the current XML node, with the
* name "string". It must have a title attribute, named titleString, and the body
* of the XML node will be read into the valueString output argument.
*
* If the child node is not found then the empty string is returned.
*
* Example:
*
* Code snipet:
* @verbatum
const XML_Node &node;
getString(XML_Node& node, std::string titleString, std::string valueString,
std::string typeString);
@endverbatum
*
* Reads the following the snippet in the XML file:
* @verbatum
<string title="titleString" type="typeString">
valueString
<\string>
@endverbatum
*
* @param node reference to the XML_Node object of the parent XML element
* @param titleString String name of the title attribute of the child node
* @param valueString Value string that is found in the child node. output variable
* @param typeString String type. This is an optional output variable
*/
void getString(Cantera::XML_Node& node, const std::string &titleString,
std::string& valueString, std::string& typeString);
//! This function reads a child node with the name, nameString, and returns
//! its xml value as the return string
/*!
* If the child XML_node named "name" doesn't exist, the empty string is returned.
*
* Code snipet:
* @verbatum
const XML_Node &parent;
string nameString = "vacency_species";
string valueString = getChildValue(parent, nameString
std::string typeString);
@endverbatum
*
* returns valueString = "O(V)"
*
* from the following the snippet in the XML file:
*
* @verbatum
<vacencySpecies>
O(V)
<\vancencySpecies>
@endverbatum
*
* @param parent parent reference to the XML_Node object of the parent XML element
* @param nameString Name of the childe XML_Node to read the value from.
*
* @return String value of the child XML_Node
*/
std::string getChildValue(const Cantera::XML_Node& parent, const std::string &nameString);
// these are defined in ct2ctml.cpp
void get_CTML_Tree(Cantera::XML_Node* node, std::string file, int debug = 0);

View file

@ -1563,7 +1563,7 @@ namespace Cantera {
spPtr = xspecies[k];
if (!spPtr) {
if (spPtr->hasChild("electrolyteSpeciesType")) {
std::string est = getString(*spPtr, "electrolyteSpeciesType");
std::string est = getChildValue(*spPtr, "electrolyteSpeciesType");
if ((m_electrolyteSpeciesType[k] = interp_est(est)) == -1) {
throw CanteraError("DebyeHuckel:initThermoXML",
"Bad electrolyte type: " + est);

View file

@ -1476,7 +1476,7 @@ namespace Cantera {
spPtr = xspecies[k];
if (!spPtr) {
if (spPtr->hasChild("electrolyteSpeciesType")) {
string est = getString(*spPtr, "electrolyteSpeciesType");
string est = getChildValue(*spPtr, "electrolyteSpeciesType");
if ((m_electrolyteSpeciesType[k] = interp_est(est)) == -1) {
throw CanteraError("HMWSoln::initThermoXML",
"Bad electrolyte type: " + est);

View file

@ -249,7 +249,7 @@ namespace Cantera {
void LatticePhase::setParametersFromXML(const XML_Node& eosdata) {
eosdata._require("model","Lattice");
m_molar_density = getFloat(eosdata, "site_density", "toSI");
m_vacancy = getString(eosdata, "vacancy_species");
m_vacancy = getChildValue(eosdata, "vacancy_species");
}
}

View file

@ -594,7 +594,7 @@ namespace Cantera {
*/
void MolalityVPSSTP::setStateFromXML(const XML_Node& state) {
VPStandardStateTP::setStateFromXML(state);
string comp = getString(state,"soluteMolalities");
string comp = getChildValue(state,"soluteMolalities");
if (comp != "") {
setMolalitiesByName(comp);
}

View file

@ -475,7 +475,7 @@ namespace Cantera {
}
if (state.hasChild("coverages")) {
string comp = getString(state,"coverages");
string comp = getChildValue(state,"coverages");
setCoveragesByName(comp);
}
}

View file

@ -904,11 +904,11 @@ namespace Cantera {
*/
void ThermoPhase::setStateFromXML(const XML_Node& state) {
string comp = getString(state,"moleFractions");
string comp = getChildValue(state,"moleFractions");
if (comp != "")
setMoleFractionsByName(comp);
else {
comp = getString(state,"massFractions");
comp = getChildValue(state,"massFractions");
if (comp != "")
setMassFractionsByName(comp);
}