Cantera  2.1.2
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 node with a specified name
160  /*!
161  * This will add an XML_Node as a child to the current node.
162  * The node will be blank except for the specified name.
163  *
164  * @param cstring Name of the new child as a c string
165  *
166  * @return Returns a reference to the added node
167  */
168  XML_Node& addChild(const char* cstring);
169 
170  //! Add a child node to the current xml node, and at the
171  //! same time add a value to the child
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 - string
179  * @return Returns a reference to the created child XML_Node object
180  */
181  XML_Node& addChild(const std::string& name, const std::string& value);
182 
183  //! Add a child node to the current xml node, and at the
184  //! same time add a formatted value to the child
185  /*!
186  * This version supplies a formatting string (printf format)
187  * to the output of the value.
188  *
189  * Resulting XML string:
190  *
191  * <name> value </name>
192  *
193  * @param name Name of the child XML_Node object
194  * @param value Value of the XML_Node - double.
195  * @param fmt Format of the output for value
196  *
197  * @return Returns a reference to the created child XML_Node object
198  */
199  XML_Node& addChild(const std::string& name, const doublereal value,
200  const std::string& fmt="%g");
201 
202  //! Remove a child from this node's list of children
203  /*!
204  * This function removes an XML_Node from the children of this node.
205  *
206  * @param node Pointer to the node to be removed. Note, this node
207  * isn't modified in any way.
208  */
209  void removeChild(const XML_Node* const node);
210 
211  //! Modify the value for the current node
212  /*!
213  * This functions fills in the m_value field of the current node
214  *
215  * @param val string Value that the node will be assigned
216  */
217  void addValue(const std::string& val);
218 
219  //! Modify the value for the current node
220  /*!
221  * This functions fills in the m_value field of the current node
222  * with a formatted double value
223  *
224  * @param val double Value that the node will be assigned
225  * @param fmt Format of the printf string conversion of the double.
226  * Default is "%g". Must be less than 63 chars
227  */
228  void addValue(const doublereal val, const std::string& fmt="%g");
229 
230  //! Return the value of an XML node as a string
231  /*!
232  * This is a simple accessor routine
233  */
234  std::string value() const;
235 
236  //! Overloaded parenthesis operator returns the value of the Node
237  /*!
238  * @return Returns the value of the node as a string.
239  */
240  std::string operator()() const;
241 
242  //! Return the value of an XML child node as a string
243  /*!
244  * @param cname Name of the child node to the current
245  * node, for which you want the value
246  */
247  std::string value(const std::string& cname) const;
248 
249  //! The Overloaded parenthesis operator with one augment
250  //! returns the value of an XML child node as a string
251  /*!
252  * @param cname Name of the child node to the current
253  * node, for which you want the value
254  */
255  std::string operator()(const std::string& cname) const;
256 
257  //! Return the value of an XML node as a single double
258  /*!
259  * This accesses the value string, and then tries to
260  * interpret it as a single double value.
261  */
262  doublereal fp_value() const;
263 
264  //! Return the value of an XML node as a single int
265  /*!
266  * This accesses the value string, and then tries to
267  * interpret it as a single int value.
268  */
269  integer int_value() const;
270 
271  //! Add or modify an attribute of the current node
272  /*!
273  * This functions fills in the m_value field of the current node
274  * with a string value
275  *
276  * @param attrib String name for the attribute to be assigned
277  * @param value String value that the attribute will have
278  */
279  void addAttribute(const std::string& attrib, const std::string& value);
280 
281  //! Add or modify an attribute to the double, value
282  /*!
283  * This functions fills in the attribute field, named attrib,
284  * with the double value, value. A formatting string is used.
285  *
286  * @param attrib String name for the attribute to be assigned
287  * @param value double Value that the node will be assigned
288  * @param fmt Format of the printf string conversion of the double.
289  * Default is "%g".
290  */
291  void addAttribute(const std::string& attrib, const doublereal value,
292  const std::string& fmt="%g");
293 
294  //! The operator[] is overloaded to provide a lookup capability
295  //! on attributes for the current XML element.
296  /*!
297  * For example
298  * xmlNode["id"]
299  * will return the value of the attribute "id" for the current
300  * XML element. It will return the blank std::string if there isn't
301  * an attribute with that name.
302  *
303  * @param attr attribute string to look up
304  *
305  * @return Returns a string representing the value of the attribute
306  * within the XML node. If there is no attribute
307  * with the given name, it returns the null string.
308  */
309  std::string operator[](const std::string& attr) const;
310 
311  //! Function returns the value of an attribute
312  /*!
313  * This function searches the attributes vector for the attribute named
314  * 'attr'. If a match is found, the attribute value is returned as a
315  * string. If no match is found, the empty string is returned.
316  *
317  * @param attr String containing the attribute to be searched for.
318  *
319  * @return Returns If a match is found, the attribute value is returned
320  * as a string. If no match is found, the empty string is
321  * returned.
322  */
323  std::string attrib(const std::string& attr) const;
324 
325  //! Clear the current node and everything under it
326  /*!
327  * The value, attributes and children are all zeroed. The name and the
328  * parent information is kept.
329  */
330  void clear();
331 
332 private:
333  //! Returns a changeable value of the attributes map for the current node
334  /*!
335  * Note this is a simple accessor routine. And, it is a private function.
336  * It's used in some internal copy and assignment routines
337  */
338  std::map<std::string,std::string>& attribs();
339 
340 public:
341  //! Returns an unchangeable value of the attributes map for the current node
342  /*!
343  * @return Returns an unchangeable reference to the attributes map
344  */
345  const std::map<std::string,std::string>& attribsConst() const;
346 
347  //! Set the line number
348  /*!
349  * @param n the member data m_linenum is set to n
350  */
351  void setLineNumber(const int n);
352 
353  //! Return the line number
354  /*!
355  * @return returns the member data m_linenum
356  */
357  int lineNumber() const;
358 
359  //! Returns a pointer to the parent node of the current node
360  XML_Node* parent() const;
361 
362  //! Sets the pointer for the parent node of the current node
363  /*!
364  * @param p Pointer to the parent node
365  *
366  * @return Returns the pointer p
367  */
368  XML_Node* setParent(XML_Node* const p);
369 
370  //! Tests whether the current node has a child node with a particular name
371  /*!
372  * @param ch Name of the child node to test
373  *
374  * @return Returns true if the child node exists, false otherwise.
375  */
376  bool hasChild(const std::string& ch) const;
377 
378  //! Tests whether the current node has an attribute with a particular name
379  /*!
380  * @param a Name of the attribute to test
381  *
382  * @return Returns true if the attribute exists, false otherwise.
383  */
384  bool hasAttrib(const std::string& a) const;
385 
386  //! Returns the name of the XML node
387  /*!
388  * The name is the XML node is the XML node name
389  */
390  std::string name() const {
391  return m_name;
392  }
393 
394  //! Sets the name of the XML node
395  /*!
396  * @param name_ The name of the XML node
397  */
398  void setName(const std::string& name_) {
399  m_name = name_;
400  }
401 
402  //! Return the id attribute, if present
403  /*!
404  * Returns the id attribute if present. If not
405  * it return the empty string
406  */
407  std::string id() const;
408 
409  //! Return a changeable reference to the n'th child of the current node
410  /*!
411  * @param n Number of the child to return
412  */
413  XML_Node& child(const size_t n) const ;
414 
415  //! Return an unchangeable reference to the vector of children of the current node
416  /*!
417  * Each of the individual XML_Node child pointers, however,
418  * is to a changeable xml node object.
419  *
420  */
421  const std::vector<XML_Node*>& children() const;
422 
423  //! Return the number of children
424  /*!
425  * @param discardComments If true comments are discarded when adding up the number of children.
426  * Defaults to false.
427  */
428  size_t nChildren(bool discardComments = false) const;
429 
430  //! Boolean function indicating whether a comment
431  bool isComment() const;
432 
433  //! Require that the current xml node have an attribute named by the first
434  //! argument, a, and that this attribute have the the string value listed
435  //! in the second argument, v.
436  /*!
437  * @param a attribute name
438  * @param v required value of the attribute
439  *
440  * If the condition is not true, an exception is thrown
441  */
442  void _require(const std::string& a, const std::string& v) const;
443 
444  //! This routine carries out a recursive search for an XML node based
445  //! on both the xml element name and the attribute ID.
446  /*!
447  * If exact matches are found for both fields, the pointer
448  * to the matching XML Node is returned.
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  *
457  * @return Returns the pointer to the XML node that fits the criteria
458  *
459  * @internal
460  * This algorithm does a lateral search of first generation children
461  * first before diving deeper into each tree branch.
462  */
463  XML_Node* findNameID(const std::string& nameTarget,
464  const std::string& idTarget) const;
465 
466  //! This routine carries out a search for an XML node based
467  //! on both the xml element name and the attribute ID and an integer index.
468  /*!
469  * If exact matches are found for all fields, the pointer
470  * to the matching XML Node is returned. The search is only carried out on
471  * the current element and the child elements of the current element.
472  *
473  * The "id" attribute may be defaulted by setting it to "".
474  * In this case the pointer to the first xml element matching the name
475  * only is returned.
476  *
477  * @param nameTarget Name of the XML Node that is being searched for
478  * @param idTarget "id" attribute of the XML Node that the routine
479  * looks for
480  * @param index Integer describing the index. The index is an
481  * attribute of the form index = "3"
482  *
483  * @return Returns the pointer to the XML node that fits the criteria
484  */
485  XML_Node* findNameIDIndex(const std::string& nameTarget,
486  const std::string& idTarget, const int index) const;
487 
488  //! This routine carries out a recursive search for an XML node based
489  //! on the xml element attribute, "id"
490  /*!
491  * If exact match is found, the pointer
492  * to the matching XML Node is returned. If not, 0 is returned.
493  *
494  * The ID attribute may be defaulted by setting it to "".
495  * In this case the pointer to the first xml element matching the name
496  * only is returned.
497  *
498  * @param id "id" attribute of the XML Node that the routine
499  * looks for
500  * @param depth Depth of the search.
501  *
502  * @return Returns the pointer to the XML node that fits the criteria
503  *
504  * @internal
505  * This algorithm does a lateral search of first generation children
506  * first before diving deeper into each tree branch.
507  */
508  XML_Node* findID(const std::string& id, const int depth=100) const;
509 
510  //! This routine carries out a recursive search for an XML node based
511  //! on an attribute of each XML node
512  /*!
513  * If exact match is found with respect to the attribute name and value of
514  * the attribute, the pointer to the matching XML Node is returned. If
515  * not, 0 is returned.
516  *
517  * @param attr Attribute of the XML Node that the routine
518  * looks for
519  * @param val Value of the attribute
520  * @param depth Depth of the search. A value of 1 means that only the
521  * immediate children are searched.
522  *
523  * @return Returns the pointer to the XML node that fits the criteria
524  */
525  XML_Node* findByAttr(const std::string& attr, const std::string& val,
526  int depth = 100000) const;
527 
528  //! This routine carries out a recursive search for an XML node based
529  //! on the name of the node.
530  /*!
531  * If exact match is found with respect to XML_Node name, the pointer
532  * to the matching XML Node is returned. If not, 0 is returned.
533  * This is the const version of the routine.
534  *
535  * @param nm Name of the XML node
536  * @param depth Depth of the search. A value of 1 means that only the
537  * immediate children are searched.
538  *
539  * @return Returns the pointer to the XML node that fits the criteria
540  */
541  const XML_Node* findByName(const std::string& nm, int depth = 100000) const;
542 
543  //! This routine carries out a recursive search for an XML node based
544  //! on the name of the node.
545  /*!
546  * If exact match is found with respect to XML_Node name, the pointer
547  * to the matching XML Node is returned. If not, 0 is returned.
548  * This is the non-const version of the routine.
549  *
550  * @param nm Name of the XML node
551  * @param depth Depth of the search. A value of 1 means that only the
552  * immediate children are searched.
553  *
554  * @return Returns the pointer to the XML node that fits the criteria
555  */
556  XML_Node* findByName(const std::string& nm, int depth = 100000);
557 
558  //! Get a vector of pointers to XML_Node containing all of the children
559  //! of the current node which matches the input name
560  /*!
561  * @param name Name of the XML_Node children to search on
562  *
563  * @param children output vector of pointers to XML_Node children
564  * with the matching name
565  */
566  void getChildren(const std::string& name, std::vector<XML_Node*>& children) const;
567 
568  //! Return a changeable reference to a child of the current node, named by the argument
569  /*!
570  * Note the underlying data allows for more than one XML element with the same name.
571  * This routine returns the first child with the given name.
572  *
573  * @param loc Name of the child to return
574  */
575  XML_Node& child(const std::string& loc) const;
576 
577  //! Write the header to the xml file to the specified ostream
578  /*!
579  * @param s ostream to write the output to
580  */
581  void writeHeader(std::ostream& s);
582 
583  //! Write an XML subtree to an output stream.
584  /*!
585  * This is a wrapper around the static routine write_int(). All this does
586  * is add an endl on to the output stream. write_int() is fine, but the
587  * last endl wasn't being written. It also checks for the special name
588  * "`--`". If found and we are at the root of the xml tree, then the block
589  * is skipped and the children are processed. "`--`" is used to denote the
590  * top of the tree.
591  *
592  * @param s ostream to write to
593  * @param level Indentation level to work from
594  * @param numRecursivesAllowed Number of recursive calls allowed
595  */
596  void write(std::ostream& s, const int level = 0, int numRecursivesAllowed = 60000) const;
597 
598  //! Return the root of the current XML_Node tree
599  /*!
600  * Returns a reference to the root of the current
601  * XML tree
602  */
603  XML_Node& root() const;
604 
605  //! Set the root XML_Node value within the current node
606  /*!
607  * @param root Value of the root XML_Node.
608  */
609  void setRoot(const XML_Node& root);
610 
611  //! Main routine to create an tree-like representation of an XML file
612  /*!
613  * Given an input stream, this routine will read matched XML tags
614  * representing the ctml file until an EOF is read from the file.
615  * This routine is called by the root XML_Node object.
616  *
617  * @param f Input stream containing the ascii input file
618  */
619  void build(std::istream& f);
620 
621  //! Copy all of the information in the current XML_Node tree
622  //! into the destination XML_Node tree, doing a union operation as
623  //! we go
624  /*!
625  * Note this is a const function because the current XML_Node and
626  * its children isn't altered by this operation.
627  * copyUnion() doesn't duplicate existing entries in the
628  * destination XML_Node tree.
629  *
630  * @param node_dest This is the XML node to receive the information
631  */
632  void copyUnion(XML_Node* const node_dest) const;
633 
634  //! Copy all of the information in the current XML_Node tree
635  //! into the destination XML_Node tree, doing a complete copy
636  //! as we go.
637  /*!
638  * Note this is a const function because the current XML_Node and
639  * its children isn't altered by this operation.
640  *
641  * @param node_dest This is the XML node to receive the information
642  */
643  void copy(XML_Node* const node_dest) const;
644 
645  //! Set the lock for this node and all of its children
646  void lock();
647 
648  //! Unset the lock for this node and all of its children
649  void unlock();
650 
651 private:
652  //! Write an XML subtree to an output stream.
653  /*!
654  * This is the main recursive routine. It doesn't put a final endl
655  * on. This is fixed up in the public method. A method to only write out a limited
656  * amount of the xml tree has been added.
657  *
658  * @param s ostream to write to
659  * @param level Indentation level to work from
660  * @param numRecursivesAllowed Number of recursive calls allowed
661  */
662  void write_int(std::ostream& s, int level = 0, int numRecursivesAllowed = 60000) const;
663 
664 protected:
665  //! XML node name of the node.
666  /*!
667  * For example, if we were in the XML_Node where
668  *
669  * <phase dim="3" id="gas">
670  * </phase>
671  *
672  * Then, this string would be equal to "phase". "dim" and "id"
673  * are attributes of the XML_Node.
674  */
675  std::string m_name;
676 
677  //! Value of the xml node
678  /*!
679  * This is the string contents of the XML node. For
680  * example. The xml node named eps:
681  *
682  * <eps>
683  * valueString
684  * </eps>
685  *
686  * has a m_value string containing "valueString".
687  */
688  std::string m_value;
689 
690  //! Map containing an index between the node name and the
691  //! pointer to the node
692  /*!
693  * m_childindex[node.name()] = XML_Node *pointer
694  *
695  * This object helps to speed up searches.
696  */
697  std::multimap<std::string, XML_Node*> m_childindex;
698 
699  //! Storage of attributes for a node
700  /*!
701  * m_attribs[attribName] = attribValue
702  */
703  std::map<std::string, std::string> m_attribs;
704 
705  //! Pointer to the parent XML_Node for the current node
706  /*!
707  * Note, the top node has a parent value of 0
708  */
710 
711  //! Pointer to the root XML_Node for the current node
712  /*!
713  * Note, the top node has a root value equal to itself
714  */
716 
717  //! Lock for this node
718  /*!
719  * Currently, unimplemented functionality. If locked,
720  * it means you can't delete this node.
721  */
722  bool m_locked;
723 
724  //! Vector of pointers to child nodes
725  std::vector<XML_Node*> m_children;
726 
727  //! Number of children of this node
728  size_t m_nchildren;
729 
730  //! True if the current node is a comment node
732 
733  //! The member data m_linenum
734  /*!
735  * Currently, unimplemented functionality
736  */
738 };
739 
740 //! Search an XML_Node tree for a named phase XML_Node
741 /*!
742  * Search for a phase Node matching a name.
743  *
744  * @param root Starting XML_Node* pointer for the search
745  * @param phaseName Name of the phase to search for
746  *
747  * @return Returns the XML_Node pointer if the phase is found.
748  * If the phase is not found, it returns 0
749  */
750 XML_Node* findXMLPhase(XML_Node* root, const std::string& phaseName);
751 
752 }
753 
754 #endif
void setName(const std::string &name_)
Sets the name of the XML node.
Definition: xml.h:398
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:716
integer int_value() const
Return the value of an XML node as a single int.
Definition: xml.cpp:503
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:614
std::vector< XML_Node * > m_children
Vector of pointers to child nodes.
Definition: xml.h:725
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:627
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:155
std::string readTag(std::map< std::string, std::string > &attribs)
Reads an XML tag into a string.
Definition: xml.cpp:234
XML_Node * findXMLPhase(XML_Node *root, const std::string &idtarget)
Search an XML_Node tree for a named phase XML_Node.
Definition: xml.cpp:1104
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:534
void clear()
Clear the current node and everything under it.
Definition: xml.cpp:379
const std::vector< XML_Node * > & children() const
Return an unchangeable reference to the vector of children of the current node.
Definition: xml.cpp:589
void unlock()
Unset the lock for this node and all of its children.
Definition: xml.cpp:908
std::map< std::string, std::string > & attribs()
Returns a changeable value of the attributes map for the current node.
Definition: xml.cpp:543
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
size_t m_nchildren
Number of children of this node.
Definition: xml.h:728
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:660
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, HTML_logs (see Input File Handling, Diagnostic Output, Writing messages to the screen and Writing HTML Logfiles).
std::map< std::string, std::string > m_attribs
Storage of attributes for a node.
Definition: xml.h:703
const std::map< std::string, std::string > & attribsConst() const
Returns an unchangeable value of the attributes map for the current node.
Definition: xml.cpp:548
XML_Node * setParent(XML_Node *const p)
Sets the pointer for the parent node of the current node.
Definition: xml.cpp:568
std::string m_value
Value of the xml node.
Definition: xml.h:688
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:584
void addValue(const std::string &val)
Modify the value for the current node.
Definition: xml.cpp:475
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:754
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:194
XML_Reader(std::istream &input)
Sole Constructor for the XML_Reader class.
Definition: xml.cpp:111
bool m_locked
Lock for this node.
Definition: xml.h:722
XML_Node * m_root
Pointer to the root XML_Node for the current node.
Definition: xml.h:715
void lock()
Set the lock for this node and all of its children.
Definition: xml.cpp:900
bool m_iscomment
True if the current node is a comment node.
Definition: xml.h:731
std::string name() const
Returns the name of the XML node.
Definition: xml.h:390
XML_Node(const std::string &nm="--", XML_Node *const parent=0)
Constructor for XML_Node, representing a tree structure.
Definition: xml.cpp:312
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:574
void write(std::ostream &s, const int level=0, int numRecursivesAllowed=60000) const
Write an XML subtree to an output stream.
Definition: xml.cpp:1078
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:709
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
Definition: xml.cpp:518
void setLineNumber(const int n)
Set the line number.
Definition: xml.cpp:553
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:875
void setRoot(const XML_Node &root)
Set the root XML_Node value within the current node.
Definition: xml.cpp:1096
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:488
std::string m_name
XML node name of the node.
Definition: xml.h:675
int lineNumber() const
Return the line number.
Definition: xml.cpp:558
std::string readValue()
Return the value portion of an XML element.
Definition: xml.cpp:280
std::string id() const
Return the id attribute, if present.
Definition: xml.cpp:467
void removeChild(const XML_Node *const node)
Remove a child from this node's list of children.
Definition: xml.cpp:458
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:697
void writeHeader(std::ostream &s)
Write the header to the xml file to the specified ostream.
Definition: xml.cpp:771
bool isComment() const
Boolean function indicating whether a comment.
Definition: xml.cpp:609
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:529
doublereal fp_value() const
Return the value of an XML node as a single double.
Definition: xml.cpp:498
XML_Node & root() const
Return the root of the current XML_Node tree.
Definition: xml.cpp:1091
XML_Node * parent() const
Returns a pointer to the parent node of the current node.
Definition: xml.cpp:563
int m_linenum
The member data m_linenum.
Definition: xml.h:737
void build(std::istream &f)
Main routine to create an tree-like representation of an XML file.
Definition: xml.cpp:776
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:697
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:821
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:594
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:916
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:579
void write_int(std::ostream &s, int level=0, int numRecursivesAllowed=60000) const
Write an XML subtree to an output stream.
Definition: xml.cpp:955
void getchr(char &ch)
Read a single character from the input stream and returns it.
Definition: xml.cpp:117
std::string operator()() const
Overloaded parenthesis operator returns the value of the Node.
Definition: xml.cpp:493