Cantera  2.5.1
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 https://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  *
27  * @deprecated The XML input format is deprecated and will be removed in
28  * Cantera 3.0.
29  */
31 {
32 public:
33  //! Sole Constructor for the XML_Reader class
34  /*!
35  * @param input Reference to the istream object containing the XML file
36  */
37  XML_Reader(std::istream& input);
38 
39  //! Read a single character from the input stream and returns it
40  /*!
41  * All low level reads occur through this function. The function also keeps
42  * track of the line numbers.
43  *
44  * @param ch Character to be returned.
45  */
46  void getchr(char& ch);
47 
48  //! Searches a string for the first occurrence of a valid quoted string.
49  /*!
50  * Quotes can start with either a single quote or a double quote, but must
51  * also end with the same type. Quotes may be commented out by preceding
52  * with a backslash character, '\\'.
53  *
54  * @param aline This is the input string to be searched
55  * @param rstring Return value of the string that is found.
56  * The quotes are stripped from the string.
57  * @returns the integer position just after 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 in between
62  //! 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  * @deprecated The XML input format is deprecated and will be removed in
101  * Cantera 3.0.
102  */
103 class XML_Node
104 {
105 public:
106  //! Constructor for XML_Node, representing a tree structure
107  /*!
108  * @param nm Name of the node.
109  * @param parent Pointer to the parent for this node in the tree.
110  * A value of 0 indicates this is the top of the tree.
111  */
112  explicit XML_Node(const std::string& nm="--", XML_Node* const parent=0);
113 
114  XML_Node(const XML_Node& right);
115  XML_Node& operator=(const XML_Node& right);
116  virtual ~XML_Node();
117 
118  //! Clear the current node and everything under it
119  /*!
120  * The value, attributes and children are all zeroed. The name and the
121  * parent information is kept.
122  */
123  void clear();
124 
125  //! Merge an existing node as a child node to the current node
126  /*!
127  * This will merge an XML_Node as a child to the current node. Note, this
128  * actually adds the node. Therefore, the current node is changed. There is
129  * no copy made of the child node. The child node should not be deleted in
130  * the future
131  *
132  * @param node Reference to a child XML_Node object
133  * @returns a reference to the added child node
134  */
136 
137  // Add a child node to the current node by making a copy of an existing node
138  // tree
139  /*
140  * This will add an XML_Node as a child to the current node. Note, this
141  * actually adds the node. Therefore, node is changed. A copy is made of the
142  * underlying tree
143  *
144  * @param node Reference to a child XML_Node object
145  * @returns a reference to the added node
146  */
147  XML_Node& addChild(const XML_Node& node);
148 
149  //! Add a child node to the current node with a specified name
150  /*!
151  * This will add an XML_Node as a child to the current node.
152  * The node will be blank except for the specified name.
153  *
154  * @param sname Name of the new child
155  * @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 same time add a
160  //! 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  * @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 same time add a
173  //! formatted value to the child
174  /*!
175  * This version supplies a formatting string (printf format) to the output
176  * 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  * @returns a reference to the created child XML_Node object
186  */
187  XML_Node& addChild(const std::string& name, const doublereal value,
188  const std::string& fmt="%g");
189 
190  //! Remove a child from this node's list of children
191  /*!
192  * This function removes an XML_Node from the children of this node.
193  *
194  * @param node Pointer to the node to be removed. Note, this node
195  * isn't modified in any way.
196  */
197  void removeChild(const XML_Node* const node);
198 
199  //! Add a child node to the current node containing a comment
200  /*!
201  * Child node will have the name, comment.
202  *
203  * @param comment Content of the comment
204  */
205  void addComment(const std::string& comment);
206 
207  //! Modify the value for the current node
208  /*!
209  * This functions fills in the m_value field of the current node
210  *
211  * @param val string Value that the node will be assigned
212  */
213  void addValue(const std::string& val);
214 
215  //! Modify the value for the current node
216  /*!
217  * This functions fills in the m_value field of the current node
218  * with a formatted double value
219  *
220  * @param val double Value that the node will be assigned
221  * @param fmt Format of the printf string conversion of the double.
222  * Default is "%g". Must be less than 63 chars
223  */
224  void addValue(const doublereal val, const std::string& fmt="%g");
225 
226  //! Return the value of an XML node as a string
227  /*!
228  * This is a simple accessor routine
229  */
230  std::string value() 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 node, for which you
235  * 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 node, for which you
243  * 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 interpret it as a
250  * 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 interpret it as a
257  * 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  * @returns a string representing the value of the attribute within the XML
309  * node. If there is no attribute with the given name, it returns
310  * the null string.
311  */
312  std::string operator[](const std::string& attr) const;
313 
314  //! Function returns the value of an attribute
315  /*!
316  * This function searches the attributes vector for the attribute named
317  * 'attr'. If a match is found, the attribute value is returned as a
318  * string. If no match is found, the empty string is returned.
319  *
320  * @param attr String containing the attribute to be searched for.
321  * @return If a match is found, the attribute value is returned as a
322  * string. If no match is found, the empty string is returned.
323  */
324  std::string attrib(const std::string& attr) const;
325 
326 private:
327  //! Returns a changeable value of the attributes map for the current node
328  /*!
329  * Note this is a simple accessor routine. And, it is a private function.
330  * It's used in some internal copy and assignment routines
331  */
332  std::map<std::string,std::string>& attribs();
333 
334 public:
335  //! Returns an unchangeable value of the attributes map for the current node
336  const std::map<std::string,std::string>& attribsConst() const;
337 
338  //! Set the line number
339  /*!
340  * @param n the member data m_linenum is set to n
341  */
342  void setLineNumber(const int n);
343 
344  //! Return the line number
345  int lineNumber() const;
346 
347  //! Returns a pointer to the parent node of the current node
348  XML_Node* parent() const;
349 
350  //! Sets the pointer for the parent node of the current node
351  /*!
352  * @param p Pointer to the parent node
353  * @returns the pointer p
354  */
355  XML_Node* setParent(XML_Node* const p);
356 
357  //! Tests whether the current node has a child node with a particular name
358  /*!
359  * @param ch Name of the child node to test
360  * @returns true if the child node exists, false otherwise.
361  */
362  bool hasChild(const std::string& ch) const;
363 
364  //! Tests whether the current node has an attribute with a particular name
365  /*!
366  * @param a Name of the attribute to test
367  * @returns true if the attribute exists, false otherwise.
368  */
369  bool hasAttrib(const std::string& a) const;
370 
371  //! Returns the name of the XML node
372  std::string name() const {
373  return m_name;
374  }
375 
376  //! Sets the name of the XML node
377  /*!
378  * @param name_ The name of the XML node
379  */
380  void setName(const std::string& name_) {
381  m_name = name_;
382  }
383 
384  //! Return the id attribute, if present
385  /*!
386  * Returns the id attribute if present. If not it return the empty string
387  */
388  std::string id() const;
389 
390  //! Return a changeable reference to the n'th child of the current node
391  /*!
392  * @param n Number of the child to return
393  */
394  XML_Node& child(const size_t n) const;
395 
396  //! Return an unchangeable reference to the vector of children of the current node
397  /*!
398  * Each of the individual XML_Node child pointers, however, is pointing to a
399  * changeable XML node object.
400  */
401  const std::vector<XML_Node*>& children() const;
402 
403  //! Return the number of children
404  /*!
405  * @param discardComments If true comments are discarded when adding up the
406  * number of children. Defaults to false.
407  */
408  size_t nChildren(bool discardComments = false) const;
409 
410  //! Boolean function indicating whether a comment
411  bool isComment() const;
412 
413  //! Require that the current XML node has an attribute named by the first
414  //! argument, a, and that this attribute has the string value listed in
415  //! the second argument, v.
416  /*!
417  * @param a attribute name
418  * @param v required value of the attribute
419  *
420  * If the condition is not true, an exception is thrown
421  */
422  void _require(const std::string& a, const std::string& v) const;
423 
424  //! This routine carries out a recursive search for an XML node based
425  //! on both the XML element name and the attribute ID.
426  /*!
427  * If exact matches are found for both fields, the pointer
428  * to the matching XML Node is returned.
429  *
430  * The ID attribute may be defaulted by setting it to "". In this case the
431  * pointer to the first XML element matching the name only is returned.
432  *
433  * @param nameTarget Name of the XML Node that is being searched for
434  * @param idTarget "id" attribute of the XML Node that the routine
435  * looks for
436  * @returns the pointer to the XML node that fits the criteria
437  *
438  * @internal
439  * This algorithm does a lateral search of first generation children
440  * first before diving deeper into each tree branch.
441  */
442  XML_Node* findNameID(const std::string& nameTarget,
443  const std::string& idTarget) const;
444 
445  //! This routine carries out a search for an XML node based on the XML
446  //! element name, the attribute ID and an integer index.
447  /*!
448  * If exact matches are found for all fields, the pointer
449  * to the matching XML Node is returned. The search is only carried out on
450  * the current element and the child elements of the current element.
451  *
452  * The "id" attribute may be defaulted by setting it to "". In this case the
453  * pointer to the first XML element matching the name and the Index is returned.
454  *
455  * @param nameTarget Name of the XML Node that is being searched for
456  * @param idTarget "id" attribute of the XML Node that the routine
457  * looks for
458  * @param index Integer describing the index. The index is an
459  * attribute of the form index = "3"
460  * @returns the pointer to the XML node that fits the criteria
461  */
462  XML_Node* findNameIDIndex(const std::string& nameTarget,
463  const std::string& idTarget, const int index) const;
464 
465  //! This routine carries out a recursive search for an XML node based
466  //! on the XML element attribute "id"
467  /*!
468  * If exact match is found, the pointer to the matching XML Node is
469  * returned. If not, 0 is returned.
470  *
471  * @param id "id" attribute of the XML Node that the routine looks for
472  * @param depth Depth of the search.
473  * @returns the pointer to the XML node that fits the criteria
474  *
475  * @internal
476  * This algorithm does a lateral search of first generation children
477  * first before diving deeper into each tree branch.
478  */
479  XML_Node* findID(const std::string& id, const int depth=100) const;
480 
481  //! This routine carries out a recursive search for an XML node based
482  //! on an attribute of each XML node
483  /*!
484  * If exact match is found with respect to the attribute name and value of
485  * the attribute, the pointer to the matching XML Node is returned. If
486  * not, 0 is returned.
487  *
488  * @param attr Attribute of the XML Node that the routine looks for
489  * @param val Value of the attribute
490  * @param depth Depth of the search. A value of 1 means that only the
491  * immediate children are searched.
492  * @returns the pointer to the XML node that fits the criteria
493  */
494  XML_Node* findByAttr(const std::string& attr, const std::string& val,
495  int depth = 100000) const;
496 
497  //! This routine carries out a recursive search for an XML node based
498  //! on the name of the node.
499  /*!
500  * If exact match is found with respect to XML_Node name, the pointer to the
501  * matching XML Node is returned. If not, 0 is returned. This is the const
502  * version of the routine.
503  *
504  * @param nm Name of the XML node
505  * @param depth Depth of the search. A value of 1 means that only the
506  * immediate children are searched.
507  * @returns the pointer to the XML node that fits the criteria
508  */
509  const XML_Node* findByName(const std::string& nm, int depth = 100000) const;
510 
511  //! This routine carries out a recursive search for an XML node based
512  //! on the name of the node.
513  /*!
514  * If exact match is found with respect to XML_Node name, the pointer
515  * to the matching XML Node is returned. If not, 0 is returned.
516  * This is the non-const version of the routine.
517  *
518  * @param nm Name of the XML node
519  * @param depth Depth of the search. A value of 1 means that only the
520  * immediate children are searched.
521  * @returns the pointer to the XML node that fits the criteria
522  */
523  XML_Node* findByName(const std::string& nm, int depth = 100000);
524 
525  //! Get a vector of pointers to XML_Node containing all of the children
526  //! of the current node which match the given name
527  /*!
528  * @param name Name of the XML_Node children to search for
529  * @return vector of pointers to child XML_Nodes with the matching name
530  */
531  std::vector<XML_Node*> getChildren(const std::string& name) const;
532 
533  //! Return a changeable reference to a child of the current node, named by
534  //! the argument
535  /*!
536  * Note the underlying data allows for more than one XML element with the
537  * same name. This routine returns the first child with the given name.
538  *
539  * @param loc Name of the child to return
540  */
541  XML_Node& child(const std::string& loc) const;
542 
543  //! Write the header to the XML file to the specified ostream
544  /*!
545  * @param s ostream to write the output to
546  */
547  void writeHeader(std::ostream& s);
548 
549  //! Write an XML subtree to an output stream.
550  /*!
551  * This is a wrapper around the static routine write_int(). All this does
552  * is add an endl on to the output stream. write_int() is fine, but the
553  * last endl wasn't being written.
554  *
555  * @param s ostream to write to
556  * @param level Indentation level to work from
557  * @param numRecursivesAllowed Number of recursive calls allowed
558  */
559  void write(std::ostream& s, const int level = 0, int numRecursivesAllowed = 60000) const;
560 
561  //! Return the root of the current XML_Node tree
562  /*!
563  * Returns a reference to the root of the current XML tree
564  */
565  XML_Node& root() const;
566 
567  //! Set the root XML_Node value within the current node
568  /*!
569  * @param root Value of the root XML_Node.
570  */
571  void setRoot(const XML_Node& root);
572 
573  //! Populate the XML tree from an input file
574  void build(const std::string& filename);
575 
576  //! Main routine to create an tree-like representation of an XML file
577  /*!
578  * Given an input stream, this routine will read matched XML tags
579  * representing the ctml file until an EOF is read from the file. This
580  * routine is called by the root XML_Node object.
581  *
582  * @param f Input stream containing the ascii input file
583  * @param filename Name of the input file, used in error messages
584  */
585  void build(std::istream& f, const std::string& filename="[unknown]");
586 
587  //! Copy all of the information in the current XML_Node tree into the
588  //! destination XML_Node tree, doing a union operation as we go
589  /*!
590  * Note this is a const function because the current XML_Node and its
591  * children isn't altered by this operation. copyUnion() doesn't duplicate
592  * existing entries in the destination XML_Node tree.
593  *
594  * @param node_dest This is the XML node to receive the information
595  */
596  void copyUnion(XML_Node* const node_dest) const;
597 
598  //! Copy all of the information in the current XML_Node tree into the
599  //! destination XML_Node tree, doing a complete copy as we go.
600  /*!
601  * Note this is a const function because the current XML_Node and its
602  * children isn't altered by this operation.
603  *
604  * @param node_dest This is the XML node to receive the information
605  */
606  void copy(XML_Node* const node_dest) const;
607 
608  //! Set the lock for this node and all of its children
609  void lock();
610 
611  //! Unset the lock for this node and all of its children
612  void unlock();
613 
614 private:
615  //! Write an XML subtree to an output stream.
616  /*!
617  * This is the main recursive routine. It doesn't put a final endl on. This
618  * is fixed up in the public method. A method to only write out a limited
619  * amount of the XML tree has been added.
620  *
621  * @param s ostream to write to
622  * @param level Indentation level to work from
623  * @param numRecursivesAllowed Number of recursive calls allowed
624  */
625  void write_int(std::ostream& s, int level = 0, int numRecursivesAllowed = 60000) const;
626 
627 protected:
628  //! XML node name of the node.
629  /*!
630  * For example, if we were in the XML_Node where
631  *
632  * <phase dim="3" id="gas">
633  * </phase>
634  *
635  * Then, this string would be equal to "phase". "dim" and "id" are
636  * attributes of the XML_Node.
637  */
638  std::string m_name;
639 
640  //! Value of the XML node
641  /*!
642  * This is the string contents of the XML node. For example. The XML node
643  * named eps:
644  *
645  * <eps>
646  * valueString
647  * </eps>
648  *
649  * has a m_value string containing "valueString".
650  */
651  std::string m_value;
652 
653  //! Name of the file from which this XML node was read. Only populated for
654  //! the root node.
655  std::string m_filename;
656 
657  //! Map containing an index between the node name and the
658  //! pointer to the node
659  /*!
660  * m_childindex[node.name()] = XML_Node *pointer
661  *
662  * This object helps to speed up searches.
663  */
664  std::multimap<std::string, XML_Node*> m_childindex;
665 
666  //! Storage of attributes for a node
667  /*!
668  * m_attribs[attribName] = attribValue
669  */
670  std::map<std::string, std::string> m_attribs;
671 
672  //! Pointer to the parent XML_Node for the current node
673  /*!
674  * Note, the top node has a parent value of 0
675  */
677 
678  //! Pointer to the root XML_Node for the current node
679  /*!
680  * Note, the top node has a root value equal to itself
681  */
683 
684  //! Lock for this node
685  /*!
686  * Currently, unimplemented functionality. If locked,
687  * it means you can't delete this node.
688  */
689  bool m_locked;
690 
691  //! Vector of pointers to child nodes
692  std::vector<XML_Node*> m_children;
693 
694  //! True if the current node is a comment node
696 
697  //! The member data m_linenum
698  /*!
699  * Currently, unimplemented functionality
700  */
702 };
703 
704 //! Search an XML_Node tree for a named phase XML_Node
705 /*!
706  * Search for a phase Node matching an id.
707  *
708  * @param root Starting XML_Node* pointer for the search
709  * @param phaseId id of the phase to search for
710  * @returns the XML_Node pointer if the phase is found. If the phase is not
711  * found, it returns 0
712  *
713  * @deprecated The XML input format is deprecated and will be removed in
714  * Cantera 3.0.
715  */
716 XML_Node* findXMLPhase(XML_Node* root, const std::string& phaseId);
717 
718 }
719 
720 #endif
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:104
void removeChild(const XML_Node *const node)
Remove a child from this node's list of children.
Definition: xml.cpp:416
std::map< std::string, std::string > m_attribs
Storage of attributes for a node.
Definition: xml.h:670
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
void setName(const std::string &name_)
Sets the name of the XML node.
Definition: xml.h:380
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:492
XML_Node(const std::string &nm="--", XML_Node *const parent=0)
Constructor for XML_Node, representing a tree structure.
Definition: xml.cpp:309
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:871
std::string name() const
Returns the name of the XML node.
Definition: xml.h:372
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:528
int lineNumber() const
Return the line number.
Definition: xml.cpp:512
void build(const std::string &filename)
Populate the XML tree from an input file.
Definition: xml.cpp:762
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:451
XML_Node * m_root
Pointer to the root XML_Node for the current node.
Definition: xml.h:682
XML_Node & mergeAsChild(XML_Node &node)
Merge an existing node as a child node to the current node.
Definition: xml.cpp:382
void write_int(std::ostream &s, int level=0, int numRecursivesAllowed=60000) const
Write an XML subtree to an output stream.
Definition: xml.cpp:915
std::string id() const
Return the id attribute, if present.
Definition: xml.cpp:538
XML_Node & root() const
Return the root of the current XML_Node tree.
Definition: xml.cpp:749
void addValue(const std::string &val)
Modify the value for the current node.
Definition: xml.cpp:428
std::map< std::string, std::string > & attribs()
Returns a changeable value of the attributes map for the current node.
Definition: xml.cpp:497
int m_linenum
The member data m_linenum.
Definition: xml.h:701
XML_Node * m_parent
Pointer to the parent XML_Node for the current node.
Definition: xml.h:676
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
Definition: xml.cpp:466
bool m_locked
Lock for this node.
Definition: xml.h:689
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:827
bool m_iscomment
True if the current node is a comment node.
Definition: xml.h:695
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:679
integer int_value() const
Return the value of an XML node as a single int.
Definition: xml.cpp:461
void unlock()
Unset the lock for this node and all of its children.
Definition: xml.cpp:902
void write(std::ostream &s, const int level=0, int numRecursivesAllowed=60000) const
Write an XML subtree to an output stream.
Definition: xml.cpp:1032
void _require(const std::string &a, const std::string &v) const
Require that the current XML node has an attribute named by the first argument, a,...
Definition: xml.cpp:576
doublereal fp_value() const
Return the value of an XML node as a single double.
Definition: xml.cpp:456
void writeHeader(std::ostream &s)
Write the header to the XML file to the specified ostream.
Definition: xml.cpp:910
void lock()
Set the lock for this node and all of its children.
Definition: xml.cpp:894
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 "id".
Definition: xml.cpp:645
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:664
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_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 the XML element name, the attribute ID and...
Definition: xml.cpp:616
void setLineNumber(const int n)
Set the line number.
Definition: xml.cpp:507
XML_Node * parent() const
Returns a pointer to the parent node of the current node.
Definition: xml.cpp:517
std::string m_filename
Name of the file from which this XML node was read.
Definition: xml.h:655
void clear()
Clear the current node and everything under it.
Definition: xml.cpp:365
void addComment(const std::string &comment)
Add a child node to the current node containing a comment.
Definition: xml.cpp:423
const std::map< std::string, std::string > & attribsConst() const
Returns an unchangeable value of the attributes map for the current node.
Definition: xml.cpp:502
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:711
std::string value() const
Return the value of an XML node as a string.
Definition: xml.cpp:441
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
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:487
std::string m_value
Value of the XML node.
Definition: xml.h:651
size_t nChildren(bool discardComments=false) const
Return the number of children.
Definition: xml.cpp:556
XML_Node * setParent(XML_Node *const p)
Sets the pointer for the parent node of the current node.
Definition: xml.cpp:522
std::string m_name
XML node name of the node.
Definition: xml.h:638
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:546
void setRoot(const XML_Node &root)
Set the root XML_Node value within the current node.
Definition: xml.cpp:754
std::vector< XML_Node * > m_children
Vector of pointers to child nodes.
Definition: xml.h:692
bool isComment() const
Boolean function indicating whether a comment.
Definition: xml.cpp:571
bool hasAttrib(const std::string &a) const
Tests whether the current node has an attribute with a particular name.
Definition: xml.cpp:533
Class XML_Reader reads an XML file into an XML_Node object.
Definition: xml.h:31
std::string readTag(std::map< std::string, std::string > &attribs)
Reads an XML tag into a string.
Definition: xml.cpp:231
int m_line
Line count.
Definition: xml.h:92
void getchr(char &ch)
Read a single character from the input stream and returns it.
Definition: xml.cpp:121
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
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_Reader(std::istream &input)
Sole Constructor for the XML_Reader class.
Definition: xml.cpp:115
std::istream & m_s
Input stream containing the XML file.
Definition: xml.h:88
std::string readValue()
Return the value portion of an XML element.
Definition: xml.cpp:278
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
This file contains definitions for utility functions and text for modules, inputfiles,...
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
XML_Node * findXMLPhase(XML_Node *root, const std::string &phaseId)
Search an XML_Node tree for a named phase XML_Node.
Definition: xml.cpp:1038
Versions 6.2.0 and 6.2.1 of fmtlib do not include this define before they include windows....
Definition: fmt.h:35