Added a recursive limit to the writes.

This commit is contained in:
Harry Moffat 2012-01-13 02:24:48 +00:00
parent 8c39c0307b
commit 8e1563b07d
2 changed files with 37 additions and 22 deletions

View file

@ -450,7 +450,7 @@ namespace Cantera {
m_iscomment(right.m_iscomment),
m_linenum(right.m_linenum)
{
m_root = & right.root();
m_root = this;
m_name = right.m_name;
m_value = right.m_value;
right.copy(this);
@ -797,6 +797,10 @@ namespace Cantera {
return m_attribs;
}
const std::map<std::string,std::string>& XML_Node::attribsConst() const {
return m_attribs;
}
// Set the line number
/*
* @param n the member data m_linenum is set to n
@ -1127,8 +1131,7 @@ namespace Cantera {
}
else {
if (node->name() != nm.substr(1,nm.size()-1))
throw XML_TagMismatch(node->name(),
nm.substr(1,nm.size()-1), lnum);
throw XML_TagMismatch(node->name(), nm.substr(1,nm.size()-1), lnum);
node = node->parent();
}
}
@ -1202,6 +1205,7 @@ namespace Cantera {
int ndc;
node_dest->addValue(m_value);
node_dest->setName(m_name);
node_dest->setLineNumber(m_linenum);
if (m_name == "") return;
map<string,string>::const_iterator b = m_attribs.begin();
for (; b != m_attribs.end(); ++b) {
@ -1292,7 +1296,7 @@ namespace Cantera {
* main recursive routine. It doesn't put a final endl
* on. This is fixed up in the public method.
*/
void XML_Node::write_int(std::ostream& s, int level) const {
void XML_Node::write_int(std::ostream& s, int level, int numRecursivesAllowed) const {
if (m_name == "") return;
@ -1402,9 +1406,11 @@ namespace Cantera {
}
}
int i;
for (i = 0; i < m_nchildren; i++) {
s << endl;
m_children[i]->write_int(s,level + 2);
if (numRecursivesAllowed > 0) {
for (i = 0; i < m_nchildren; i++) {
s << endl;
m_children[i]->write_int(s,level + 2, numRecursivesAllowed - 1);
}
}
if (m_nchildren > 0) s << endl << indent;
s << "</" << m_name << ">";
@ -1421,14 +1427,14 @@ namespace Cantera {
* is skipped and the children are processed. "--" is used
* to denote the top of the tree.
*/
void XML_Node::write(std::ostream& s, const int level) const {
void XML_Node::write(std::ostream& s, const int level, int numRecursivesAllowed) const {
if (m_name == "--" && m_root == this) {
for (int i = 0; i < m_nchildren; i++) {
m_children[i]->write_int(s,level);
m_children[i]->write_int(s,level, numRecursivesAllowed-1);
s << endl;
}
} else {
write_int(s, level);
write_int(s, level, numRecursivesAllowed);
s << endl;
}
}

View file

@ -45,8 +45,7 @@ namespace Cantera {
*/
XML_Reader(std::istream& input);
//! Read a single character from the input stream
//! and return it
//! Read a single character from the input stream and returns it
/*!
* All low level reads occur through this function.
* The function also keeps track of the line numbers.
@ -130,13 +129,14 @@ namespace Cantera {
std::string readValue();
protected:
//! Input Stream containing the XML file
//! Input stream containing the XML file
std::istream& m_s;
public:
//! Line count
int m_line;
};
@ -412,6 +412,7 @@ namespace Cantera {
void clear();
private:
//! Returns a changeable value of the attributes map for the current node
/*!
* Note this is a simple accessor routine. And, it is a private function.
@ -421,6 +422,13 @@ namespace Cantera {
public:
//! Returns an unchangeable value of the attributs map for the current node
/*!
*
* @return Returns an unchangeable reference to the attributes map
*/
const std::map<std::string,std::string>& attribsConst() const;
//! Set the line number
/*!
* @param n the member data m_linenum is set to n
@ -432,7 +440,6 @@ namespace Cantera {
* @return returns the member data m_linenum
*/
int lineNumber() const;
//! Returns a pointer to the parent node of the current node
XML_Node* parent() const;
@ -642,9 +649,10 @@ namespace Cantera {
* to denote the top of the tree.
*
* @param s ostream to write to
* @param level Indentation level to work from
* @param level Indentation level to work from
* @param numRecursivesAllowed Number of recursive calls allowed
*/
void write(std::ostream& s, const int level = 0) const;
void write(std::ostream& s, const int level = 0, int numRecursivesAllowed = 60000) const;
//! Return the root of the current XML_Node tree
/*!
@ -705,15 +713,16 @@ namespace Cantera {
//! Write an XML subtree to an output stream.
/*!
* This is the
* main recursive routine. It doesn't put a final endl
* on. This is fixed up in the public method.
* This is the main recursive routine. It doesn't put a final endl
* on. This is fixed up in the public method. A method to only write out a limited
* amount of the xml tree has been added.
*
*
* @param s ostream to write to
* @param level Indentation level to work from
* @param numRecurvivesAllowed Number of recursive calls allowed
*/
void write_int(std::ostream& s, int level = 0) const;
void write_int(std::ostream& s, int level = 0, int numRecursivesAllowed = 60000) const;
protected:
@ -785,7 +794,7 @@ namespace Cantera {
//! True if the current node is a comment node
bool m_iscomment;
//! the member data m_linenum
//! The member data m_linenum
/*!
* Currently, unimplemented functionality
*/