NDDEM
pugixml.hpp
Go to the documentation of this file.
1 
14 // Define version macro; evaluates to major * 1000 + minor * 10 + patch so that it's safe to use in less-than comparisons
15 // Note: pugixml used major * 100 + minor * 10 + patch format up until 1.9 (which had version identifier 190); starting from pugixml 1.10, the minor version number is two digits
16 #ifndef PUGIXML_VERSION
17 # define PUGIXML_VERSION 1130 // 1.13
18 #endif
19 
20 // Include user configuration file (this can define various configuration macros)
21 #include "pugiconfig.hpp"
22 
23 #ifndef HEADER_PUGIXML_HPP
24 #define HEADER_PUGIXML_HPP
25 
26 // Include stddef.h for size_t and ptrdiff_t
27 #include <stddef.h>
28 
29 // Include exception header for XPath
30 #if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
31 # include <exception>
32 #endif
33 
34 // Include STL headers
35 #ifndef PUGIXML_NO_STL
36 # include <iterator>
37 # include <iosfwd>
38 # include <string>
39 #endif
40 
41 // Macro for deprecated features
42 #ifndef PUGIXML_DEPRECATED
43 # if defined(__GNUC__)
44 # define PUGIXML_DEPRECATED __attribute__((deprecated))
45 # elif defined(_MSC_VER) && _MSC_VER >= 1300
46 # define PUGIXML_DEPRECATED __declspec(deprecated)
47 # else
48 # define PUGIXML_DEPRECATED
49 # endif
50 #endif
51 
52 // If no API is defined, assume default
53 #ifndef PUGIXML_API
54 # define PUGIXML_API
55 #endif
56 
57 // If no API for classes is defined, assume default
58 #ifndef PUGIXML_CLASS
59 # define PUGIXML_CLASS PUGIXML_API
60 #endif
61 
62 // If no API for functions is defined, assume default
63 #ifndef PUGIXML_FUNCTION
64 # define PUGIXML_FUNCTION PUGIXML_API
65 #endif
66 
67 // If the platform is known to have long long support, enable long long functions
68 #ifndef PUGIXML_HAS_LONG_LONG
69 # if __cplusplus >= 201103
70 # define PUGIXML_HAS_LONG_LONG
71 # elif defined(_MSC_VER) && _MSC_VER >= 1400
72 # define PUGIXML_HAS_LONG_LONG
73 # endif
74 #endif
75 
76 // If the platform is known to have move semantics support, compile move ctor/operator implementation
77 #ifndef PUGIXML_HAS_MOVE
78 # if __cplusplus >= 201103
79 # define PUGIXML_HAS_MOVE
80 # elif defined(_MSC_VER) && _MSC_VER >= 1600
81 # define PUGIXML_HAS_MOVE
82 # endif
83 #endif
84 
85 // If C++ is 2011 or higher, add 'noexcept' specifiers
86 #ifndef PUGIXML_NOEXCEPT
87 # if __cplusplus >= 201103
88 # define PUGIXML_NOEXCEPT noexcept
89 # elif defined(_MSC_VER) && _MSC_VER >= 1900
90 # define PUGIXML_NOEXCEPT noexcept
91 # else
92 # define PUGIXML_NOEXCEPT
93 # endif
94 #endif
95 
96 // Some functions can not be noexcept in compact mode
97 #ifdef PUGIXML_COMPACT
98 # define PUGIXML_NOEXCEPT_IF_NOT_COMPACT
99 #else
100 # define PUGIXML_NOEXCEPT_IF_NOT_COMPACT PUGIXML_NOEXCEPT
101 #endif
102 
103 // If C++ is 2011 or higher, add 'override' qualifiers
104 #ifndef PUGIXML_OVERRIDE
105 # if __cplusplus >= 201103
106 # define PUGIXML_OVERRIDE override
107 # elif defined(_MSC_VER) && _MSC_VER >= 1700
108 # define PUGIXML_OVERRIDE override
109 # else
110 # define PUGIXML_OVERRIDE
111 # endif
112 #endif
113 
114 // If C++ is 2011 or higher, use 'nullptr'
115 #ifndef PUGIXML_NULL
116 # if __cplusplus >= 201103
117 # define PUGIXML_NULL nullptr
118 # elif defined(_MSC_VER) && _MSC_VER >= 1600
119 # define PUGIXML_NULL nullptr
120 # else
121 # define PUGIXML_NULL 0
122 # endif
123 #endif
124 
125 // Character interface macros
126 #ifdef PUGIXML_WCHAR_MODE
127 # define PUGIXML_TEXT(t) L ## t
128 # define PUGIXML_CHAR wchar_t
129 #else
130 # define PUGIXML_TEXT(t) t
131 # define PUGIXML_CHAR char
132 #endif
133 
134 namespace pugi
135 {
136  // Character type used for all internal storage and operations; depends on PUGIXML_WCHAR_MODE
138 
139 #ifndef PUGIXML_NO_STL
140  // String type used for operations that work with STL string; depends on PUGIXML_WCHAR_MODE
141  typedef std::basic_string<PUGIXML_CHAR, std::char_traits<PUGIXML_CHAR>, std::allocator<PUGIXML_CHAR> > string_t;
142 #endif
143 }
144 
145 // The PugiXML namespace
146 namespace pugi
147 {
148  // Tree node types
150  {
151  node_null, // Empty (null) node handle
152  node_document, // A document tree's absolute root
153  node_element, // Element tag, i.e. '<node/>'
154  node_pcdata, // Plain character data, i.e. 'text'
155  node_cdata, // Character data, i.e. '<![CDATA[text]]>'
156  node_comment, // Comment tag, i.e. '<!-- text -->'
157  node_pi, // Processing instruction, i.e. '<?name?>'
158  node_declaration, // Document declaration, i.e. '<?xml version="1.0"?>'
159  node_doctype // Document type declaration, i.e. '<!DOCTYPE doc>'
160  };
161 
162  // Parsing options
163 
164  // Minimal parsing mode (equivalent to turning all other flags off).
165  // Only elements and PCDATA sections are added to the DOM tree, no text conversions are performed.
166  const unsigned int parse_minimal = 0x0000;
167 
168  // This flag determines if processing instructions (node_pi) are added to the DOM tree. This flag is off by default.
169  const unsigned int parse_pi = 0x0001;
170 
171  // This flag determines if comments (node_comment) are added to the DOM tree. This flag is off by default.
172  const unsigned int parse_comments = 0x0002;
173 
174  // This flag determines if CDATA sections (node_cdata) are added to the DOM tree. This flag is on by default.
175  const unsigned int parse_cdata = 0x0004;
176 
177  // This flag determines if plain character data (node_pcdata) that consist only of whitespace are added to the DOM tree.
178  // This flag is off by default; turning it on usually results in slower parsing and more memory consumption.
179  const unsigned int parse_ws_pcdata = 0x0008;
180 
181  // This flag determines if character and entity references are expanded during parsing. This flag is on by default.
182  const unsigned int parse_escapes = 0x0010;
183 
184  // This flag determines if EOL characters are normalized (converted to #xA) during parsing. This flag is on by default.
185  const unsigned int parse_eol = 0x0020;
186 
187  // This flag determines if attribute values are normalized using CDATA normalization rules during parsing. This flag is on by default.
188  const unsigned int parse_wconv_attribute = 0x0040;
189 
190  // This flag determines if attribute values are normalized using NMTOKENS normalization rules during parsing. This flag is off by default.
191  const unsigned int parse_wnorm_attribute = 0x0080;
192 
193  // This flag determines if document declaration (node_declaration) is added to the DOM tree. This flag is off by default.
194  const unsigned int parse_declaration = 0x0100;
195 
196  // This flag determines if document type declaration (node_doctype) is added to the DOM tree. This flag is off by default.
197  const unsigned int parse_doctype = 0x0200;
198 
199  // This flag determines if plain character data (node_pcdata) that is the only child of the parent node and that consists only
200  // of whitespace is added to the DOM tree.
201  // This flag is off by default; turning it on may result in slower parsing and more memory consumption.
202  const unsigned int parse_ws_pcdata_single = 0x0400;
203 
204  // This flag determines if leading and trailing whitespace is to be removed from plain character data. This flag is off by default.
205  const unsigned int parse_trim_pcdata = 0x0800;
206 
207  // This flag determines if plain character data that does not have a parent node is added to the DOM tree, and if an empty document
208  // is a valid document. This flag is off by default.
209  const unsigned int parse_fragment = 0x1000;
210 
211  // This flag determines if plain character data is be stored in the parent element's value. This significantly changes the structure of
212  // the document; this flag is only recommended for parsing documents with many PCDATA nodes in memory-constrained environments.
213  // This flag is off by default.
214  const unsigned int parse_embed_pcdata = 0x2000;
215 
216  // The default parsing mode.
217  // Elements, PCDATA and CDATA sections are added to the DOM tree, character/reference entities are expanded,
218  // End-of-Line characters are normalized, attribute values are normalized using CDATA normalization rules.
220 
221  // The full parsing mode.
222  // Nodes of all types are added to the DOM tree, character/reference entities are expanded,
223  // End-of-Line characters are normalized, attribute values are normalized using CDATA normalization rules.
225 
226  // These flags determine the encoding of input data for XML document
228  {
229  encoding_auto, // Auto-detect input encoding using BOM or < / <? detection; use UTF8 if BOM is not found
230  encoding_utf8, // UTF8 encoding
231  encoding_utf16_le, // Little-endian UTF16
232  encoding_utf16_be, // Big-endian UTF16
233  encoding_utf16, // UTF16 with native endianness
234  encoding_utf32_le, // Little-endian UTF32
235  encoding_utf32_be, // Big-endian UTF32
236  encoding_utf32, // UTF32 with native endianness
237  encoding_wchar, // The same encoding wchar_t has (either UTF16 or UTF32)
239  };
240 
241  // Formatting flags
242 
243  // Indent the nodes that are written to output stream with as many indentation strings as deep the node is in DOM tree. This flag is on by default.
244  const unsigned int format_indent = 0x01;
245 
246  // Write encoding-specific BOM to the output stream. This flag is off by default.
247  const unsigned int format_write_bom = 0x02;
248 
249  // Use raw output mode (no indentation and no line breaks are written). This flag is off by default.
250  const unsigned int format_raw = 0x04;
251 
252  // Omit default XML declaration even if there is no declaration in the document. This flag is off by default.
253  const unsigned int format_no_declaration = 0x08;
254 
255  // Don't escape attribute values and PCDATA contents. This flag is off by default.
256  const unsigned int format_no_escapes = 0x10;
257 
258  // Open file using text mode in xml_document::save_file. This enables special character (i.e. new-line) conversions on some systems. This flag is off by default.
259  const unsigned int format_save_file_text = 0x20;
260 
261  // Write every attribute on a new line with appropriate indentation. This flag is off by default.
262  const unsigned int format_indent_attributes = 0x40;
263 
264  // Don't output empty element tags, instead writing an explicit start and end tag even if there are no children. This flag is off by default.
265  const unsigned int format_no_empty_element_tags = 0x80;
266 
267  // Skip characters belonging to range [0; 32) instead of "&#xNN;" encoding. This flag is off by default.
268  const unsigned int format_skip_control_chars = 0x100;
269 
270  // Use single quotes ' instead of double quotes " for enclosing attribute values. This flag is off by default.
271  const unsigned int format_attribute_single_quote = 0x200;
272 
273  // The default set of formatting flags.
274  // Nodes are indented depending on their depth in DOM tree, a default declaration is output if document has none.
275  const unsigned int format_default = format_indent;
276 
277  const int default_double_precision = 17;
278  const int default_float_precision = 9;
279 
280  // Forward declarations
281  struct xml_attribute_struct;
282  struct xml_node_struct;
283 
284  class xml_node_iterator;
287 
288  class xml_tree_walker;
289 
290  struct xml_parse_result;
291 
292  class xml_node;
293 
294  class xml_text;
295 
296  #ifndef PUGIXML_NO_XPATH
297  class xpath_node;
298  class xpath_node_set;
299  class xpath_query;
300  class xpath_variable_set;
301  #endif
302 
303  // Range-based for loop support
304  template <typename It> class xml_object_range
305  {
306  public:
307  typedef It const_iterator;
308  typedef It iterator;
309 
310  xml_object_range(It b, It e): _begin(b), _end(e)
311  {
312  }
313 
314  It begin() const { return _begin; }
315  It end() const { return _end; }
316 
317  bool empty() const { return _begin == _end; }
318 
319  private:
321  };
322 
323  // Writer interface for node printing (see xml_node::print)
325  {
326  public:
327  virtual ~xml_writer();
328 
329  // Write memory chunk into stream/file/whatever
330  virtual void write(const void* data, size_t size) = 0;
331  };
332 
333  // xml_writer implementation for FILE*
335  {
336  public:
337  // Construct writer from a FILE* object; void* is used to avoid header dependencies on stdio
338  xml_writer_file(void* file);
339 
340  virtual void write(const void* data, size_t size) PUGIXML_OVERRIDE;
341 
342  private:
343  void* file;
344  };
345 
346  #ifndef PUGIXML_NO_STL
347  // xml_writer implementation for streams
349  {
350  public:
351  // Construct writer from an output stream object
352  xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream);
353  xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream);
354 
355  virtual void write(const void* data, size_t size) PUGIXML_OVERRIDE;
356 
357  private:
358  std::basic_ostream<char, std::char_traits<char> >* narrow_stream;
359  std::basic_ostream<wchar_t, std::char_traits<wchar_t> >* wide_stream;
360  };
361  #endif
362 
363  // A light-weight handle for manipulating attributes in DOM tree
365  {
367  friend class xml_node;
368 
369  private:
371 
372  typedef void (*unspecified_bool_type)(xml_attribute***);
373 
374  public:
375  // Default constructor. Constructs an empty attribute.
376  xml_attribute();
377 
378  // Constructs attribute from internal pointer
379  explicit xml_attribute(xml_attribute_struct* attr);
380 
381  // Safe bool conversion operator
382  operator unspecified_bool_type() const;
383 
384  // Borland C++ workaround
385  bool operator!() const;
386 
387  // Comparison operators (compares wrapped attribute pointers)
388  bool operator==(const xml_attribute& r) const;
389  bool operator!=(const xml_attribute& r) const;
390  bool operator<(const xml_attribute& r) const;
391  bool operator>(const xml_attribute& r) const;
392  bool operator<=(const xml_attribute& r) const;
393  bool operator>=(const xml_attribute& r) const;
394 
395  // Check if attribute is empty
396  bool empty() const;
397 
398  // Get attribute name/value, or "" if attribute is empty
399  const char_t* name() const;
400  const char_t* value() const;
401 
402  // Get attribute value, or the default value if attribute is empty
403  const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;
404 
405  // Get attribute value as a number, or the default value if conversion did not succeed or attribute is empty
406  int as_int(int def = 0) const;
407  unsigned int as_uint(unsigned int def = 0) const;
408  double as_double(double def = 0) const;
409  float as_float(float def = 0) const;
410 
411  #ifdef PUGIXML_HAS_LONG_LONG
412  long long as_llong(long long def = 0) const;
413  unsigned long long as_ullong(unsigned long long def = 0) const;
414  #endif
415 
416  // Get attribute value as bool (returns true if first character is in '1tTyY' set), or the default value if attribute is empty
417  bool as_bool(bool def = false) const;
418 
419  // Set attribute name/value (returns false if attribute is empty or there is not enough memory)
420  bool set_name(const char_t* rhs);
421  bool set_value(const char_t* rhs, size_t sz);
422  bool set_value(const char_t* rhs);
423 
424  // Set attribute value with type conversion (numbers are converted to strings, boolean is converted to "true"/"false")
425  bool set_value(int rhs);
426  bool set_value(unsigned int rhs);
427  bool set_value(long rhs);
428  bool set_value(unsigned long rhs);
429  bool set_value(double rhs);
430  bool set_value(double rhs, int precision);
431  bool set_value(float rhs);
432  bool set_value(float rhs, int precision);
433  bool set_value(bool rhs);
434 
435  #ifdef PUGIXML_HAS_LONG_LONG
436  bool set_value(long long rhs);
437  bool set_value(unsigned long long rhs);
438  #endif
439 
440  // Set attribute value (equivalent to set_value without error checking)
441  xml_attribute& operator=(const char_t* rhs);
442  xml_attribute& operator=(int rhs);
443  xml_attribute& operator=(unsigned int rhs);
444  xml_attribute& operator=(long rhs);
445  xml_attribute& operator=(unsigned long rhs);
446  xml_attribute& operator=(double rhs);
447  xml_attribute& operator=(float rhs);
448  xml_attribute& operator=(bool rhs);
449 
450  #ifdef PUGIXML_HAS_LONG_LONG
451  xml_attribute& operator=(long long rhs);
452  xml_attribute& operator=(unsigned long long rhs);
453  #endif
454 
455  // Get next/previous attribute in the attribute list of the parent node
456  xml_attribute next_attribute() const;
457  xml_attribute previous_attribute() const;
458 
459  // Get hash value (unique for handles to the same object)
460  size_t hash_value() const;
461 
462  // Get internal pointer
463  xml_attribute_struct* internal_object() const;
464  };
465 
466 #ifdef __BORLANDC__
467  // Borland C++ workaround
468  bool PUGIXML_FUNCTION operator&&(const xml_attribute& lhs, bool rhs);
469  bool PUGIXML_FUNCTION operator||(const xml_attribute& lhs, bool rhs);
470 #endif
471 
472  // A light-weight handle for manipulating nodes in DOM tree
474  {
476  friend class xml_node_iterator;
478 
479  protected:
481 
482  typedef void (*unspecified_bool_type)(xml_node***);
483 
484  public:
485  // Default constructor. Constructs an empty node.
486  xml_node();
487 
488  // Constructs node from internal pointer
489  explicit xml_node(xml_node_struct* p);
490 
491  // Safe bool conversion operator
492  operator unspecified_bool_type() const;
493 
494  // Borland C++ workaround
495  bool operator!() const;
496 
497  // Comparison operators (compares wrapped node pointers)
498  bool operator==(const xml_node& r) const;
499  bool operator!=(const xml_node& r) const;
500  bool operator<(const xml_node& r) const;
501  bool operator>(const xml_node& r) const;
502  bool operator<=(const xml_node& r) const;
503  bool operator>=(const xml_node& r) const;
504 
505  // Check if node is empty.
506  bool empty() const;
507 
508  // Get node type
509  xml_node_type type() const;
510 
511  // Get node name, or "" if node is empty or it has no name
512  const char_t* name() const;
513 
514  // Get node value, or "" if node is empty or it has no value
515  // Note: For <node>text</node> node.value() does not return "text"! Use child_value() or text() methods to access text inside nodes.
516  const char_t* value() const;
517 
518  // Get attribute list
519  xml_attribute first_attribute() const;
520  xml_attribute last_attribute() const;
521 
522  // Get children list
523  xml_node first_child() const;
524  xml_node last_child() const;
525 
526  // Get next/previous sibling in the children list of the parent node
527  xml_node next_sibling() const;
528  xml_node previous_sibling() const;
529 
530  // Get parent node
531  xml_node parent() const;
532 
533  // Get root of DOM tree this node belongs to
534  xml_node root() const;
535 
536  // Get text object for the current node
537  xml_text text() const;
538 
539  // Get child, attribute or next/previous sibling with the specified name
540  xml_node child(const char_t* name) const;
541  xml_attribute attribute(const char_t* name) const;
542  xml_node next_sibling(const char_t* name) const;
543  xml_node previous_sibling(const char_t* name) const;
544 
545  // Get attribute, starting the search from a hint (and updating hint so that searching for a sequence of attributes is fast)
546  xml_attribute attribute(const char_t* name, xml_attribute& hint) const;
547 
548  // Get child value of current node; that is, value of the first child node of type PCDATA/CDATA
549  const char_t* child_value() const;
550 
551  // Get child value of child with specified name. Equivalent to child(name).child_value().
552  const char_t* child_value(const char_t* name) const;
553 
554  // Set node name/value (returns false if node is empty, there is not enough memory, or node can not have name/value)
555  bool set_name(const char_t* rhs);
556  bool set_value(const char_t* rhs, size_t sz);
557  bool set_value(const char_t* rhs);
558 
559  // Add attribute with specified name. Returns added attribute, or empty attribute on errors.
562  xml_attribute insert_attribute_after(const char_t* name, const xml_attribute& attr);
563  xml_attribute insert_attribute_before(const char_t* name, const xml_attribute& attr);
564 
565  // Add a copy of the specified attribute. Returns added attribute, or empty attribute on errors.
566  xml_attribute append_copy(const xml_attribute& proto);
567  xml_attribute prepend_copy(const xml_attribute& proto);
568  xml_attribute insert_copy_after(const xml_attribute& proto, const xml_attribute& attr);
569  xml_attribute insert_copy_before(const xml_attribute& proto, const xml_attribute& attr);
570 
571  // Add child node with specified type. Returns added node, or empty node on errors.
572  xml_node append_child(xml_node_type type = node_element);
573  xml_node prepend_child(xml_node_type type = node_element);
574  xml_node insert_child_after(xml_node_type type, const xml_node& node);
575  xml_node insert_child_before(xml_node_type type, const xml_node& node);
576 
577  // Add child element with specified name. Returns added node, or empty node on errors.
578  xml_node append_child(const char_t* name);
579  xml_node prepend_child(const char_t* name);
580  xml_node insert_child_after(const char_t* name, const xml_node& node);
581  xml_node insert_child_before(const char_t* name, const xml_node& node);
582 
583  // Add a copy of the specified node as a child. Returns added node, or empty node on errors.
584  xml_node append_copy(const xml_node& proto);
585  xml_node prepend_copy(const xml_node& proto);
586  xml_node insert_copy_after(const xml_node& proto, const xml_node& node);
587  xml_node insert_copy_before(const xml_node& proto, const xml_node& node);
588 
589  // Move the specified node to become a child of this node. Returns moved node, or empty node on errors.
590  xml_node append_move(const xml_node& moved);
591  xml_node prepend_move(const xml_node& moved);
592  xml_node insert_move_after(const xml_node& moved, const xml_node& node);
593  xml_node insert_move_before(const xml_node& moved, const xml_node& node);
594 
595  // Remove specified attribute
596  bool remove_attribute(const xml_attribute& a);
597  bool remove_attribute(const char_t* name);
598 
599  // Remove all attributes
600  bool remove_attributes();
601 
602  // Remove specified child
603  bool remove_child(const xml_node& n);
604  bool remove_child(const char_t* name);
605 
606  // Remove all children
607  bool remove_children();
608 
609  // Parses buffer as an XML document fragment and appends all nodes as children of the current node.
610  // Copies/converts the buffer, so it may be deleted or changed after the function returns.
611  // Note: append_buffer allocates memory that has the lifetime of the owning document; removing the appended nodes does not immediately reclaim that memory.
612  xml_parse_result append_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
613 
614  // Find attribute using predicate. Returns first attribute for which predicate returned true.
615  template <typename Predicate> xml_attribute find_attribute(Predicate pred) const
616  {
617  if (!_root) return xml_attribute();
618 
619  for (xml_attribute attrib = first_attribute(); attrib; attrib = attrib.next_attribute())
620  if (pred(attrib))
621  return attrib;
622 
623  return xml_attribute();
624  }
625 
626  // Find child node using predicate. Returns first child for which predicate returned true.
627  template <typename Predicate> xml_node find_child(Predicate pred) const
628  {
629  if (!_root) return xml_node();
630 
631  for (xml_node node = first_child(); node; node = node.next_sibling())
632  if (pred(node))
633  return node;
634 
635  return xml_node();
636  }
637 
638  // Find node from subtree using predicate. Returns first node from subtree (depth-first), for which predicate returned true.
639  template <typename Predicate> xml_node find_node(Predicate pred) const
640  {
641  if (!_root) return xml_node();
642 
643  xml_node cur = first_child();
644 
645  while (cur._root && cur._root != _root)
646  {
647  if (pred(cur)) return cur;
648 
649  if (cur.first_child()) cur = cur.first_child();
650  else if (cur.next_sibling()) cur = cur.next_sibling();
651  else
652  {
653  while (!cur.next_sibling() && cur._root != _root) cur = cur.parent();
654 
655  if (cur._root != _root) cur = cur.next_sibling();
656  }
657  }
658 
659  return xml_node();
660  }
661 
662  // Find child node by attribute name/value
663  xml_node find_child_by_attribute(const char_t* name, const char_t* attr_name, const char_t* attr_value) const;
664  xml_node find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const;
665 
666  #ifndef PUGIXML_NO_STL
667  // Get the absolute node path from root as a text string.
668  string_t path(char_t delimiter = '/') const;
669  #endif
670 
671  // Search for a node by path consisting of node names and . or .. elements.
672  xml_node first_element_by_path(const char_t* path, char_t delimiter = '/') const;
673 
674  // Recursively traverse subtree with xml_tree_walker
675  bool traverse(xml_tree_walker& walker);
676 
677  #ifndef PUGIXML_NO_XPATH
678  // Select single node by evaluating XPath query. Returns first node from the resulting node set.
679  xpath_node select_node(const char_t* query, xpath_variable_set* variables = PUGIXML_NULL) const;
680  xpath_node select_node(const xpath_query& query) const;
681 
682  // Select node set by evaluating XPath query
683  xpath_node_set select_nodes(const char_t* query, xpath_variable_set* variables = PUGIXML_NULL) const;
684  xpath_node_set select_nodes(const xpath_query& query) const;
685 
686  // (deprecated: use select_node instead) Select single node by evaluating XPath query.
687  PUGIXML_DEPRECATED xpath_node select_single_node(const char_t* query, xpath_variable_set* variables = PUGIXML_NULL) const;
688  PUGIXML_DEPRECATED xpath_node select_single_node(const xpath_query& query) const;
689 
690  #endif
691 
692  // Print subtree using a writer object
693  void print(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;
694 
695  #ifndef PUGIXML_NO_STL
696  // Print subtree to stream
697  void print(std::basic_ostream<char, std::char_traits<char> >& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;
698  void print(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, unsigned int depth = 0) const;
699  #endif
700 
701  // Child nodes iterators
703 
704  iterator begin() const;
705  iterator end() const;
706 
707  // Attribute iterators
709 
710  attribute_iterator attributes_begin() const;
711  attribute_iterator attributes_end() const;
712 
713  // Range-based for support
714  xml_object_range<xml_node_iterator> children() const;
715  xml_object_range<xml_attribute_iterator> attributes() const;
716 
717  // Range-based for support for all children with the specified name
718  // Note: name pointer must have a longer lifetime than the returned object; be careful with passing temporaries!
719  xml_object_range<xml_named_node_iterator> children(const char_t* name) const;
720 
721  // Get node offset in parsed file/string (in char_t units) for debugging purposes
722  ptrdiff_t offset_debug() const;
723 
724  // Get hash value (unique for handles to the same object)
725  size_t hash_value() const;
726 
727  // Get internal pointer
728  xml_node_struct* internal_object() const;
729  };
730 
731 #ifdef __BORLANDC__
732  // Borland C++ workaround
733  bool PUGIXML_FUNCTION operator&&(const xml_node& lhs, bool rhs);
734  bool PUGIXML_FUNCTION operator||(const xml_node& lhs, bool rhs);
735 #endif
736 
737  // A helper for working with text inside PCDATA nodes
739  {
740  friend class xml_node;
741 
743 
744  typedef void (*unspecified_bool_type)(xml_text***);
745 
746  explicit xml_text(xml_node_struct* root);
747 
748  xml_node_struct* _data_new();
749  xml_node_struct* _data() const;
750 
751  public:
752  // Default constructor. Constructs an empty object.
753  xml_text();
754 
755  // Safe bool conversion operator
756  operator unspecified_bool_type() const;
757 
758  // Borland C++ workaround
759  bool operator!() const;
760 
761  // Check if text object is empty
762  bool empty() const;
763 
764  // Get text, or "" if object is empty
765  const char_t* get() const;
766 
767  // Get text, or the default value if object is empty
768  const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;
769 
770  // Get text as a number, or the default value if conversion did not succeed or object is empty
771  int as_int(int def = 0) const;
772  unsigned int as_uint(unsigned int def = 0) const;
773  double as_double(double def = 0) const;
774  float as_float(float def = 0) const;
775 
776  #ifdef PUGIXML_HAS_LONG_LONG
777  long long as_llong(long long def = 0) const;
778  unsigned long long as_ullong(unsigned long long def = 0) const;
779  #endif
780 
781  // Get text as bool (returns true if first character is in '1tTyY' set), or the default value if object is empty
782  bool as_bool(bool def = false) const;
783 
784  // Set text (returns false if object is empty or there is not enough memory)
785  bool set(const char_t* rhs, size_t sz);
786  bool set(const char_t* rhs);
787 
788  // Set text with type conversion (numbers are converted to strings, boolean is converted to "true"/"false")
789  bool set(int rhs);
790  bool set(unsigned int rhs);
791  bool set(long rhs);
792  bool set(unsigned long rhs);
793  bool set(double rhs);
794  bool set(double rhs, int precision);
795  bool set(float rhs);
796  bool set(float rhs, int precision);
797  bool set(bool rhs);
798 
799  #ifdef PUGIXML_HAS_LONG_LONG
800  bool set(long long rhs);
801  bool set(unsigned long long rhs);
802  #endif
803 
804  // Set text (equivalent to set without error checking)
805  xml_text& operator=(const char_t* rhs);
806  xml_text& operator=(int rhs);
807  xml_text& operator=(unsigned int rhs);
808  xml_text& operator=(long rhs);
809  xml_text& operator=(unsigned long rhs);
810  xml_text& operator=(double rhs);
811  xml_text& operator=(float rhs);
812  xml_text& operator=(bool rhs);
813 
814  #ifdef PUGIXML_HAS_LONG_LONG
815  xml_text& operator=(long long rhs);
816  xml_text& operator=(unsigned long long rhs);
817  #endif
818 
819  // Get the data node (node_pcdata or node_cdata) for this object
820  xml_node data() const;
821  };
822 
823 #ifdef __BORLANDC__
824  // Borland C++ workaround
825  bool PUGIXML_FUNCTION operator&&(const xml_text& lhs, bool rhs);
826  bool PUGIXML_FUNCTION operator||(const xml_text& lhs, bool rhs);
827 #endif
828 
829  // Child node iterator (a bidirectional iterator over a collection of xml_node)
831  {
832  friend class xml_node;
833 
834  private:
835  mutable xml_node _wrap;
837 
839 
840  public:
841  // Iterator traits
842  typedef ptrdiff_t difference_type;
844  typedef xml_node* pointer;
845  typedef xml_node& reference;
846 
847  #ifndef PUGIXML_NO_STL
848  typedef std::bidirectional_iterator_tag iterator_category;
849  #endif
850 
851  // Default constructor
853 
854  // Construct an iterator which points to the specified node
855  xml_node_iterator(const xml_node& node);
856 
857  // Iterator operators
858  bool operator==(const xml_node_iterator& rhs) const;
859  bool operator!=(const xml_node_iterator& rhs) const;
860 
861  xml_node& operator*() const;
862  xml_node* operator->() const;
863 
864  xml_node_iterator& operator++();
865  xml_node_iterator operator++(int);
866 
867  xml_node_iterator& operator--();
868  xml_node_iterator operator--(int);
869  };
870 
871  // Attribute iterator (a bidirectional iterator over a collection of xml_attribute)
873  {
874  friend class xml_node;
875 
876  private:
879 
881 
882  public:
883  // Iterator traits
884  typedef ptrdiff_t difference_type;
888 
889  #ifndef PUGIXML_NO_STL
890  typedef std::bidirectional_iterator_tag iterator_category;
891  #endif
892 
893  // Default constructor
895 
896  // Construct an iterator which points to the specified attribute
897  xml_attribute_iterator(const xml_attribute& attr, const xml_node& parent);
898 
899  // Iterator operators
900  bool operator==(const xml_attribute_iterator& rhs) const;
901  bool operator!=(const xml_attribute_iterator& rhs) const;
902 
903  xml_attribute& operator*() const;
904  xml_attribute* operator->() const;
905 
906  xml_attribute_iterator& operator++();
907  xml_attribute_iterator operator++(int);
908 
909  xml_attribute_iterator& operator--();
910  xml_attribute_iterator operator--(int);
911  };
912 
913  // Named node range helper
915  {
916  friend class xml_node;
917 
918  public:
919  // Iterator traits
920  typedef ptrdiff_t difference_type;
922  typedef xml_node* pointer;
923  typedef xml_node& reference;
924 
925  #ifndef PUGIXML_NO_STL
926  typedef std::bidirectional_iterator_tag iterator_category;
927  #endif
928 
929  // Default constructor
931 
932  // Construct an iterator which points to the specified node
933  // Note: name pointer is stored in the iterator and must have a longer lifetime than iterator itself
934  xml_named_node_iterator(const xml_node& node, const char_t* name);
935 
936  // Iterator operators
937  bool operator==(const xml_named_node_iterator& rhs) const;
938  bool operator!=(const xml_named_node_iterator& rhs) const;
939 
940  xml_node& operator*() const;
941  xml_node* operator->() const;
942 
943  xml_named_node_iterator& operator++();
944  xml_named_node_iterator operator++(int);
945 
946  xml_named_node_iterator& operator--();
947  xml_named_node_iterator operator--(int);
948 
949  private:
950  mutable xml_node _wrap;
952  const char_t* _name;
953 
955  };
956 
957  // Abstract tree walker class (see xml_node::traverse)
959  {
960  friend class xml_node;
961 
962  private:
963  int _depth;
964 
965  protected:
966  // Get current traversal depth
967  int depth() const;
968 
969  public:
970  xml_tree_walker();
971  virtual ~xml_tree_walker();
972 
973  // Callback that is called when traversal begins
974  virtual bool begin(xml_node& node);
975 
976  // Callback that is called for each node traversed
977  virtual bool for_each(xml_node& node) = 0;
978 
979  // Callback that is called when traversal ends
980  virtual bool end(xml_node& node);
981  };
982 
983  // Parsing status, returned as part of xml_parse_result object
985  {
986  status_ok = 0, // No error
987 
988  status_file_not_found, // File was not found during load_file()
989  status_io_error, // Error reading from file/stream
990  status_out_of_memory, // Could not allocate memory
991  status_internal_error, // Internal error occurred
992 
993  status_unrecognized_tag, // Parser could not determine tag type
994 
995  status_bad_pi, // Parsing error occurred while parsing document declaration/processing instruction
996  status_bad_comment, // Parsing error occurred while parsing comment
997  status_bad_cdata, // Parsing error occurred while parsing CDATA section
998  status_bad_doctype, // Parsing error occurred while parsing document type declaration
999  status_bad_pcdata, // Parsing error occurred while parsing PCDATA section
1000  status_bad_start_element, // Parsing error occurred while parsing start element tag
1001  status_bad_attribute, // Parsing error occurred while parsing element attribute
1002  status_bad_end_element, // Parsing error occurred while parsing end element tag
1003  status_end_element_mismatch,// There was a mismatch of start-end tags (closing tag had incorrect name, some tag was not closed or there was an excessive closing tag)
1004 
1005  status_append_invalid_root, // Unable to append nodes since root type is not node_element or node_document (exclusive to xml_node::append_buffer)
1006 
1007  status_no_document_element // Parsing resulted in a document without element nodes
1008  };
1009 
1010  // Parsing result
1012  {
1013  // Parsing status (see xml_parse_status)
1015 
1016  // Last parsed offset (in char_t units from start of input data)
1017  ptrdiff_t offset;
1018 
1019  // Source document encoding
1021 
1022  // Default constructor, initializes object to failed state
1023  xml_parse_result();
1024 
1025  // Cast to bool operator
1026  operator bool() const;
1027 
1028  // Get error description
1029  const char* description() const;
1030  };
1031 
1032  // Document class (DOM tree root)
1034  {
1035  private:
1037 
1038  char _memory[192];
1039 
1040  // Non-copyable semantics
1043 
1044  void _create();
1045  void _destroy();
1047 
1048  public:
1049  // Default constructor, makes empty document
1050  xml_document();
1051 
1052  // Destructor, invalidates all node/attribute handles to this document
1053  ~xml_document();
1054 
1055  #ifdef PUGIXML_HAS_MOVE
1056  // Move semantics support
1059  #endif
1060 
1061  // Removes all nodes, leaving the empty document
1062  void reset();
1063 
1064  // Removes all nodes, then copies the entire contents of the specified document
1065  void reset(const xml_document& proto);
1066 
1067  #ifndef PUGIXML_NO_STL
1068  // Load document from stream.
1069  xml_parse_result load(std::basic_istream<char, std::char_traits<char> >& stream, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1070  xml_parse_result load(std::basic_istream<wchar_t, std::char_traits<wchar_t> >& stream, unsigned int options = parse_default);
1071  #endif
1072 
1073  // (deprecated: use load_string instead) Load document from zero-terminated string. No encoding conversions are applied.
1074  PUGIXML_DEPRECATED xml_parse_result load(const char_t* contents, unsigned int options = parse_default);
1075 
1076  // Load document from zero-terminated string. No encoding conversions are applied.
1077  xml_parse_result load_string(const char_t* contents, unsigned int options = parse_default);
1078 
1079  // Load document from file
1080  xml_parse_result load_file(const char* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1081  xml_parse_result load_file(const wchar_t* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1082 
1083  // Load document from buffer. Copies/converts the buffer, so it may be deleted or changed after the function returns.
1084  xml_parse_result load_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1085 
1086  // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data).
1087  // You should ensure that buffer data will persist throughout the document's lifetime, and free the buffer memory manually once document is destroyed.
1088  xml_parse_result load_buffer_inplace(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1089 
1090  // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data).
1091  // You should allocate the buffer with pugixml allocation function; document will free the buffer when it is no longer needed (you can't use it anymore).
1092  xml_parse_result load_buffer_inplace_own(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
1093 
1094  // Save XML document to writer (semantics is slightly different from xml_node::print, see documentation for details).
1095  void save(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
1096 
1097  #ifndef PUGIXML_NO_STL
1098  // Save XML document to stream (semantics is slightly different from xml_node::print, see documentation for details).
1099  void save(std::basic_ostream<char, std::char_traits<char> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
1100  void save(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default) const;
1101  #endif
1102 
1103  // Save XML to file
1104  bool save_file(const char* path, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
1105  bool save_file(const wchar_t* path, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
1106 
1107  // Get document element
1108  xml_node document_element() const;
1109  };
1110 
1111 #ifndef PUGIXML_NO_XPATH
1112  // XPath query return type
1114  {
1115  xpath_type_none, // Unknown type (query failed to compile)
1116  xpath_type_node_set, // Node set (xpath_node_set)
1119  xpath_type_boolean // Boolean
1120  };
1121 
1122  // XPath parsing result
1124  {
1125  // Error message (0 if no error)
1126  const char* error;
1127 
1128  // Last parsed offset (in char_t units from string start)
1129  ptrdiff_t offset;
1130 
1131  // Default constructor, initializes object to failed state
1133 
1134  // Cast to bool operator
1135  operator bool() const;
1136 
1137  // Get error description
1138  const char* description() const;
1139  };
1140 
1141  // A single XPath variable
1143  {
1144  friend class xpath_variable_set;
1145 
1146  protected:
1149 
1151 
1152  // Non-copyable semantics
1155 
1156  public:
1157  // Get variable name
1158  const char_t* name() const;
1159 
1160  // Get variable type
1161  xpath_value_type type() const;
1162 
1163  // Get variable value; no type conversion is performed, default value (false, NaN, empty string, empty node set) is returned on type mismatch error
1164  bool get_boolean() const;
1165  double get_number() const;
1166  const char_t* get_string() const;
1167  const xpath_node_set& get_node_set() const;
1168 
1169  // Set variable value; no type conversion is performed, false is returned on type mismatch error
1170  bool set(bool value);
1171  bool set(double value);
1172  bool set(const char_t* value);
1173  bool set(const xpath_node_set& value);
1174  };
1175 
1176  // A set of XPath variables
1178  {
1179  private:
1180  xpath_variable* _data[64];
1181 
1182  void _assign(const xpath_variable_set& rhs);
1183  void _swap(xpath_variable_set& rhs);
1184 
1185  xpath_variable* _find(const char_t* name) const;
1186 
1187  static bool _clone(xpath_variable* var, xpath_variable** out_result);
1188  static void _destroy(xpath_variable* var);
1189 
1190  public:
1191  // Default constructor/destructor
1193  ~xpath_variable_set();
1194 
1195  // Copy constructor/assignment operator
1197  xpath_variable_set& operator=(const xpath_variable_set& rhs);
1198 
1199  #ifdef PUGIXML_HAS_MOVE
1200  // Move semantics support
1203  #endif
1204 
1205  // Add a new variable or get the existing one, if the types match
1206  xpath_variable* add(const char_t* name, xpath_value_type type);
1207 
1208  // Set value of an existing variable; no type conversion is performed, false is returned if there is no such variable or if types mismatch
1209  bool set(const char_t* name, bool value);
1210  bool set(const char_t* name, double value);
1211  bool set(const char_t* name, const char_t* value);
1212  bool set(const char_t* name, const xpath_node_set& value);
1213 
1214  // Get existing variable by name
1215  xpath_variable* get(const char_t* name);
1216  const xpath_variable* get(const char_t* name) const;
1217  };
1218 
1219  // A compiled XPath query object
1221  {
1222  private:
1223  void* _impl;
1225 
1226  typedef void (*unspecified_bool_type)(xpath_query***);
1227 
1228  // Non-copyable semantics
1231 
1232  public:
1233  // Construct a compiled object from XPath expression.
1234  // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on compilation errors.
1235  explicit xpath_query(const char_t* query, xpath_variable_set* variables = PUGIXML_NULL);
1236 
1237  // Constructor
1238  xpath_query();
1239 
1240  // Destructor
1241  ~xpath_query();
1242 
1243  #ifdef PUGIXML_HAS_MOVE
1244  // Move semantics support
1246  xpath_query& operator=(xpath_query&& rhs) PUGIXML_NOEXCEPT;
1247  #endif
1248 
1249  // Get query expression return type
1250  xpath_value_type return_type() const;
1251 
1252  // Evaluate expression as boolean value in the specified context; performs type conversion if necessary.
1253  // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
1254  bool evaluate_boolean(const xpath_node& n) const;
1255 
1256  // Evaluate expression as double value in the specified context; performs type conversion if necessary.
1257  // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
1258  double evaluate_number(const xpath_node& n) const;
1259 
1260  #ifndef PUGIXML_NO_STL
1261  // Evaluate expression as string value in the specified context; performs type conversion if necessary.
1262  // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
1263  string_t evaluate_string(const xpath_node& n) const;
1264  #endif
1265 
1266  // Evaluate expression as string value in the specified context; performs type conversion if necessary.
1267  // At most capacity characters are written to the destination buffer, full result size is returned (includes terminating zero).
1268  // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
1269  // If PUGIXML_NO_EXCEPTIONS is defined, returns empty set instead.
1270  size_t evaluate_string(char_t* buffer, size_t capacity, const xpath_node& n) const;
1271 
1272  // Evaluate expression as node set in the specified context.
1273  // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on type mismatch and std::bad_alloc on out of memory errors.
1274  // If PUGIXML_NO_EXCEPTIONS is defined, returns empty node set instead.
1275  xpath_node_set evaluate_node_set(const xpath_node& n) const;
1276 
1277  // Evaluate expression as node set in the specified context.
1278  // Return first node in document order, or empty node if node set is empty.
1279  // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on type mismatch and std::bad_alloc on out of memory errors.
1280  // If PUGIXML_NO_EXCEPTIONS is defined, returns empty node instead.
1281  xpath_node evaluate_node(const xpath_node& n) const;
1282 
1283  // Get parsing result (used to get compilation errors in PUGIXML_NO_EXCEPTIONS mode)
1284  const xpath_parse_result& result() const;
1285 
1286  // Safe bool conversion operator
1287  operator unspecified_bool_type() const;
1288 
1289  // Borland C++ workaround
1290  bool operator!() const;
1291  };
1292 
1293  #ifndef PUGIXML_NO_EXCEPTIONS
1294  #if defined(_MSC_VER)
1295  // C4275 can be ignored in Visual C++ if you are deriving
1296  // from a type in the Standard C++ Library
1297  #pragma warning(push)
1298  #pragma warning(disable: 4275)
1299  #endif
1300  // XPath exception class
1301  class PUGIXML_CLASS xpath_exception: public std::exception
1302  {
1303  private:
1305 
1306  public:
1307  // Construct exception from parse result
1308  explicit xpath_exception(const xpath_parse_result& result);
1309 
1310  // Get error message
1311  virtual const char* what() const throw() PUGIXML_OVERRIDE;
1312 
1313  // Get parse result
1314  const xpath_parse_result& result() const;
1315  };
1316  #if defined(_MSC_VER)
1317  #pragma warning(pop)
1318  #endif
1319  #endif
1320 
1321  // XPath node class (either xml_node or xml_attribute)
1323  {
1324  private:
1327 
1328  typedef void (*unspecified_bool_type)(xpath_node***);
1329 
1330  public:
1331  // Default constructor; constructs empty XPath node
1332  xpath_node();
1333 
1334  // Construct XPath node from XML node/attribute
1335  xpath_node(const xml_node& node);
1336  xpath_node(const xml_attribute& attribute, const xml_node& parent);
1337 
1338  // Get node/attribute, if any
1339  xml_node node() const;
1340  xml_attribute attribute() const;
1341 
1342  // Get parent of contained node/attribute
1343  xml_node parent() const;
1344 
1345  // Safe bool conversion operator
1346  operator unspecified_bool_type() const;
1347 
1348  // Borland C++ workaround
1349  bool operator!() const;
1350 
1351  // Comparison operators
1352  bool operator==(const xpath_node& n) const;
1353  bool operator!=(const xpath_node& n) const;
1354  };
1355 
1356 #ifdef __BORLANDC__
1357  // Borland C++ workaround
1358  bool PUGIXML_FUNCTION operator&&(const xpath_node& lhs, bool rhs);
1359  bool PUGIXML_FUNCTION operator||(const xpath_node& lhs, bool rhs);
1360 #endif
1361 
1362  // A fixed-size collection of XPath nodes
1364  {
1365  public:
1366  // Collection type
1367  enum type_t
1368  {
1369  type_unsorted, // Not ordered
1370  type_sorted, // Sorted by document order (ascending)
1371  type_sorted_reverse // Sorted by document order (descending)
1372  };
1373 
1374  // Constant iterator type
1375  typedef const xpath_node* const_iterator;
1376 
1377  // We define non-constant iterator to be the same as constant iterator so that various generic algorithms (i.e. boost foreach) work
1378  typedef const xpath_node* iterator;
1379 
1380  // Default constructor. Constructs empty set.
1381  xpath_node_set();
1382 
1383  // Constructs a set from iterator range; data is not checked for duplicates and is not sorted according to provided type, so be careful
1384  xpath_node_set(const_iterator begin, const_iterator end, type_t type = type_unsorted);
1385 
1386  // Destructor
1387  ~xpath_node_set();
1388 
1389  // Copy constructor/assignment operator
1390  xpath_node_set(const xpath_node_set& ns);
1391  xpath_node_set& operator=(const xpath_node_set& ns);
1392 
1393  #ifdef PUGIXML_HAS_MOVE
1394  // Move semantics support
1397  #endif
1398 
1399  // Get collection type
1400  type_t type() const;
1401 
1402  // Get collection size
1403  size_t size() const;
1404 
1405  // Indexing operator
1406  const xpath_node& operator[](size_t index) const;
1407 
1408  // Collection iterators
1409  const_iterator begin() const;
1410  const_iterator end() const;
1411 
1412  // Sort the collection in ascending/descending order by document order
1413  void sort(bool reverse = false);
1414 
1415  // Get first node in the collection by document order
1416  xpath_node first() const;
1417 
1418  // Check if collection is empty
1419  bool empty() const;
1420 
1421  private:
1423 
1424  xpath_node _storage[1];
1425 
1428 
1429  void _assign(const_iterator begin, const_iterator end, type_t type);
1431  };
1432 #endif
1433 
1434 #ifndef PUGIXML_NO_STL
1435  // Convert wide string to UTF8
1436  std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const wchar_t* str);
1437  std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >& str);
1438 
1439  // Convert UTF8 to wide string
1440  std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const char* str);
1441  std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const std::basic_string<char, std::char_traits<char>, std::allocator<char> >& str);
1442 #endif
1443 
1444  // Memory allocation function interface; returns pointer to allocated memory or NULL on failure
1445  typedef void* (*allocation_function)(size_t size);
1446 
1447  // Memory deallocation function interface
1448  typedef void (*deallocation_function)(void* ptr);
1449 
1450  // Override default memory management functions. All subsequent allocations/deallocations will be performed via supplied functions.
1452 
1453  // Get current memory management functions
1456 }
1457 
1458 #if !defined(PUGIXML_NO_STL) && (defined(_MSC_VER) || defined(__ICC))
1459 namespace std
1460 {
1461  // Workarounds for (non-standard) iterator category detection for older versions (MSVC7/IC8 and earlier)
1462  std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_node_iterator&);
1463  std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_attribute_iterator&);
1464  std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_named_node_iterator&);
1465 }
1466 #endif
1467 
1468 #if !defined(PUGIXML_NO_STL) && defined(__SUNPRO_CC)
1469 namespace std
1470 {
1471  // Workarounds for (non-standard) iterator category detection
1472  std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_node_iterator&);
1473  std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_attribute_iterator&);
1474  std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_named_node_iterator&);
1475 }
1476 #endif
1477 
1478 #endif
1479 
1480 // Make sure implementation is included in header-only mode
1481 // Use macro expansion in #include to work around QMake (QTBUG-11923)
1482 #if defined(PUGIXML_HEADER_ONLY) && !defined(PUGIXML_SOURCE)
1483 # define PUGIXML_SOURCE "pugixml.cpp"
1484 # include PUGIXML_SOURCE
1485 #endif
1486 
bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition: json.hpp:15536
Definition: pugixml.hpp:873
ptrdiff_t difference_type
Definition: pugixml.hpp:884
xml_attribute value_type
Definition: pugixml.hpp:885
xml_node _parent
Definition: pugixml.hpp:878
xml_attribute _wrap
Definition: pugixml.hpp:877
xml_attribute * pointer
Definition: pugixml.hpp:886
std::bidirectional_iterator_tag iterator_category
Definition: pugixml.hpp:890
xml_attribute & reference
Definition: pugixml.hpp:887
Definition: pugixml.hpp:365
xml_attribute_struct * _attr
Definition: pugixml.hpp:370
xml_attribute next_attribute() const
Definition: pugixml.cpp:5235
Definition: pugixml.hpp:1034
xml_document(const xml_document &)
char_t * _buffer
Definition: pugixml.hpp:1036
void _move(xml_document &rhs) PUGIXML_NOEXCEPT_IF_NOT_COMPACT
xml_document & operator=(const xml_document &)
Definition: pugixml.hpp:915
ptrdiff_t difference_type
Definition: pugixml.hpp:920
xml_node & reference
Definition: pugixml.hpp:923
const char_t * _name
Definition: pugixml.hpp:952
xml_node _wrap
Definition: pugixml.hpp:950
xml_node value_type
Definition: pugixml.hpp:921
std::bidirectional_iterator_tag iterator_category
Definition: pugixml.hpp:926
xml_node _parent
Definition: pugixml.hpp:951
xml_node * pointer
Definition: pugixml.hpp:922
Definition: pugixml.hpp:831
xml_node value_type
Definition: pugixml.hpp:843
xml_node _parent
Definition: pugixml.hpp:836
xml_node * pointer
Definition: pugixml.hpp:844
xml_node _wrap
Definition: pugixml.hpp:835
std::bidirectional_iterator_tag iterator_category
Definition: pugixml.hpp:848
xml_node & reference
Definition: pugixml.hpp:845
ptrdiff_t difference_type
Definition: pugixml.hpp:842
Definition: pugixml.hpp:474
xml_node parent() const
Definition: pugixml.cpp:5727
xml_attribute find_attribute(Predicate pred) const
Definition: pugixml.hpp:615
xml_node_struct * _root
Definition: pugixml.hpp:480
xml_node find_node(Predicate pred) const
Definition: pugixml.hpp:639
xml_attribute_iterator attribute_iterator
Definition: pugixml.hpp:708
xml_node first_child() const
Definition: pugixml.cpp:5778
xml_node find_child(Predicate pred) const
Definition: pugixml.hpp:627
xml_node_iterator iterator
Definition: pugixml.hpp:702
xml_node next_sibling() const
Definition: pugixml.cpp:5662
Definition: pugixml.hpp:305
It iterator
Definition: pugixml.hpp:308
It begin() const
Definition: pugixml.hpp:314
bool empty() const
Definition: pugixml.hpp:317
It _begin
Definition: pugixml.hpp:320
xml_object_range(It b, It e)
Definition: pugixml.hpp:310
It end() const
Definition: pugixml.hpp:315
It const_iterator
Definition: pugixml.hpp:307
It _end
Definition: pugixml.hpp:320
Definition: pugixml.hpp:739
xml_node_struct * _root
Definition: pugixml.hpp:742
Definition: pugixml.hpp:959
virtual bool for_each(xml_node &node)=0
int _depth
Definition: pugixml.hpp:963
Definition: pugixml.hpp:335
void * file
Definition: pugixml.hpp:343
Definition: pugixml.hpp:349
std::basic_ostream< wchar_t, std::char_traits< wchar_t > > * wide_stream
Definition: pugixml.hpp:359
std::basic_ostream< char, std::char_traits< char > > * narrow_stream
Definition: pugixml.hpp:358
Definition: pugixml.hpp:325
virtual void write(const void *data, size_t size)=0
Definition: pugixml.hpp:1302
xpath_parse_result _result
Definition: pugixml.hpp:1304
Definition: pugixml.hpp:1364
type_t _type
Definition: pugixml.hpp:1422
const xpath_node * const_iterator
Definition: pugixml.hpp:1375
type_t
Definition: pugixml.hpp:1368
@ type_unsorted
Definition: pugixml.hpp:1369
@ type_sorted
Definition: pugixml.hpp:1370
const xpath_node * iterator
Definition: pugixml.hpp:1378
xpath_node * _begin
Definition: pugixml.hpp:1426
xpath_node * _end
Definition: pugixml.hpp:1427
void _move(xpath_node_set &rhs) PUGIXML_NOEXCEPT
Definition: pugixml.hpp:1323
xml_node _node
Definition: pugixml.hpp:1325
xml_attribute _attribute
Definition: pugixml.hpp:1326
Definition: pugixml.hpp:1221
xpath_parse_result _result
Definition: pugixml.hpp:1224
xpath_query & operator=(const xpath_query &)
xpath_query(const xpath_query &)
void * _impl
Definition: pugixml.hpp:1223
Definition: pugixml.hpp:1178
Definition: pugixml.hpp:1143
xpath_variable * _next
Definition: pugixml.hpp:1148
xpath_variable & operator=(const xpath_variable &)
xpath_variable(const xpath_variable &)
xpath_value_type _type
Definition: pugixml.hpp:1147
bool operator==(const cp< d > &a, const cp< d > &b)
Contact equivalence is based solely on the index of objects in contact i and j.
Definition: ContactList.h:291
bool operator<(const cp< d > &a, const cp< d > &b)
The contact list is order in increasing order of index i, and for two identical i in increasing order...
Definition: ContactList.h:289
v1d operator*(v1d a, double b)
Definition: Tools.cpp:9
type
The type the bitset is encoded with.
Definition: bitset.hpp:44
OutIt print(OutIt out, const xml_node< Ch > &node, int flags=0)
Definition: rapidxml_print.hpp:394
void save(Archive &ar, SetT const &set)
Definition: set.hpp:42
void load(Archive &ar, SetT &set)
Definition: set.hpp:52
auto get(const nlohmann::detail::iteration_proxy_value< IteratorType > &i) -> decltype(i.key())
Definition: json.hpp:5657
Definition: pugixml.cpp:1109
const unsigned int format_no_empty_element_tags
Definition: pugixml.hpp:265
xml_encoding
Definition: pugixml.hpp:228
@ encoding_utf32
Definition: pugixml.hpp:236
@ encoding_utf16_le
Definition: pugixml.hpp:231
@ encoding_utf32_be
Definition: pugixml.hpp:235
@ encoding_utf16_be
Definition: pugixml.hpp:232
@ encoding_utf8
Definition: pugixml.hpp:230
@ encoding_latin1
Definition: pugixml.hpp:238
@ encoding_utf16
Definition: pugixml.hpp:233
@ encoding_utf32_le
Definition: pugixml.hpp:234
@ encoding_auto
Definition: pugixml.hpp:229
@ encoding_wchar
Definition: pugixml.hpp:237
std::basic_string< PUGIXML_CHAR, std::char_traits< PUGIXML_CHAR >, std::allocator< PUGIXML_CHAR > > string_t
Definition: pugixml.hpp:141
PUGI_IMPL_FN deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function()
Definition: pugixml.cpp:7514
PUGI_IMPL_FN allocation_function PUGIXML_FUNCTION get_memory_allocation_function()
Definition: pugixml.cpp:7509
const unsigned int format_no_declaration
Definition: pugixml.hpp:253
xml_node_type
Definition: pugixml.hpp:150
@ node_comment
Definition: pugixml.hpp:156
@ node_pcdata
Definition: pugixml.hpp:154
@ node_element
Definition: pugixml.hpp:153
@ node_doctype
Definition: pugixml.hpp:159
@ node_document
Definition: pugixml.hpp:152
@ node_declaration
Definition: pugixml.hpp:158
@ node_pi
Definition: pugixml.hpp:157
@ node_null
Definition: pugixml.hpp:151
@ node_cdata
Definition: pugixml.hpp:155
const unsigned int parse_trim_pcdata
Definition: pugixml.hpp:205
const unsigned int parse_wconv_attribute
Definition: pugixml.hpp:188
const unsigned int format_skip_control_chars
Definition: pugixml.hpp:268
const unsigned int format_raw
Definition: pugixml.hpp:250
const unsigned int format_default
Definition: pugixml.hpp:275
void(* deallocation_function)(void *ptr)
Definition: pugixml.hpp:1448
const int default_double_precision
Definition: pugixml.hpp:277
const unsigned int parse_cdata
Definition: pugixml.hpp:175
PUGI_IMPL_FN std::string PUGIXML_FUNCTION as_utf8(const wchar_t *str)
Definition: pugixml.cpp:7478
const unsigned int parse_fragment
Definition: pugixml.hpp:209
void *(* allocation_function)(size_t size)
Definition: pugixml.hpp:1445
const unsigned int parse_full
Definition: pugixml.hpp:224
const unsigned int parse_embed_pcdata
Definition: pugixml.hpp:214
const unsigned int parse_wnorm_attribute
Definition: pugixml.hpp:191
const unsigned int format_indent_attributes
Definition: pugixml.hpp:262
const unsigned int parse_pi
Definition: pugixml.hpp:169
xml_parse_status
Definition: pugixml.hpp:985
@ status_append_invalid_root
Definition: pugixml.hpp:1005
@ status_end_element_mismatch
Definition: pugixml.hpp:1003
@ status_bad_end_element
Definition: pugixml.hpp:1002
@ status_io_error
Definition: pugixml.hpp:989
@ status_bad_attribute
Definition: pugixml.hpp:1001
@ status_file_not_found
Definition: pugixml.hpp:988
@ status_internal_error
Definition: pugixml.hpp:991
@ status_bad_start_element
Definition: pugixml.hpp:1000
@ status_ok
Definition: pugixml.hpp:986
@ status_bad_comment
Definition: pugixml.hpp:996
@ status_bad_doctype
Definition: pugixml.hpp:998
@ status_out_of_memory
Definition: pugixml.hpp:990
@ status_unrecognized_tag
Definition: pugixml.hpp:993
@ status_bad_cdata
Definition: pugixml.hpp:997
@ status_bad_pcdata
Definition: pugixml.hpp:999
@ status_bad_pi
Definition: pugixml.hpp:995
@ status_no_document_element
Definition: pugixml.hpp:1007
const unsigned int format_save_file_text
Definition: pugixml.hpp:259
const unsigned int parse_escapes
Definition: pugixml.hpp:182
const unsigned int format_write_bom
Definition: pugixml.hpp:247
PUGI_IMPL_FN void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate)
Definition: pugixml.cpp:7503
const unsigned int format_attribute_single_quote
Definition: pugixml.hpp:271
const unsigned int format_indent
Definition: pugixml.hpp:244
const unsigned int parse_eol
Definition: pugixml.hpp:185
const unsigned int parse_default
Definition: pugixml.hpp:219
const unsigned int parse_declaration
Definition: pugixml.hpp:194
const unsigned int parse_comments
Definition: pugixml.hpp:172
PUGI_IMPL_FN std::basic_string< wchar_t > PUGIXML_FUNCTION as_wide(const char *str)
Definition: pugixml.cpp:7490
xpath_value_type
Definition: pugixml.hpp:1114
@ xpath_type_number
Definition: pugixml.hpp:1117
@ xpath_type_boolean
Definition: pugixml.hpp:1119
@ xpath_type_none
Definition: pugixml.hpp:1115
@ xpath_type_string
Definition: pugixml.hpp:1118
@ xpath_type_node_set
Definition: pugixml.hpp:1116
const unsigned int parse_ws_pcdata
Definition: pugixml.hpp:179
const unsigned int parse_minimal
Definition: pugixml.hpp:166
const unsigned int parse_ws_pcdata_single
Definition: pugixml.hpp:202
const unsigned int format_no_escapes
Definition: pugixml.hpp:256
PUGIXML_CHAR char_t
Definition: pugixml.hpp:137
const int default_float_precision
Definition: pugixml.hpp:278
const unsigned int parse_doctype
Definition: pugixml.hpp:197
Definition: json.hpp:5678
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1282
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1181
PUGI_IMPL_FN void sort(I begin, I end, const Pred &pred)
Definition: pugixml.cpp:7707
PUGI_IMPL_FN void reverse(I begin, I end)
Definition: pugixml.cpp:7615
void remove_attribute(xml_attribute_struct *attr, xml_node_struct *node)
Definition: pugixml.cpp:1409
void insert_attribute_before(xml_attribute_struct *attr, xml_attribute_struct *place, xml_node_struct *node)
Definition: pugixml.cpp:1395
void append_attribute(xml_attribute_struct *attr, xml_node_struct *node)
Definition: pugixml.cpp:1346
void prepend_attribute(xml_attribute_struct *attr, xml_node_struct *node)
Definition: pugixml.cpp:1365
void insert_attribute_after(xml_attribute_struct *attr, xml_attribute_struct *place, xml_node_struct *node)
Definition: pugixml.cpp:1381
#define PUGIXML_NULL
Definition: pugixml.hpp:121
#define PUGIXML_DEPRECATED
Definition: pugixml.hpp:48
#define PUGIXML_NOEXCEPT_IF_NOT_COMPACT
Definition: pugixml.hpp:100
#define PUGIXML_FUNCTION
Definition: pugixml.hpp:64
#define PUGIXML_NOEXCEPT
Definition: pugixml.hpp:92
#define PUGIXML_OVERRIDE
Definition: pugixml.hpp:110
#define PUGIXML_CLASS
Definition: pugixml.hpp:59
#define PUGIXML_TEXT(t)
Definition: pugixml.hpp:130
#define PUGIXML_CHAR
Definition: pugixml.hpp:131
Definition: pugixml.cpp:1111
Definition: pugixml.cpp:1127
Definition: pugixml.hpp:1012
xml_encoding encoding
Definition: pugixml.hpp:1020
ptrdiff_t offset
Definition: pugixml.hpp:1017
xml_parse_status status
Definition: pugixml.hpp:1014
Definition: pugixml.hpp:1124
const char * error
Definition: pugixml.hpp:1126
ptrdiff_t offset
Definition: pugixml.hpp:1129
#define const
Definition: zconf.h:233