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

UCC git Repository :: git.ucc.asn.au