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