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