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