From 8a740e53d8e6ffba81359cd322f5c78bfa48e726 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Fri, 31 Oct 2008 19:14:57 +0000 Subject: [PATCH] Doxygen updates --- Cantera/src/base/stringUtils.cpp | 10 +++--- Cantera/src/base/xml.cpp | 41 ++++++++++++++++------- Cantera/src/base/xml.h | 56 +++++++++++++++++++++++--------- 3 files changed, 74 insertions(+), 33 deletions(-) diff --git a/Cantera/src/base/stringUtils.cpp b/Cantera/src/base/stringUtils.cpp index 727f8e553..e1ef95c8b 100755 --- a/Cantera/src/base/stringUtils.cpp +++ b/Cantera/src/base/stringUtils.cpp @@ -31,17 +31,17 @@ namespace Cantera { * Convert a floating point number to a std::string using sprintf. */ std::string fp2str(double x, std::string fmt) { - char buf[30]; - int n = SNPRINTF(buf, 30, fmt.c_str(), x); + char buf[64]; + int n = SNPRINTF(buf, 63, fmt.c_str(), x); if (n > 0) { - buf[29] = '\0'; + buf[63] = '\0'; return std::string(buf); } return std::string(" "); } std::string fp2str(double x) { - char buf[30]; - int n = SNPRINTF(buf, 30, "%g" , x); + char buf[64]; + int n = SNPRINTF(buf, 64, "%g" , x); if (n > 0) { buf[29] = '\0'; return std::string(buf); diff --git a/Cantera/src/base/xml.cpp b/Cantera/src/base/xml.cpp index 0c9ad1dd9..5c2338ea9 100755 --- a/Cantera/src/base/xml.cpp +++ b/Cantera/src/base/xml.cpp @@ -525,11 +525,36 @@ namespace Cantera { * Default is "%g" Must be less than 63 chars */ void XML_Node::addValue(const doublereal val, const std::string fmt) { - char buf[64]; - sprintf(buf, fmt.c_str(), val); - m_value = stripws(buf); + m_value = stripws(fp2str(val, fmt)); } + // Add or modify an attribute of the current node + /* + * This functions fills in the m_value field of the current node + * with a string value + * + * @param attrib String name for the attribute to be assigned + * @param value String value that the attribute will have + */ + void XML_Node::addAttribute(const std::string attrib, const std::string value) { + m_attribs[attrib] = value; + } + + // Add or modify an attribute to the double, value + /* + * This functions fills in the attribute field, named attrib, + * with the double value, value. A formatting string is used. + * + * @param attrib String name for the attribute to be assigned + * @param value double Value that the node will be assigned + * @param fmt Format of the printf string conversion of the double. + * Default is "%g". + */ + void XML_Node::addAttribute(const std::string attrib, + const doublereal value, const std::string fmt) { + m_attribs[attrib] = fp2str(value, fmt); + } + // The operator[] is overloaded to provide a lookup capability // on attributes for the current XML element. /* @@ -545,7 +570,7 @@ namespace Cantera { * within the XML node. If there is no attribute * with the given name, it returns the null string. */ - std::string XML_Node::operator[](std::string attr) const { + std::string XML_Node::operator[](const std::string attr) const { return attrib(attr); } @@ -671,14 +696,6 @@ namespace Cantera { - - void XML_Node::addAttribute(string attrib, string value) { - m_attribs[attrib] = value; - } - void XML_Node::addAttribute(string attrib, double value, string fmt) { - m_attribs[attrib] = fp2str(value, fmt); - } - void XML_Node::writeHeader(ostream& s) { s << "" << endl; } diff --git a/Cantera/src/base/xml.h b/Cantera/src/base/xml.h index 75a730948..22a70b637 100755 --- a/Cantera/src/base/xml.h +++ b/Cantera/src/base/xml.h @@ -229,22 +229,28 @@ namespace Cantera { */ void addValue(const doublereal val, const std::string fmt="%g"); - void addAttribute(std::string attrib, std::string value); - void addAttribute(std::string attrib, double value, std::string fmt="%g"); - void writeHeader(std::ostream& s); - std::string value() const { return m_value; } - std::string value(std::string loc) const { return child(loc).value(); } - void setLineNumber(int n) {m_linenum = n;} - int lineNumber() const {return m_linenum;} - doublereal fp_value() const { - return std::atof(m_value.c_str()); - } - integer int_value() const { - return std::atoi(m_value.c_str()); - } - std::string operator()() const { return m_value; } - std::string operator()(std::string loc) const { return value(loc); } + //! Add or modify an attribute of the current node + /*! + * This functions fills in the m_value field of the current node + * with a string value + * + * @param attrib String name for the attribute to be assigned + * @param value String value that the attribute will have + */ + void addAttribute(const std::string attrib, const std::string value); + //! Add or modify an attribute to the double, value + /*! + * This functions fills in the attribute field, named attrib, + * with the double value, value. A formatting string is used. + * + * @param attrib String name for the attribute to be assigned + * @param value double Value that the node will be assigned + * @param fmt Format of the printf string conversion of the double. + * Default is "%g". + */ + void addAttribute(const std::string attrib, const double value, + const std::string fmt="%g"); //! The operator[] is overloaded to provide a lookup capability //! on attributes for the current XML element. @@ -261,7 +267,7 @@ namespace Cantera { * within the XML node. If there is no attribute * with the given name, it returns the null string. */ - std::string operator[](std::string attr) const; + std::string operator[](const std::string attr) const; //! Function returns the value of an attribute /*! @@ -278,8 +284,25 @@ namespace Cantera { */ std::string attrib(const std::string attr) const; + void writeHeader(std::ostream& s); + std::string value() const { return m_value; } + std::string value(std::string loc) const { return child(loc).value(); } + void setLineNumber(int n) {m_linenum = n;} + int lineNumber() const {return m_linenum;} + doublereal fp_value() const { + return std::atof(m_value.c_str()); + } + integer int_value() const { + return std::atoi(m_value.c_str()); + } + std::string operator()() const { return m_value; } + std::string operator()(std::string loc) const { return value(loc); } + + std::map& attribs() { return m_attribs; } + XML_Node* parent() const { return m_parent; } + XML_Node* setParent(XML_Node* p) { m_parent = p; return p; } //! Tests whether the current node has a child node with a particular name @@ -382,6 +405,7 @@ namespace Cantera { * has a m_value string containing "valueString". */ std::string m_value; + std::map m_childindex; std::map m_attribs; XML_Node* m_parent;