Cantera  2.3.0
xml.h
Go to the documentation of this file.
1 /**
2  * @file xml.h
3  * Classes providing support for XML data files. These classes
4  * implement only those aspects of XML required to read, write, and
5  * manipulate CTML data files.
6  */
7 
8 // This file is part of Cantera. See License.txt in the top-level directory or
9 // at http://www.cantera.org/license.txt for license and copyright information.
10 
11 #ifndef CT_XML_H
12 #define CT_XML_H
13 
14 #include "ctexceptions.h"
15 #include "global.h"
16 
17 //@{
18 #define XML_INDENT 4
19 //@}
20 
21 namespace Cantera
22 {
23 //! Class XML_Reader reads an XML file into an XML_Node object.
24 /*!
25  * Class XML_Reader is designed for internal use.
26  */
28 {
29 public:
30  //! Sole Constructor for the XML_Reader class
31  /*!
32  * @param input Reference to the istream object containing the XML file
33  */
34  XML_Reader(std::istream& input);
35 
36  //! Read a single character from the input stream and returns it
37  /*!
38  * All low level reads occur through this function. The function also keeps
39  * track of the line numbers.
40  *
41  * @param ch Character to be returned.
42  */
43  void getchr(char& ch);
44 
45  //! Searches a string for the first occurrence of a valid quoted string.
46  /*!
47  * Quotes can start with either a single quote or a double quote, but must
48  * also end with the same type. Quotes may be commented out by preceding
49  * with a backslash character, '\\'.
50  *
51  * @param aline This is the input string to be searched
52  * @param rstring Return value of the string that is found.
53  * The quotes are stripped from the string.
54  * @returns the integer position just after the quoted string.
55  */
56  int findQuotedString(const std::string& aline, std::string& rstring) const;
57 
58  //! parseTag parses XML tags, i.e., the XML elements that are in between
59  //! angle brackets.
60  /*!
61  * @param tag Tag to be parsed - input
62  * @param name Output string containing name of the XML
63  * @param[out] attribs map of attribute name and attribute value
64  */
65  void parseTag(const std::string& tag, std::string& name,
66  std::map<std::string, std::string>& attribs) const;
67 
68  //! Reads an XML tag into a string
69  /*!
70  * This function advances the input streams pointer
71  *
72  * @param attribs map of attribute name and attribute value - output
73  * @return Output string containing name of the XML
74  */
75  std::string readTag(std::map<std::string, std::string>& attribs);
76 
77  //! Return the value portion of an XML element
78  /*!
79  * This function advances the input streams pointer
80  */
81  std::string readValue();
82 
83 protected:
84  //! Input stream containing the XML file
85  std::istream& m_s;
86 
87 public:
88  //! Line count
89  int m_line;
90 };
91 
92 //! Class XML_Node is a tree-based representation of the contents of an XML file
93 /*!
94  * There are routines for adding to the tree, querying and searching the tree,
95  * and for writing the tree out to an output file.
96  */
97 class XML_Node
98 {
99 public:
100  //! Constructor for XML_Node, representing a tree structure
101  /*!
102  * @param nm Name of the node.
103  * @param parent Pointer to the parent for this node in the tree.
104  * A value of 0 indicates this is the top of the tree.
105  */
106  explicit XML_Node(const std::string& nm="--", XML_Node* const parent=0);
107 
108  XML_Node(const XML_Node& right);
109  XML_Node& operator=(const XML_Node& right);
110  virtual ~XML_Node();
111 
112  //! Add a child node to the current node containing a comment
113  /*!
114  * Child node will have the name, comment.
115  *
116  * @param comment Content of the comment
117  */
118  void addComment(const std::string& comment);
119 
120  //! Merge an existing node as a child node to the current node
121  /*!
122  * This will merge an XML_Node as a child to the current node. Note, this
123  * actually adds the node. Therefore, the current node is changed. There is
124  * no copy made of the child node. The child node should not be deleted in
125  * the future
126  *
127  * @param node Reference to a child XML_Node object
128  * @returns a reference to the added child node
129  */
131 
132  // Add a child node to the current node by making a copy of an existing node
133  // tree
134  /*
135  * This will add an XML_Node as a child to the current node. Note, this
136  * actually adds the node. Therefore, node is changed. A copy is made of the
137  * underlying tree
138  *
139  * @param node Reference to a child XML_Node object
140  * @returns a reference to the added node
141  */
142  XML_Node& addChild(const XML_Node& node);
143 
144  //! Add a child node to the current node with a specified name
145  /*!
146  * This will add an XML_Node as a child to the current node.
147  * The node will be blank except for the specified name.
148  *
149  * @param sname Name of the new child
150  * @returns a reference to the added node
151  */
152  XML_Node& addChild(const std::string& sname);
153 
154  //! Add a child node to the current XML node, and at the same time add a
155  //! value to the child
156  /*!
157  * Resulting XML string:
158  *
159  * <name> value </name>
160  *
161  * @param name Name of the child XML_Node object
162  * @param value Value of the XML_Node - string
163  * @returns a reference to the created child XML_Node object
164  */
165  XML_Node& addChild(const std::string& name, const std::string& value);
166 
167  //! Add a child node to the current XML node, and at the same time add a
168  //! formatted value to the child
169  /*!
170  * This version supplies a formatting string (printf format) to the output
171  * of the value.
172  *
173  * Resulting XML string:
174  *
175  * <name> value </name>
176  *
177  * @param name Name of the child XML_Node object
178  * @param value Value of the XML_Node - double.
179  * @param fmt Format of the output for value
180  * @returns a reference to the created child XML_Node object
181  */
182  XML_Node& addChild(const std::string& name, const doublereal value,
183  const std::string& fmt="%g");
184 
185  //! Remove a child from this node's list of children
186  /*!
187  * This function removes an XML_Node from the children of this node.
188  *
189  * @param node Pointer to the node to be removed. Note, this node
190  * isn't modified in any way.
191  */
192  void removeChild(const XML_Node* const node);
193 
194  //! Modify the value for the current node
195  /*!
196  * This functions fills in the m_value field of the current node
197  *
198  * @param val string Value that the node will be assigned
199  */
200  void addValue(const std::string& val);
201 
202  //! Modify the value for the current node
203  /*!
204  * This functions fills in the m_value field of the current node
205  * with a formatted double value
206  *
207  * @param val double Value that the node will be assigned
208  * @param fmt Format of the printf string conversion of the double.
209  * Default is "%g". Must be less than 63 chars
210  */
211  void addValue(const doublereal val, const std::string& fmt="%g");
212 
213  //! Return the value of an XML node as a string
214  /*!
215  * This is a simple accessor routine
216  */
217  std::string value() const;
218 
219  //! Return the value of an XML child node as a string
220  /*!
221  * @param cname Name of the child node to the current node, for which you
222  * want the value
223  */
224  std::string value(const std::string& cname) const;
225 
226  //! The Overloaded parenthesis operator with one augment
227  //! returns the value of an XML child node as a string
228  /*!
229  * @param cname Name of the child node to the current node, for which you
230  * want the value
231  */
232  std::string operator()(const std::string& cname) const;
233 
234  //! Return the value of an XML node as a single double
235  /*!
236  * This accesses the value string, and then tries to interpret it as a
237  * single double value.
238  */
239  doublereal fp_value() const;
240 
241  //! Return the value of an XML node as a single int
242  /*!
243  * This accesses the value string, and then tries to interpret it as a
244  * single int value.
245  */
246  integer int_value() const;
247 
248  //! Add or modify an attribute of the current node
249  /*!
250  * This functions fills in the m_value field of the current node
251  * with a string value
252  *
253  * @param attrib String name for the attribute to be assigned
254  * @param value String value that the attribute will have
255  */
256  void addAttribute(const std::string& attrib, const std::string& value);
257 
258  //! Add or modify an attribute to the double, value
259  /*!
260  * This functions fills in the attribute field, named attrib,
261  * with the double value, value. A formatting string is used.
262  *
263  * @param attrib String name for the attribute to be assigned
264  * @param value double Value that the node will be assigned
265  * @param fmt Format of the printf string conversion of the double.
266  * Default is "%g".
267  */
268  void addAttribute(const std::string& attrib, const doublereal value,
269  const std::string& fmt="%g");
270 
271  //! Add an integer attribute
272  /*!
273  * @param attrib String name for the attribute to be assigned
274  * @param value int Value that the node will be assigned
275  */
276  void addAttribute(const std::string& attrib, int value);
277 
278  //! Add an unsigned integer attribute
279  /*!
280  * @param attrib String name for the attribute to be assigned
281  * @param value int Value that the node will be assigned
282  */
283  void addAttribute(const std::string& attrib, size_t value);
284 
285  //! The operator[] is overloaded to provide a lookup capability
286  //! on attributes for the current XML element.
287  /*!
288  * For example
289  * xmlNode["id"]
290  * will return the value of the attribute "id" for the current
291  * XML element. It will return the blank std::string if there isn't
292  * an attribute with that name.
293  *
294  * @param attr attribute string to look up
295  * @returns a string representing the value of the attribute within the XML
296  * node. If there is no attribute with the given name, it returns
297  * the null string.
298  */
299  std::string operator[](const std::string& attr) const;
300 
301  //! Function returns the value of an attribute
302  /*!
303  * This function searches the attributes vector for the attribute named
304  * 'attr'. If a match is found, the attribute value is returned as a
305  * string. If no match is found, the empty string is returned.
306  *
307  * @param attr String containing the attribute to be searched for.
308  * @return If a match is found, the attribute value is returned as a
309  * string. If no match is found, the empty string is
310  * returned.
311  */
312  std::string attrib(const std::string& attr) const;
313 
314  //! Clear the current node and everything under it
315  /*!
316  * The value, attributes and children are all zeroed. The name and the
317  * parent information is kept.
318  */
319  void clear();
320 
321 private:
322  //! Returns a changeable value of the attributes map for the current node
323  /*!
324  * Note this is a simple accessor routine. And, it is a private function.
325  * It's used in some internal copy and assignment routines
326  */
327  std::map<std::string,std::string>& attribs();
328 
329 public:
330  //! Returns an unchangeable value of the attributes map for the current node
331  const std::map<std::string,std::string>& attribsConst() const;
332 
333  //! Set the line number
334  /*!
335  * @param n the member data m_linenum is set to n
336  */
337  void setLineNumber(const int n);
338 
339  //! Return the line number
340  int lineNumber() const;
341 
342  //! Returns a pointer to the parent node of the current node
343  XML_Node* parent() const;
344 
345  //! Sets the pointer for the parent node of the current node
346  /*!
347  * @param p Pointer to the parent node
348  * @returns the pointer p
349  */
350  XML_Node* setParent(XML_Node* const p);
351 
352  //! Tests whether the current node has a child node with a particular name
353  /*!
354  * @param ch Name of the child node to test
355  * @returns true if the child node exists, false otherwise.
356  */
357  bool hasChild(const std::string& ch) const;
358 
359  //! Tests whether the current node has an attribute with a particular name
360  /*!
361  * @param a Name of the attribute to test
362  * @returns true if the attribute exists, false otherwise.
363  */
364  bool hasAttrib(const std::string& a) const;
365 
366  //! Returns the name of the XML node
367  /*!
368  * The name is the XML node is the XML node name
369  */
370  std::string name() const {
371  return m_name;
372  }
373 
374  //! Sets the name of the XML node
375  /*!
376  * @param name_ The name of the XML node
377  */
378  void setName(const std::string& name_) {
379  m_name = name_;
380  }
381 
382  //! Return the id attribute, if present
383  /*!
384  * Returns the id attribute if present. If not it return the empty string
385  */
386  std::string id() const;
387 
388  //! Return a changeable reference to the n'th child of the current node
389  /*!
390  * @param n Number of the child to return
391  */
392  XML_Node& child(const size_t n) const;
393 
394  //! Return an unchangeable reference to the vector of children of the current node
395  /*!
396  * Each of the individual XML_Node child pointers, however, is to a
397  * changeable XML node object.
398  */
399  const std::vector<XML_Node*>& children() const;
400 
401  //! Return the number of children
402  /*!
403  * @param discardComments If true comments are discarded when adding up the
404  * number of children. Defaults to false.
405  */
406  size_t nChildren(bool discardComments = false) const;
407 
408  //! Boolean function indicating whether a comment
409  bool isComment() const;
410 
411  //! Require that the current XML node have an attribute named by the first
412  //! argument, a, and that this attribute have the the string value listed
413  //! in the second argument, v.
414  /*!
415  * @param a attribute name
416  * @param v required value of the attribute
417  *
418  * If the condition is not true, an exception is thrown
419  */
420  void _require(const std::string& a, const std::string& v) const;
421 
422  //! This routine carries out a recursive search for an XML node based
423  //! on both the XML element name and the attribute ID.
424  /*!
425  * If exact matches are found for both fields, the pointer
426  * to the matching XML Node is returned.
427  *
428  * The ID attribute may be defaulted by setting it to "". In this case the
429  * pointer to the first XML element matching the name only is returned.
430  *
431  * @param nameTarget Name of the XML Node that is being searched for
432  * @param idTarget "id" attribute of the XML Node that the routine
433  * looks for
434  * @returns the pointer to the XML node that fits the criteria
435  *
436  * @internal
437  * This algorithm does a lateral search of first generation children
438  * first before diving deeper into each tree branch.
439  */
440  XML_Node* findNameID(const std::string& nameTarget,
441  const std::string& idTarget) const;
442 
443  //! This routine carries out a search for an XML node based
444  //! on both the XML element name and the attribute ID and an integer index.
445  /*!
446  * If exact matches are found for all fields, the pointer
447  * to the matching XML Node is returned. The search is only carried out on
448  * the current element and the child elements of the current element.
449  *
450  * The "id" attribute may be defaulted by setting it to "". In this case the
451  * pointer to the first XML element matching the name only is returned.
452  *
453  * @param nameTarget Name of the XML Node that is being searched for
454  * @param idTarget "id" attribute of the XML Node that the routine
455  * looks for
456  * @param index Integer describing the index. The index is an
457  * attribute of the form index = "3"
458  * @returns the pointer to the XML node that fits the criteria
459  */
460  XML_Node* findNameIDIndex(const std::string& nameTarget,
461  const std::string& idTarget, const int index) const;
462 
463  //! This routine carries out a recursive search for an XML node based
464  //! on the XML element attribute, "id"
465  /*!
466  * If exact match is found, the pointer to the matching XML Node is
467  * returned. If not, 0 is returned.
468  *
469  * The ID attribute may be defaulted by setting it to "". In this case the
470  * pointer to the first XML element matching the name only is returned.
471  *
472  * @param id "id" attribute of the XML Node that the routine looks for
473  * @param depth Depth of the search.
474  * @returns the pointer to the XML node that fits the criteria
475  *
476  * @internal
477  * This algorithm does a lateral search of first generation children
478  * first before diving deeper into each tree branch.
479  */
480  XML_Node* findID(const std::string& id, const int depth=100) const;
481 
482  //! This routine carries out a recursive search for an XML node based
483  //! on an attribute of each XML node
484  /*!
485  * If exact match is found with respect to the attribute name and value of
486  * the attribute, the pointer to the matching XML Node is returned. If
487  * not, 0 is returned.
488  *
489  * @param attr Attribute of the XML Node that the routine looks for
490  * @param val Value of the attribute
491  * @param depth Depth of the search. A value of 1 means that only the
492  * immediate children are searched.
493  * @returns the pointer to the XML node that fits the criteria
494  */
495  XML_Node* findByAttr(const std::string& attr, const std::string& val,
496  int depth = 100000) const;
497 
498  //! This routine carries out a recursive search for an XML node based
499  //! on the name of the node.
500  /*!
501  * If exact match is found with respect to XML_Node name, the pointer to the
502  * matching XML Node is returned. If not, 0 is returned. This is the const
503  * version of the routine.
504  *
505  * @param nm Name of the XML node
506  * @param depth Depth of the search. A value of 1 means that only the
507  * immediate children are searched.
508  * @returns the pointer to the XML node that fits the criteria
509  */
510  const XML_Node* findByName(const std::string& nm, int depth = 100000) const;
511 
512  //! This routine carries out a recursive search for an XML node based
513  //! on the name of the node.
514  /*!
515  * If exact match is found with respect to XML_Node name, the pointer
516  * to the matching XML Node is returned. If not, 0 is returned.
517  * This is the non-const version of the routine.
518  *
519  * @param nm Name of the XML node
520  * @param depth Depth of the search. A value of 1 means that only the
521  * immediate children are searched.
522  * @returns the pointer to the XML node that fits the criteria
523  */
524  XML_Node* findByName(const std::string& nm, int depth = 100000);
525 
526  //! Get a vector of pointers to XML_Node containing all of the children
527  //! of the current node which match the given name
528  /*!
529  * @param name Name of the XML_Node children to search for
530  * @return vector of pointers to child XML_Nodes with the matching name
531  */
532  std::vector<XML_Node*> getChildren(const std::string& name) const;
533 
534  //! Return a changeable reference to a child of the current node, named by
535  //! the argument
536  /*!
537  * Note the underlying data allows for more than one XML element with the
538  * same name. This routine returns the first child with the given name.
539  *
540  * @param loc Name of the child to return
541  */
542  XML_Node& child(const std::string& loc) const;
543 
544  //! Write the header to the XML file to the specified ostream
545  /*!
546  * @param s ostream to write the output to
547  */
548  void writeHeader(std::ostream& s);
549 
550  //! Write an XML subtree to an output stream.
551  /*!
552  * This is a wrapper around the static routine write_int(). All this does
553  * is add an endl on to the output stream. write_int() is fine, but the
554  * last endl wasn't being written.
555  *
556  * @param s ostream to write to
557  * @param level Indentation level to work from
558  * @param numRecursivesAllowed Number of recursive calls allowed
559  */
560  void write(std::ostream& s, const int level = 0, int numRecursivesAllowed = 60000) const;
561 
562  //! Return the root of the current XML_Node tree
563  /*!
564  * Returns a reference to the root of the current XML tree
565  */
566  XML_Node& root() const;
567 
568  //! Set the root XML_Node value within the current node
569  /*!
570  * @param root Value of the root XML_Node.
571  */
572  void setRoot(const XML_Node& root);
573 
574  //! Populate the XML tree from an input file
575  void build(const std::string& filename);
576 
577  //! Main routine to create an tree-like representation of an XML file
578  /*!
579  * Given an input stream, this routine will read matched XML tags
580  * representing the ctml file until an EOF is read from the file. This
581  * routine is called by the root XML_Node object.
582  *
583  * @param f Input stream containing the ascii input file
584  * @param filename Name of the input file, used in error messages
585  */
586  void build(std::istream& f, const std::string& filename="[unknown]");
587 
588  //! Copy all of the information in the current XML_Node tree into the
589  //! destination XML_Node tree, doing a union operation as we go
590  /*!
591  * Note this is a const function because the current XML_Node and its
592  * children isn't altered by this operation. copyUnion() doesn't duplicate
593  * existing entries in the destination XML_Node tree.
594  *
595  * @param node_dest This is the XML node to receive the information
596  */
597  void copyUnion(XML_Node* const node_dest) const;
598 
599  //! Copy all of the information in the current XML_Node tree into the
600  //! destination XML_Node tree, doing a complete copy as we go.
601  /*!
602  * Note this is a const function because the current XML_Node and its
603  * children isn't altered by this operation.
604  *
605  * @param node_dest This is the XML node to receive the information
606  */
607  void copy(XML_Node* const node_dest) const;
608 
609  //! Set the lock for this node and all of its children
610  void lock();
611 
612  //! Unset the lock for this node and all of its children
613  void unlock();
614 
615 private:
616  //! Write an XML subtree to an output stream.
617  /*!
618  * This is the main recursive routine. It doesn't put a final endl on. This
619  * is fixed up in the public method. A method to only write out a limited
620  * amount of the XML tree has been added.
621  *
622  * @param s ostream to write to
623  * @param level Indentation level to work from
624  * @param numRecursivesAllowed Number of recursive calls allowed
625  */
626  void write_int(std::ostream& s, int level = 0, int numRecursivesAllowed = 60000) const;
627 
628 protected:
629  //! XML node name of the node.
630  /*!
631  * For example, if we were in the XML_Node where
632  *
633  * <phase dim="3" id="gas">
634  * </phase>
635  *
636  * Then, this string would be equal to "phase". "dim" and "id" are
637  * attributes of the XML_Node.
638  */
639  std::string m_name;
640 
641  //! Value of the XML node
642  /*!
643  * This is the string contents of the XML node. For example. The XML node
644  * named eps:
645  *
646  * <eps>
647  * valueString
648  * </eps>
649  *
650  * has a m_value string containing "valueString".
651  */
652  std::string m_value;
653 
654  //! Name of the file from which this XML node was read. Only populated for
655  //! the root node.
656  std::string m_filename;
657 
658  //! Map containing an index between the node name and the
659  //! pointer to the node
660  /*!
661  * m_childindex[node.name()] = XML_Node *pointer
662  *
663  * This object helps to speed up searches.
664  */
665  std::multimap<std::string, XML_Node*> m_childindex;
666 
667  //! Storage of attributes for a node
668  /*!
669  * m_attribs[attribName] = attribValue
670  */
671  std::map<std::string, std::string> m_attribs;
672 
673  //! Pointer to the parent XML_Node for the current node
674  /*!
675  * Note, the top node has a parent value of 0
676  */
678 
679  //! Pointer to the root XML_Node for the current node
680  /*!
681  * Note, the top node has a root value equal to itself
682  */
684 
685  //! Lock for this node
686  /*!
687  * Currently, unimplemented functionality. If locked,
688  * it means you can't delete this node.
689  */
690  bool m_locked;
691 
692  //! Vector of pointers to child nodes
693  std::vector<XML_Node*> m_children;
694 
695  //! True if the current node is a comment node
697 
698  //! The member data m_linenum
699  /*!
700  * Currently, unimplemented functionality
701  */
703 };
704 
705 //! Search an XML_Node tree for a named phase XML_Node
706 /*!
707  * Search for a phase Node matching a name.
708  *
709  * @param root Starting XML_Node* pointer for the search
710  * @param phaseName Name of the phase to search for
711  * @returns the XML_Node pointer if the phase is found. If the phase is not
712  * found, it returns 0
713  */
714 XML_Node* findXMLPhase(XML_Node* root, const std::string& phaseName);
715 
716 }
717 
718 #endif
void setName(const std::string &name_)
Sets the name of the XML node.
Definition: xml.h:378
std::vector< XML_Node * > getChildren(const std::string &name) const
Get a vector of pointers to XML_Node containing all of the children of the current node which match t...
Definition: xml.cpp:864
std::vector< XML_Node * > m_children
Vector of pointers to child nodes.
Definition: xml.h:693
std::string readTag(std::map< std::string, std::string > &attribs)
Reads an XML tag into a string.
Definition: xml.cpp:231
std::string name() const
Returns the name of the XML node.
Definition: xml.h:370
XML_Node * findXMLPhase(XML_Node *root, const std::string &idtarget)
Search an XML_Node tree for a named phase XML_Node.
Definition: xml.cpp:1038
const XML_Node * findByName(const std::string &nm, int depth=100000) const
This routine carries out a recursive search for an XML node based on the name of the node...
Definition: xml.cpp:695
void clear()
Clear the current node and everything under it.
Definition: xml.cpp:365
void copyUnion(XML_Node *const node_dest) const
Copy all of the information in the current XML_Node tree into the destination XML_Node tree...
Definition: xml.cpp:781
std::string operator()(const std::string &cname) const
The Overloaded parenthesis operator with one augment returns the value of an XML child node as a stri...
Definition: xml.cpp:469
integer int_value() const
Return the value of an XML node as a single int.
Definition: xml.cpp:459
void unlock()
Unset the lock for this node and all of its children.
Definition: xml.cpp:856
std::map< std::string, std::string > & attribs()
Returns a changeable value of the attributes map for the current node.
Definition: xml.cpp:505
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
void write(std::ostream &s, const int level=0, int numRecursivesAllowed=60000) const
Write an XML subtree to an output stream.
Definition: xml.cpp:1019
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, (see Input File Handling, Diagnostic Output, and Writing messages to the screen).
std::map< std::string, std::string > m_attribs
Storage of attributes for a node.
Definition: xml.h:671
bool hasAttrib(const std::string &a) const
Tests whether the current node has an attribute with a particular name.
Definition: xml.cpp:541
bool isComment() const
Boolean function indicating whether a comment.
Definition: xml.cpp:571
XML_Node * setParent(XML_Node *const p)
Sets the pointer for the parent node of the current node.
Definition: xml.cpp:530
std::string m_value
Value of the XML node.
Definition: xml.h:652
void addValue(const std::string &val)
Modify the value for the current node.
Definition: xml.cpp:436
Class XML_Reader reads an XML file into an XML_Node object.
Definition: xml.h:27
void _require(const std::string &a, const std::string &v) const
Require that the current XML node have an attribute named by the first argument, a, and that this attribute have the the string value listed in the second argument, v.
Definition: xml.cpp:576
void addComment(const std::string &comment)
Add a child node to the current node containing a comment.
Definition: xml.cpp:382
const std::vector< XML_Node * > & children() const
Return an unchangeable reference to the vector of children of the current node.
Definition: xml.cpp:551
XML_Reader(std::istream &input)
Sole Constructor for the XML_Reader class.
Definition: xml.cpp:115
int findQuotedString(const std::string &aline, std::string &rstring) const
Searches a string for the first occurrence of a valid quoted string.
Definition: xml.cpp:157
bool m_locked
Lock for this node.
Definition: xml.h:690
XML_Node * m_root
Pointer to the root XML_Node for the current node.
Definition: xml.h:683
std::string m_filename
Name of the file from which this XML node was read.
Definition: xml.h:656
void lock()
Set the lock for this node and all of its children.
Definition: xml.cpp:848
bool m_iscomment
True if the current node is a comment node.
Definition: xml.h:696
XML_Node(const std::string &nm="--", XML_Node *const parent=0)
Constructor for XML_Node, representing a tree structure.
Definition: xml.cpp:309
XML_Node * parent() const
Returns a pointer to the parent node of the current node.
Definition: xml.cpp:525
std::string value() const
Return the value of an XML node as a string.
Definition: xml.cpp:449
void build(const std::string &filename)
Populate the XML tree from an input file.
Definition: xml.cpp:716
XML_Node & mergeAsChild(XML_Node &node)
Merge an existing node as a child node to the current node.
Definition: xml.cpp:387
XML_Node * m_parent
Pointer to the parent XML_Node for the current node.
Definition: xml.h:677
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
Definition: xml.cpp:474
void copy(XML_Node *const node_dest) const
Copy all of the information in the current XML_Node tree into the destination XML_Node tree...
Definition: xml.cpp:825
int lineNumber() const
Return the line number.
Definition: xml.cpp:520
void setLineNumber(const int n)
Set the line number.
Definition: xml.cpp:515
void parseTag(const std::string &tag, std::string &name, std::map< std::string, std::string > &attribs) const
parseTag parses XML tags, i.e., the XML elements that are in between angle brackets.
Definition: xml.cpp:192
XML_Node * findNameID(const std::string &nameTarget, const std::string &idTarget) const
This routine carries out a recursive search for an XML node based on both the XML element name and th...
Definition: xml.cpp:586
void setRoot(const XML_Node &root)
Set the root XML_Node value within the current node.
Definition: xml.cpp:1030
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:536
int m_line
Line count.
Definition: xml.h:89
XML_Node & child(const size_t n) const
Return a changeable reference to the n&#39;th child of the current node.
Definition: xml.cpp:546
XML_Node & root() const
Return the root of the current XML_Node tree.
Definition: xml.cpp:1025
const std::map< std::string, std::string > & attribsConst() const
Returns an unchangeable value of the attributes map for the current node.
Definition: xml.cpp:510
std::string m_name
XML node name of the node.
Definition: xml.h:639
XML_Node * findNameIDIndex(const std::string &nameTarget, const std::string &idTarget, const int index) const
This routine carries out a search for an XML node based on both the XML element name and the attribut...
Definition: xml.cpp:616
std::string readValue()
Return the value portion of an XML element.
Definition: xml.cpp:278
void removeChild(const XML_Node *const node)
Remove a child from this node&#39;s list of children.
Definition: xml.cpp:421
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:500
std::string operator[](const std::string &attr) const
The operator[] is overloaded to provide a lookup capability on attributes for the current XML element...
Definition: xml.cpp:495
std::string id() const
Return the id attribute, if present.
Definition: xml.cpp:428
void writeHeader(std::ostream &s)
Write the header to the XML file to the specified ostream.
Definition: xml.cpp:711
XML_Node * findByAttr(const std::string &attr, const std::string &val, int depth=100000) const
This routine carries out a recursive search for an XML node based on an attribute of each XML node...
Definition: xml.cpp:661
Namespace for the Cantera kernel.
Definition: application.cpp:29
void write_int(std::ostream &s, int level=0, int numRecursivesAllowed=60000) const
Write an XML subtree to an output stream.
Definition: xml.cpp:902
doublereal fp_value() const
Return the value of an XML node as a single double.
Definition: xml.cpp:454
int m_linenum
The member data m_linenum.
Definition: xml.h:702
size_t nChildren(bool discardComments=false) const
Return the number of children.
Definition: xml.cpp:556
std::multimap< std::string, XML_Node * > m_childindex
Map containing an index between the node name and the pointer to the node.
Definition: xml.h:665
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
XML_Node * findID(const std::string &id, const int depth=100) const
This routine carries out a recursive search for an XML node based on the XML element attribute...
Definition: xml.cpp:645
std::istream & m_s
Input stream containing the XML file.
Definition: xml.h:85
void getchr(char &ch)
Read a single character from the input stream and returns it.
Definition: xml.cpp:121