From 5f9c515e03bbdb9322aa80540eebf53d4a2bcf2a Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Mon, 9 Jan 2012 16:12:23 +0000 Subject: [PATCH] Added a new function getNamedStringValue --- Cantera/src/base/ctml.cpp | 70 ++++++++++++++++++++++++++++++++++-- Cantera/src/base/ctml.h | 75 +++++++++++++++++++++++++++++++-------- Cantera/src/base/xml.cpp | 2 +- Cantera/src/base/xml.h | 2 +- 4 files changed, 130 insertions(+), 19 deletions(-) diff --git a/Cantera/src/base/ctml.cpp b/Cantera/src/base/ctml.cpp index ec6c4983d..a4856bbff 100644 --- a/Cantera/src/base/ctml.cpp +++ b/Cantera/src/base/ctml.cpp @@ -416,7 +416,7 @@ namespace ctml { if (!parent.hasChild(nameString)) return ""; return parent(nameString); } - //==================================================================================================================== + //==================================================================================================================== // This function reads a child node with the name, "string", with a specific // title attribute named "titleString" /* @@ -440,10 +440,11 @@ namespace ctml { <\string> @endverbatum * - * @param node reference to the XML_Node object of the parent XML element + * @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 + * @param typeString String type. This is an optional output variable. It is filled + * with the attribute "type" of the XML entry. */ void getString(const Cantera::XML_Node& node, const std::string &titleString, std::string& valueString, std::string& typeString) { @@ -458,6 +459,69 @@ namespace ctml { } } + //==================================================================================================================== + // This function attempts to read a named child node and returns with the contents in the value string. + // 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; + std::string valueString; + std::string typeString; + std::string nameString = "timeIncrement"; + getString(XML_Node& node, nameString, valueString, valueString, typeString); + @endverbatum + * + * Reads the following the snippet in the XML file: + * + * * @verbatum + + valueString + <\nameString> + @endverbatum + * + * or alternatively as a retrofit and special case, it also reads the following case + * + * @verbatum + + valueString + <\string> + @endverbatum + * + * @param node Reference to the XML_Node object of the parent XML element + * @param nameString Name of the XML Node input variable + * @param valueString Value string that is found in the child node. output variable + * @param typeString String type. This is an optional output variable. It is filled + * with the attribute "type" of the XML entry. output variable + */ + void getNamedStringValue(const Cantera::XML_Node& node, const std::string &nameString, std::string& valueString, + std::string& typeString) + { + valueString = ""; + typeString = ""; + if (node.hasChild(nameString)) { + XML_Node &xc = node.child(nameString); + valueString = xc.value(); + typeString = xc["type"]; + } else { + XML_Node* s = getByTitle(node, nameString); + if (s) { + if (s->name() == "string") { + valueString = (*s).value(); + typeString = (*s)["type"]; + return; + } + } + } + } //==================================================================================================================== // Get a vector of integer values from a child element. /* diff --git a/Cantera/src/base/ctml.h b/Cantera/src/base/ctml.h index 6c57abdee..bd0614b16 100644 --- a/Cantera/src/base/ctml.h +++ b/Cantera/src/base/ctml.h @@ -851,6 +851,40 @@ namespace ctml { //! 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: + * @verbatim + const XML_Node &node; + getString(XML_Node& node, std::string titleString, std::string valueString, + std::string typeString); + @endverbatim + * + * Reads the following the snippet in the XML file: + * @verbatim + + valueString + <\string> + @endverbatim + * + * @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. It is filled + * with the attribute "type" of the XML entry. + */ + void getString(const Cantera::XML_Node& node, const std::string &titleString, + std::string& valueString, std::string& typeString); + + //! This function attempts to read a named child node and returns with the contents in the value string. + //! 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 @@ -861,26 +895,39 @@ namespace ctml { * Example: * * Code snipet: - * @verbatim - const XML_Node &node; - getString(XML_Node& node, std::string titleString, std::string valueString, - std::string typeString); - @endverbatim + * @verbatum + const XML_Node &node; + std::string valueString; + std::string typeString; + std::string nameString = "timeIncrement"; + getString(XML_Node& node, nameString, valueString, valueString, typeString); + @endverbatum * * Reads the following the snippet in the XML file: - * @verbatim - + * + * * @verbatum + + valueString + <\nameString> + @endverbatum + * + * or alternatively as a retrofit and special case, it also reads the following case + * + * @verbatum + valueString <\string> - @endverbatim + @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 + * @param node Reference to the XML_Node object of the parent XML element + * @param nameString Name of the XML Node input variable + * @param valueString Value string that is found in the child node. output variable + * @param typeString String type. This is an optional output variable. It is filled + * with the attribute "type" of the XML entry. output variable */ - void getString(const Cantera::XML_Node& node, const std::string &titleString, - std::string& valueString, std::string& typeString); + void getNamedStringValue(const Cantera::XML_Node& node, const std::string &nameString, 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 diff --git a/Cantera/src/base/xml.cpp b/Cantera/src/base/xml.cpp index 1484c1b6f..65de68887 100644 --- a/Cantera/src/base/xml.cpp +++ b/Cantera/src/base/xml.cpp @@ -925,7 +925,7 @@ namespace Cantera { } // This routine carries out a recursive search for an XML node based - // on the xml element attribute ID. + // on the xml element attribute, "id" . /* * If exact match is found, the pointer * to the matching XML Node is returned. If not, 0 is returned. diff --git a/Cantera/src/base/xml.h b/Cantera/src/base/xml.h index 3be1378a3..cf9ece36d 100644 --- a/Cantera/src/base/xml.h +++ b/Cantera/src/base/xml.h @@ -517,7 +517,7 @@ namespace Cantera { const std::string &idTarget) const; //! This routine carries out a recursive search for an XML node based - //! on the xml element attribute ID. + //! on the xml element attribute, "id" /*! * If exact match is found, the pointer * to the matching XML Node is returned. If not, 0 is returned.