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