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