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