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