Mercurial > embed
comparison pugixml/src/pugixml.hpp @ 47:8a8de065f049
pugixml: upgrade to 1.8, closes #614
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 20 Jan 2017 10:44:37 +0100 |
parents | 22ae219278af |
children | 1a32b6d17c8e |
comparison
equal
deleted
inserted
replaced
46:fa2587b194ee | 47:8a8de065f049 |
---|---|
1 /** | 1 /** |
2 * pugixml parser - version 1.7 | 2 * pugixml parser - version 1.8 |
3 * -------------------------------------------------------- | 3 * -------------------------------------------------------- |
4 * Copyright (C) 2006-2015, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) | 4 * Copyright (C) 2006-2016, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) |
5 * Report bugs and download new versions at http://pugixml.org/ | 5 * Report bugs and download new versions at http://pugixml.org/ |
6 * | 6 * |
7 * This library is distributed under the MIT License. See notice at the end | 7 * This library is distributed under the MIT License. See notice at the end |
8 * of this file. | 8 * of this file. |
9 * | 9 * |
11 * Copyright (C) 2003, by Kristen Wegner (kristen@tima.net) | 11 * Copyright (C) 2003, by Kristen Wegner (kristen@tima.net) |
12 */ | 12 */ |
13 | 13 |
14 #ifndef PUGIXML_VERSION | 14 #ifndef PUGIXML_VERSION |
15 // Define version macro; evaluates to major * 100 + minor so that it's safe to use in less-than comparisons | 15 // Define version macro; evaluates to major * 100 + minor so that it's safe to use in less-than comparisons |
16 # define PUGIXML_VERSION 170 | 16 # define PUGIXML_VERSION 180 |
17 #endif | 17 #endif |
18 | 18 |
19 // Include user configuration file (this can define various configuration macros) | 19 // Include user configuration file (this can define various configuration macros) |
20 #include "pugiconfig.hpp" | 20 #include "pugiconfig.hpp" |
21 | 21 |
70 # elif defined(_MSC_VER) && _MSC_VER >= 1400 | 70 # elif defined(_MSC_VER) && _MSC_VER >= 1400 |
71 # define PUGIXML_HAS_LONG_LONG | 71 # define PUGIXML_HAS_LONG_LONG |
72 # endif | 72 # endif |
73 #endif | 73 #endif |
74 | 74 |
75 // If the platform is known to have move semantics support, compile move ctor/operator implementation | |
76 #ifndef PUGIXML_HAS_MOVE | |
77 # if __cplusplus >= 201103 | |
78 # define PUGIXML_HAS_MOVE | |
79 # elif defined(_MSC_VER) && _MSC_VER >= 1600 | |
80 # define PUGIXML_HAS_MOVE | |
81 # endif | |
82 #endif | |
83 | |
84 // If C++ is 2011 or higher, add 'override' qualifiers | |
85 #ifndef PUGIXML_OVERRIDE | |
86 # if __cplusplus >= 201103 | |
87 # define PUGIXML_OVERRIDE override | |
88 # else | |
89 # define PUGIXML_OVERRIDE | |
90 # endif | |
91 #endif | |
92 | |
75 // Character interface macros | 93 // Character interface macros |
76 #ifdef PUGIXML_WCHAR_MODE | 94 #ifdef PUGIXML_WCHAR_MODE |
77 # define PUGIXML_TEXT(t) L ## t | 95 # define PUGIXML_TEXT(t) L ## t |
78 # define PUGIXML_CHAR wchar_t | 96 # define PUGIXML_CHAR wchar_t |
79 #else | 97 #else |
131 // This flag determines if character and entity references are expanded during parsing. This flag is on by default. | 149 // This flag determines if character and entity references are expanded during parsing. This flag is on by default. |
132 const unsigned int parse_escapes = 0x0010; | 150 const unsigned int parse_escapes = 0x0010; |
133 | 151 |
134 // This flag determines if EOL characters are normalized (converted to #xA) during parsing. This flag is on by default. | 152 // This flag determines if EOL characters are normalized (converted to #xA) during parsing. This flag is on by default. |
135 const unsigned int parse_eol = 0x0020; | 153 const unsigned int parse_eol = 0x0020; |
136 | 154 |
137 // This flag determines if attribute values are normalized using CDATA normalization rules during parsing. This flag is on by default. | 155 // This flag determines if attribute values are normalized using CDATA normalization rules during parsing. This flag is on by default. |
138 const unsigned int parse_wconv_attribute = 0x0040; | 156 const unsigned int parse_wconv_attribute = 0x0040; |
139 | 157 |
140 // This flag determines if attribute values are normalized using NMTOKENS normalization rules during parsing. This flag is off by default. | 158 // This flag determines if attribute values are normalized using NMTOKENS normalization rules during parsing. This flag is off by default. |
141 const unsigned int parse_wnorm_attribute = 0x0080; | 159 const unsigned int parse_wnorm_attribute = 0x0080; |
142 | 160 |
143 // This flag determines if document declaration (node_declaration) is added to the DOM tree. This flag is off by default. | 161 // This flag determines if document declaration (node_declaration) is added to the DOM tree. This flag is off by default. |
144 const unsigned int parse_declaration = 0x0100; | 162 const unsigned int parse_declaration = 0x0100; |
145 | 163 |
146 // This flag determines if document type declaration (node_doctype) is added to the DOM tree. This flag is off by default. | 164 // This flag determines if document type declaration (node_doctype) is added to the DOM tree. This flag is off by default. |
147 const unsigned int parse_doctype = 0x0200; | 165 const unsigned int parse_doctype = 0x0200; |
155 const unsigned int parse_trim_pcdata = 0x0800; | 173 const unsigned int parse_trim_pcdata = 0x0800; |
156 | 174 |
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 | 175 // This flag determines if plain character data that does not have a parent node is added to the DOM tree, and if an empty document |
158 // is a valid document. This flag is off by default. | 176 // is a valid document. This flag is off by default. |
159 const unsigned int parse_fragment = 0x1000; | 177 const unsigned int parse_fragment = 0x1000; |
178 | |
179 // This flag determines if plain character data is be stored in the parent element's value. This significantly changes the structure of | |
180 // the document; this flag is only recommended for parsing documents with many PCDATA nodes in memory-constrained environments. | |
181 // This flag is off by default. | |
182 const unsigned int parse_embed_pcdata = 0x2000; | |
160 | 183 |
161 // The default parsing mode. | 184 // The default parsing mode. |
162 // Elements, PCDATA and CDATA sections are added to the DOM tree, character/reference entities are expanded, | 185 // Elements, PCDATA and CDATA sections are added to the DOM tree, character/reference entities are expanded, |
163 // End-of-Line characters are normalized, attribute values are normalized using CDATA normalization rules. | 186 // End-of-Line characters are normalized, attribute values are normalized using CDATA normalization rules. |
164 const unsigned int parse_default = parse_cdata | parse_escapes | parse_wconv_attribute | parse_eol; | 187 const unsigned int parse_default = parse_cdata | parse_escapes | parse_wconv_attribute | parse_eol; |
182 encoding_wchar, // The same encoding wchar_t has (either UTF16 or UTF32) | 205 encoding_wchar, // The same encoding wchar_t has (either UTF16 or UTF32) |
183 encoding_latin1 | 206 encoding_latin1 |
184 }; | 207 }; |
185 | 208 |
186 // Formatting flags | 209 // Formatting flags |
187 | 210 |
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. | 211 // 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. |
189 const unsigned int format_indent = 0x01; | 212 const unsigned int format_indent = 0x01; |
190 | 213 |
191 // Write encoding-specific BOM to the output stream. This flag is off by default. | 214 // Write encoding-specific BOM to the output stream. This flag is off by default. |
192 const unsigned int format_write_bom = 0x02; | 215 const unsigned int format_write_bom = 0x02; |
193 | 216 |
194 // Use raw output mode (no indentation and no line breaks are written). This flag is off by default. | 217 // Use raw output mode (no indentation and no line breaks are written). This flag is off by default. |
195 const unsigned int format_raw = 0x04; | 218 const unsigned int format_raw = 0x04; |
196 | 219 |
197 // Omit default XML declaration even if there is no declaration in the document. This flag is off by default. | 220 // Omit default XML declaration even if there is no declaration in the document. This flag is off by default. |
198 const unsigned int format_no_declaration = 0x08; | 221 const unsigned int format_no_declaration = 0x08; |
199 | 222 |
200 // Don't escape attribute values and PCDATA contents. This flag is off by default. | 223 // Don't escape attribute values and PCDATA contents. This flag is off by default. |
201 const unsigned int format_no_escapes = 0x10; | 224 const unsigned int format_no_escapes = 0x10; |
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. | 226 // 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. |
204 const unsigned int format_save_file_text = 0x20; | 227 const unsigned int format_save_file_text = 0x20; |
205 | 228 |
206 // Write every attribute on a new line with appropriate indentation. This flag is off by default. | 229 // Write every attribute on a new line with appropriate indentation. This flag is off by default. |
207 const unsigned int format_indent_attributes = 0x40; | 230 const unsigned int format_indent_attributes = 0x40; |
231 | |
232 // Don't output empty element tags, instead writing an explicit start and end tag even if there are no children. This flag is off by default. | |
233 const unsigned int format_no_empty_element_tags = 0x80; | |
208 | 234 |
209 // The default set of formatting flags. | 235 // The default set of formatting flags. |
210 // Nodes are indented depending on their depth in DOM tree, a default declaration is output if document has none. | 236 // Nodes are indented depending on their depth in DOM tree, a default declaration is output if document has none. |
211 const unsigned int format_default = format_indent; | 237 const unsigned int format_default = format_indent; |
212 | 238 |
223 struct xml_parse_result; | 249 struct xml_parse_result; |
224 | 250 |
225 class xml_node; | 251 class xml_node; |
226 | 252 |
227 class xml_text; | 253 class xml_text; |
228 | 254 |
229 #ifndef PUGIXML_NO_XPATH | 255 #ifndef PUGIXML_NO_XPATH |
230 class xpath_node; | 256 class xpath_node; |
231 class xpath_node_set; | 257 class xpath_node_set; |
232 class xpath_query; | 258 class xpath_query; |
233 class xpath_variable_set; | 259 class xpath_variable_set; |
266 { | 292 { |
267 public: | 293 public: |
268 // Construct writer from a FILE* object; void* is used to avoid header dependencies on stdio | 294 // Construct writer from a FILE* object; void* is used to avoid header dependencies on stdio |
269 xml_writer_file(void* file); | 295 xml_writer_file(void* file); |
270 | 296 |
271 virtual void write(const void* data, size_t size); | 297 virtual void write(const void* data, size_t size) PUGIXML_OVERRIDE; |
272 | 298 |
273 private: | 299 private: |
274 void* file; | 300 void* file; |
275 }; | 301 }; |
276 | 302 |
281 public: | 307 public: |
282 // Construct writer from an output stream object | 308 // Construct writer from an output stream object |
283 xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream); | 309 xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream); |
284 xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream); | 310 xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream); |
285 | 311 |
286 virtual void write(const void* data, size_t size); | 312 virtual void write(const void* data, size_t size) PUGIXML_OVERRIDE; |
287 | 313 |
288 private: | 314 private: |
289 std::basic_ostream<char, std::char_traits<char> >* narrow_stream; | 315 std::basic_ostream<char, std::char_traits<char> >* narrow_stream; |
290 std::basic_ostream<wchar_t, std::char_traits<wchar_t> >* wide_stream; | 316 std::basic_ostream<wchar_t, std::char_traits<wchar_t> >* wide_stream; |
291 }; | 317 }; |
297 friend class xml_attribute_iterator; | 323 friend class xml_attribute_iterator; |
298 friend class xml_node; | 324 friend class xml_node; |
299 | 325 |
300 private: | 326 private: |
301 xml_attribute_struct* _attr; | 327 xml_attribute_struct* _attr; |
302 | 328 |
303 typedef void (*unspecified_bool_type)(xml_attribute***); | 329 typedef void (*unspecified_bool_type)(xml_attribute***); |
304 | 330 |
305 public: | 331 public: |
306 // Default constructor. Constructs an empty attribute. | 332 // Default constructor. Constructs an empty attribute. |
307 xml_attribute(); | 333 xml_attribute(); |
308 | 334 |
309 // Constructs attribute from internal pointer | 335 // Constructs attribute from internal pointer |
310 explicit xml_attribute(xml_attribute_struct* attr); | 336 explicit xml_attribute(xml_attribute_struct* attr); |
311 | 337 |
312 // Safe bool conversion operator | 338 // Safe bool conversion operator |
313 operator unspecified_bool_type() const; | 339 operator unspecified_bool_type() const; |
352 bool set_value(const char_t* rhs); | 378 bool set_value(const char_t* rhs); |
353 | 379 |
354 // Set attribute value with type conversion (numbers are converted to strings, boolean is converted to "true"/"false") | 380 // Set attribute value with type conversion (numbers are converted to strings, boolean is converted to "true"/"false") |
355 bool set_value(int rhs); | 381 bool set_value(int rhs); |
356 bool set_value(unsigned int rhs); | 382 bool set_value(unsigned int rhs); |
383 bool set_value(long rhs); | |
384 bool set_value(unsigned long rhs); | |
357 bool set_value(double rhs); | 385 bool set_value(double rhs); |
358 bool set_value(float rhs); | 386 bool set_value(float rhs); |
359 bool set_value(bool rhs); | 387 bool set_value(bool rhs); |
360 | 388 |
361 #ifdef PUGIXML_HAS_LONG_LONG | 389 #ifdef PUGIXML_HAS_LONG_LONG |
365 | 393 |
366 // Set attribute value (equivalent to set_value without error checking) | 394 // Set attribute value (equivalent to set_value without error checking) |
367 xml_attribute& operator=(const char_t* rhs); | 395 xml_attribute& operator=(const char_t* rhs); |
368 xml_attribute& operator=(int rhs); | 396 xml_attribute& operator=(int rhs); |
369 xml_attribute& operator=(unsigned int rhs); | 397 xml_attribute& operator=(unsigned int rhs); |
398 xml_attribute& operator=(long rhs); | |
399 xml_attribute& operator=(unsigned long rhs); | |
370 xml_attribute& operator=(double rhs); | 400 xml_attribute& operator=(double rhs); |
371 xml_attribute& operator=(float rhs); | 401 xml_attribute& operator=(float rhs); |
372 xml_attribute& operator=(bool rhs); | 402 xml_attribute& operator=(bool rhs); |
373 | 403 |
374 #ifdef PUGIXML_HAS_LONG_LONG | 404 #ifdef PUGIXML_HAS_LONG_LONG |
415 // Safe bool conversion operator | 445 // Safe bool conversion operator |
416 operator unspecified_bool_type() const; | 446 operator unspecified_bool_type() const; |
417 | 447 |
418 // Borland C++ workaround | 448 // Borland C++ workaround |
419 bool operator!() const; | 449 bool operator!() const; |
420 | 450 |
421 // Comparison operators (compares wrapped node pointers) | 451 // Comparison operators (compares wrapped node pointers) |
422 bool operator==(const xml_node& r) const; | 452 bool operator==(const xml_node& r) const; |
423 bool operator!=(const xml_node& r) const; | 453 bool operator!=(const xml_node& r) const; |
424 bool operator<(const xml_node& r) const; | 454 bool operator<(const xml_node& r) const; |
425 bool operator>(const xml_node& r) const; | 455 bool operator>(const xml_node& r) const; |
436 const char_t* name() const; | 466 const char_t* name() const; |
437 | 467 |
438 // Get node value, or "" if node is empty or it has no value | 468 // Get node value, or "" if node is empty or it has no value |
439 // Note: For <node>text</node> node.value() does not return "text"! Use child_value() or text() methods to access text inside nodes. | 469 // Note: For <node>text</node> node.value() does not return "text"! Use child_value() or text() methods to access text inside nodes. |
440 const char_t* value() const; | 470 const char_t* value() const; |
441 | 471 |
442 // Get attribute list | 472 // Get attribute list |
443 xml_attribute first_attribute() const; | 473 xml_attribute first_attribute() const; |
444 xml_attribute last_attribute() const; | 474 xml_attribute last_attribute() const; |
445 | 475 |
446 // Get children list | 476 // Get children list |
448 xml_node last_child() const; | 478 xml_node last_child() const; |
449 | 479 |
450 // Get next/previous sibling in the children list of the parent node | 480 // Get next/previous sibling in the children list of the parent node |
451 xml_node next_sibling() const; | 481 xml_node next_sibling() const; |
452 xml_node previous_sibling() const; | 482 xml_node previous_sibling() const; |
453 | 483 |
454 // Get parent node | 484 // Get parent node |
455 xml_node parent() const; | 485 xml_node parent() const; |
456 | 486 |
457 // Get root of DOM tree this node belongs to | 487 // Get root of DOM tree this node belongs to |
458 xml_node root() const; | 488 xml_node root() const; |
476 const char_t* child_value(const char_t* name) const; | 506 const char_t* child_value(const char_t* name) const; |
477 | 507 |
478 // Set node name/value (returns false if node is empty, there is not enough memory, or node can not have name/value) | 508 // Set node name/value (returns false if node is empty, there is not enough memory, or node can not have name/value) |
479 bool set_name(const char_t* rhs); | 509 bool set_name(const char_t* rhs); |
480 bool set_value(const char_t* rhs); | 510 bool set_value(const char_t* rhs); |
481 | 511 |
482 // Add attribute with specified name. Returns added attribute, or empty attribute on errors. | 512 // Add attribute with specified name. Returns added attribute, or empty attribute on errors. |
483 xml_attribute append_attribute(const char_t* name); | 513 xml_attribute append_attribute(const char_t* name); |
484 xml_attribute prepend_attribute(const char_t* name); | 514 xml_attribute prepend_attribute(const char_t* name); |
485 xml_attribute insert_attribute_after(const char_t* name, const xml_attribute& attr); | 515 xml_attribute insert_attribute_after(const char_t* name, const xml_attribute& attr); |
486 xml_attribute insert_attribute_before(const char_t* name, const xml_attribute& attr); | 516 xml_attribute insert_attribute_before(const char_t* name, const xml_attribute& attr); |
530 | 560 |
531 // Find attribute using predicate. Returns first attribute for which predicate returned true. | 561 // Find attribute using predicate. Returns first attribute for which predicate returned true. |
532 template <typename Predicate> xml_attribute find_attribute(Predicate pred) const | 562 template <typename Predicate> xml_attribute find_attribute(Predicate pred) const |
533 { | 563 { |
534 if (!_root) return xml_attribute(); | 564 if (!_root) return xml_attribute(); |
535 | 565 |
536 for (xml_attribute attrib = first_attribute(); attrib; attrib = attrib.next_attribute()) | 566 for (xml_attribute attrib = first_attribute(); attrib; attrib = attrib.next_attribute()) |
537 if (pred(attrib)) | 567 if (pred(attrib)) |
538 return attrib; | 568 return attrib; |
539 | 569 |
540 return xml_attribute(); | 570 return xml_attribute(); |
541 } | 571 } |
542 | 572 |
543 // Find child node using predicate. Returns first child for which predicate returned true. | 573 // Find child node using predicate. Returns first child for which predicate returned true. |
544 template <typename Predicate> xml_node find_child(Predicate pred) const | 574 template <typename Predicate> xml_node find_child(Predicate pred) const |
545 { | 575 { |
546 if (!_root) return xml_node(); | 576 if (!_root) return xml_node(); |
547 | 577 |
548 for (xml_node node = first_child(); node; node = node.next_sibling()) | 578 for (xml_node node = first_child(); node; node = node.next_sibling()) |
549 if (pred(node)) | 579 if (pred(node)) |
550 return node; | 580 return node; |
551 | 581 |
552 return xml_node(); | 582 return xml_node(); |
553 } | 583 } |
554 | 584 |
555 // Find node from subtree using predicate. Returns first node from subtree (depth-first), for which predicate returned true. | 585 // Find node from subtree using predicate. Returns first node from subtree (depth-first), for which predicate returned true. |
556 template <typename Predicate> xml_node find_node(Predicate pred) const | 586 template <typename Predicate> xml_node find_node(Predicate pred) const |
557 { | 587 { |
558 if (!_root) return xml_node(); | 588 if (!_root) return xml_node(); |
559 | 589 |
560 xml_node cur = first_child(); | 590 xml_node cur = first_child(); |
561 | 591 |
562 while (cur._root && cur._root != _root) | 592 while (cur._root && cur._root != _root) |
563 { | 593 { |
564 if (pred(cur)) return cur; | 594 if (pred(cur)) return cur; |
565 | 595 |
566 if (cur.first_child()) cur = cur.first_child(); | 596 if (cur.first_child()) cur = cur.first_child(); |
588 // Search for a node by path consisting of node names and . or .. elements. | 618 // Search for a node by path consisting of node names and . or .. elements. |
589 xml_node first_element_by_path(const char_t* path, char_t delimiter = '/') const; | 619 xml_node first_element_by_path(const char_t* path, char_t delimiter = '/') const; |
590 | 620 |
591 // Recursively traverse subtree with xml_tree_walker | 621 // Recursively traverse subtree with xml_tree_walker |
592 bool traverse(xml_tree_walker& walker); | 622 bool traverse(xml_tree_walker& walker); |
593 | 623 |
594 #ifndef PUGIXML_NO_XPATH | 624 #ifndef PUGIXML_NO_XPATH |
595 // Select single node by evaluating XPath query. Returns first node from the resulting node set. | 625 // Select single node by evaluating XPath query. Returns first node from the resulting node set. |
596 xpath_node select_node(const char_t* query, xpath_variable_set* variables = 0) const; | 626 xpath_node select_node(const char_t* query, xpath_variable_set* variables = 0) const; |
597 xpath_node select_node(const xpath_query& query) const; | 627 xpath_node select_node(const xpath_query& query) const; |
598 | 628 |
603 // (deprecated: use select_node instead) Select single node by evaluating XPath query. | 633 // (deprecated: use select_node instead) Select single node by evaluating XPath query. |
604 xpath_node select_single_node(const char_t* query, xpath_variable_set* variables = 0) const; | 634 xpath_node select_single_node(const char_t* query, xpath_variable_set* variables = 0) const; |
605 xpath_node select_single_node(const xpath_query& query) const; | 635 xpath_node select_single_node(const xpath_query& query) const; |
606 | 636 |
607 #endif | 637 #endif |
608 | 638 |
609 // Print subtree using a writer object | 639 // Print subtree using a writer object |
610 void print(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const; | 640 void print(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const; |
611 | 641 |
612 #ifndef PUGIXML_NO_STL | 642 #ifndef PUGIXML_NO_STL |
613 // Print subtree to stream | 643 // Print subtree to stream |
699 bool set(const char_t* rhs); | 729 bool set(const char_t* rhs); |
700 | 730 |
701 // Set text with type conversion (numbers are converted to strings, boolean is converted to "true"/"false") | 731 // Set text with type conversion (numbers are converted to strings, boolean is converted to "true"/"false") |
702 bool set(int rhs); | 732 bool set(int rhs); |
703 bool set(unsigned int rhs); | 733 bool set(unsigned int rhs); |
734 bool set(long rhs); | |
735 bool set(unsigned long rhs); | |
704 bool set(double rhs); | 736 bool set(double rhs); |
705 bool set(float rhs); | 737 bool set(float rhs); |
706 bool set(bool rhs); | 738 bool set(bool rhs); |
707 | 739 |
708 #ifdef PUGIXML_HAS_LONG_LONG | 740 #ifdef PUGIXML_HAS_LONG_LONG |
712 | 744 |
713 // Set text (equivalent to set without error checking) | 745 // Set text (equivalent to set without error checking) |
714 xml_text& operator=(const char_t* rhs); | 746 xml_text& operator=(const char_t* rhs); |
715 xml_text& operator=(int rhs); | 747 xml_text& operator=(int rhs); |
716 xml_text& operator=(unsigned int rhs); | 748 xml_text& operator=(unsigned int rhs); |
749 xml_text& operator=(long rhs); | |
750 xml_text& operator=(unsigned long rhs); | |
717 xml_text& operator=(double rhs); | 751 xml_text& operator=(double rhs); |
718 xml_text& operator=(float rhs); | 752 xml_text& operator=(float rhs); |
719 xml_text& operator=(bool rhs); | 753 xml_text& operator=(bool rhs); |
720 | 754 |
721 #ifdef PUGIXML_HAS_LONG_LONG | 755 #ifdef PUGIXML_HAS_LONG_LONG |
865 { | 899 { |
866 friend class xml_node; | 900 friend class xml_node; |
867 | 901 |
868 private: | 902 private: |
869 int _depth; | 903 int _depth; |
870 | 904 |
871 protected: | 905 protected: |
872 // Get current traversal depth | 906 // Get current traversal depth |
873 int depth() const; | 907 int depth() const; |
874 | 908 |
875 public: | 909 public: |
876 xml_tree_walker(); | 910 xml_tree_walker(); |
877 virtual ~xml_tree_walker(); | 911 virtual ~xml_tree_walker(); |
878 | 912 |
879 // Callback that is called when traversal begins | 913 // Callback that is called when traversal begins |
940 { | 974 { |
941 private: | 975 private: |
942 char_t* _buffer; | 976 char_t* _buffer; |
943 | 977 |
944 char _memory[192]; | 978 char _memory[192]; |
945 | 979 |
946 // Non-copyable semantics | 980 // Non-copyable semantics |
947 xml_document(const xml_document&); | 981 xml_document(const xml_document&); |
948 xml_document& operator=(const xml_document&); | 982 xml_document& operator=(const xml_document&); |
949 | 983 |
950 void create(); | 984 void _create(); |
951 void destroy(); | 985 void _destroy(); |
952 | 986 |
953 public: | 987 public: |
954 // Default constructor, makes empty document | 988 // Default constructor, makes empty document |
955 xml_document(); | 989 xml_document(); |
956 | 990 |
1049 xpath_variable(xpath_value_type type); | 1083 xpath_variable(xpath_value_type type); |
1050 | 1084 |
1051 // Non-copyable semantics | 1085 // Non-copyable semantics |
1052 xpath_variable(const xpath_variable&); | 1086 xpath_variable(const xpath_variable&); |
1053 xpath_variable& operator=(const xpath_variable&); | 1087 xpath_variable& operator=(const xpath_variable&); |
1054 | 1088 |
1055 public: | 1089 public: |
1056 // Get variable name | 1090 // Get variable name |
1057 const char_t* name() const; | 1091 const char_t* name() const; |
1058 | 1092 |
1059 // Get variable type | 1093 // Get variable type |
1093 | 1127 |
1094 // Copy constructor/assignment operator | 1128 // Copy constructor/assignment operator |
1095 xpath_variable_set(const xpath_variable_set& rhs); | 1129 xpath_variable_set(const xpath_variable_set& rhs); |
1096 xpath_variable_set& operator=(const xpath_variable_set& rhs); | 1130 xpath_variable_set& operator=(const xpath_variable_set& rhs); |
1097 | 1131 |
1098 #if __cplusplus >= 201103 | 1132 #ifdef PUGIXML_HAS_MOVE |
1099 // Move semantics support | 1133 // Move semantics support |
1100 xpath_variable_set(xpath_variable_set&& rhs); | 1134 xpath_variable_set(xpath_variable_set&& rhs); |
1101 xpath_variable_set& operator=(xpath_variable_set&& rhs); | 1135 xpath_variable_set& operator=(xpath_variable_set&& rhs); |
1102 #endif | 1136 #endif |
1103 | 1137 |
1137 xpath_query(); | 1171 xpath_query(); |
1138 | 1172 |
1139 // Destructor | 1173 // Destructor |
1140 ~xpath_query(); | 1174 ~xpath_query(); |
1141 | 1175 |
1142 #if __cplusplus >= 201103 | 1176 #ifdef PUGIXML_HAS_MOVE |
1143 // Move semantics support | 1177 // Move semantics support |
1144 xpath_query(xpath_query&& rhs); | 1178 xpath_query(xpath_query&& rhs); |
1145 xpath_query& operator=(xpath_query&& rhs); | 1179 xpath_query& operator=(xpath_query&& rhs); |
1146 #endif | 1180 #endif |
1147 | 1181 |
1148 // Get query expression return type | 1182 // Get query expression return type |
1149 xpath_value_type return_type() const; | 1183 xpath_value_type return_type() const; |
1150 | 1184 |
1151 // Evaluate expression as boolean value in the specified context; performs type conversion if necessary. | 1185 // Evaluate expression as boolean value in the specified context; performs type conversion if necessary. |
1152 // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors. | 1186 // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors. |
1153 bool evaluate_boolean(const xpath_node& n) const; | 1187 bool evaluate_boolean(const xpath_node& n) const; |
1154 | 1188 |
1155 // Evaluate expression as double value in the specified context; performs type conversion if necessary. | 1189 // Evaluate expression as double value in the specified context; performs type conversion if necessary. |
1156 // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors. | 1190 // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors. |
1157 double evaluate_number(const xpath_node& n) const; | 1191 double evaluate_number(const xpath_node& n) const; |
1158 | 1192 |
1159 #ifndef PUGIXML_NO_STL | 1193 #ifndef PUGIXML_NO_STL |
1160 // Evaluate expression as string value in the specified context; performs type conversion if necessary. | 1194 // Evaluate expression as string 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. | 1195 // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors. |
1162 string_t evaluate_string(const xpath_node& n) const; | 1196 string_t evaluate_string(const xpath_node& n) const; |
1163 #endif | 1197 #endif |
1164 | 1198 |
1165 // Evaluate expression as string value in the specified context; performs type conversion if necessary. | 1199 // Evaluate expression as string value in the specified context; performs type conversion if necessary. |
1166 // At most capacity characters are written to the destination buffer, full result size is returned (includes terminating zero). | 1200 // At most capacity characters are written to the destination buffer, full result size is returned (includes terminating zero). |
1167 // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors. | 1201 // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors. |
1168 // If PUGIXML_NO_EXCEPTIONS is defined, returns empty set instead. | 1202 // If PUGIXML_NO_EXCEPTIONS is defined, returns empty set instead. |
1169 size_t evaluate_string(char_t* buffer, size_t capacity, const xpath_node& n) const; | 1203 size_t evaluate_string(char_t* buffer, size_t capacity, const xpath_node& n) const; |
1186 operator unspecified_bool_type() const; | 1220 operator unspecified_bool_type() const; |
1187 | 1221 |
1188 // Borland C++ workaround | 1222 // Borland C++ workaround |
1189 bool operator!() const; | 1223 bool operator!() const; |
1190 }; | 1224 }; |
1191 | 1225 |
1192 #ifndef PUGIXML_NO_EXCEPTIONS | 1226 #ifndef PUGIXML_NO_EXCEPTIONS |
1193 // XPath exception class | 1227 // XPath exception class |
1194 class PUGIXML_CLASS xpath_exception: public std::exception | 1228 class PUGIXML_CLASS xpath_exception: public std::exception |
1195 { | 1229 { |
1196 private: | 1230 private: |
1199 public: | 1233 public: |
1200 // Construct exception from parse result | 1234 // Construct exception from parse result |
1201 explicit xpath_exception(const xpath_parse_result& result); | 1235 explicit xpath_exception(const xpath_parse_result& result); |
1202 | 1236 |
1203 // Get error message | 1237 // Get error message |
1204 virtual const char* what() const throw(); | 1238 virtual const char* what() const throw() PUGIXML_OVERRIDE; |
1205 | 1239 |
1206 // Get parse result | 1240 // Get parse result |
1207 const xpath_parse_result& result() const; | 1241 const xpath_parse_result& result() const; |
1208 }; | 1242 }; |
1209 #endif | 1243 #endif |
1210 | 1244 |
1211 // XPath node class (either xml_node or xml_attribute) | 1245 // XPath node class (either xml_node or xml_attribute) |
1212 class PUGIXML_CLASS xpath_node | 1246 class PUGIXML_CLASS xpath_node |
1213 { | 1247 { |
1214 private: | 1248 private: |
1215 xml_node _node; | 1249 xml_node _node; |
1216 xml_attribute _attribute; | 1250 xml_attribute _attribute; |
1217 | 1251 |
1218 typedef void (*unspecified_bool_type)(xpath_node***); | 1252 typedef void (*unspecified_bool_type)(xpath_node***); |
1219 | 1253 |
1220 public: | 1254 public: |
1221 // Default constructor; constructs empty XPath node | 1255 // Default constructor; constructs empty XPath node |
1222 xpath_node(); | 1256 xpath_node(); |
1223 | 1257 |
1224 // Construct XPath node from XML node/attribute | 1258 // Construct XPath node from XML node/attribute |
1225 xpath_node(const xml_node& node); | 1259 xpath_node(const xml_node& node); |
1226 xpath_node(const xml_attribute& attribute, const xml_node& parent); | 1260 xpath_node(const xml_attribute& attribute, const xml_node& parent); |
1227 | 1261 |
1228 // Get node/attribute, if any | 1262 // Get node/attribute, if any |
1229 xml_node node() const; | 1263 xml_node node() const; |
1230 xml_attribute attribute() const; | 1264 xml_attribute attribute() const; |
1231 | 1265 |
1232 // Get parent of contained node/attribute | 1266 // Get parent of contained node/attribute |
1233 xml_node parent() const; | 1267 xml_node parent() const; |
1234 | 1268 |
1235 // Safe bool conversion operator | 1269 // Safe bool conversion operator |
1236 operator unspecified_bool_type() const; | 1270 operator unspecified_bool_type() const; |
1237 | 1271 |
1238 // Borland C++ workaround | 1272 // Borland C++ workaround |
1239 bool operator!() const; | 1273 bool operator!() const; |
1240 | 1274 |
1241 // Comparison operators | 1275 // Comparison operators |
1242 bool operator==(const xpath_node& n) const; | 1276 bool operator==(const xpath_node& n) const; |
1258 { | 1292 { |
1259 type_unsorted, // Not ordered | 1293 type_unsorted, // Not ordered |
1260 type_sorted, // Sorted by document order (ascending) | 1294 type_sorted, // Sorted by document order (ascending) |
1261 type_sorted_reverse // Sorted by document order (descending) | 1295 type_sorted_reverse // Sorted by document order (descending) |
1262 }; | 1296 }; |
1263 | 1297 |
1264 // Constant iterator type | 1298 // Constant iterator type |
1265 typedef const xpath_node* const_iterator; | 1299 typedef const xpath_node* const_iterator; |
1266 | 1300 |
1267 // We define non-constant iterator to be the same as constant iterator so that various generic algorithms (i.e. boost foreach) work | 1301 // We define non-constant iterator to be the same as constant iterator so that various generic algorithms (i.e. boost foreach) work |
1268 typedef const xpath_node* iterator; | 1302 typedef const xpath_node* iterator; |
1269 | 1303 |
1270 // Default constructor. Constructs empty set. | 1304 // Default constructor. Constructs empty set. |
1271 xpath_node_set(); | 1305 xpath_node_set(); |
1272 | 1306 |
1273 // Constructs a set from iterator range; data is not checked for duplicates and is not sorted according to provided type, so be careful | 1307 // Constructs a set from iterator range; data is not checked for duplicates and is not sorted according to provided type, so be careful |
1274 xpath_node_set(const_iterator begin, const_iterator end, type_t type = type_unsorted); | 1308 xpath_node_set(const_iterator begin, const_iterator end, type_t type = type_unsorted); |
1275 | 1309 |
1276 // Destructor | 1310 // Destructor |
1277 ~xpath_node_set(); | 1311 ~xpath_node_set(); |
1278 | 1312 |
1279 // Copy constructor/assignment operator | 1313 // Copy constructor/assignment operator |
1280 xpath_node_set(const xpath_node_set& ns); | 1314 xpath_node_set(const xpath_node_set& ns); |
1281 xpath_node_set& operator=(const xpath_node_set& ns); | 1315 xpath_node_set& operator=(const xpath_node_set& ns); |
1282 | 1316 |
1283 #if __cplusplus >= 201103 | 1317 #ifdef PUGIXML_HAS_MOVE |
1284 // Move semantics support | 1318 // Move semantics support |
1285 xpath_node_set(xpath_node_set&& rhs); | 1319 xpath_node_set(xpath_node_set&& rhs); |
1286 xpath_node_set& operator=(xpath_node_set&& rhs); | 1320 xpath_node_set& operator=(xpath_node_set&& rhs); |
1287 #endif | 1321 #endif |
1288 | 1322 |
1289 // Get collection type | 1323 // Get collection type |
1290 type_t type() const; | 1324 type_t type() const; |
1291 | 1325 |
1292 // Get collection size | 1326 // Get collection size |
1293 size_t size() const; | 1327 size_t size() const; |
1294 | 1328 |
1295 // Indexing operator | 1329 // Indexing operator |
1296 const xpath_node& operator[](size_t index) const; | 1330 const xpath_node& operator[](size_t index) const; |
1297 | 1331 |
1298 // Collection iterators | 1332 // Collection iterators |
1299 const_iterator begin() const; | 1333 const_iterator begin() const; |
1300 const_iterator end() const; | 1334 const_iterator end() const; |
1301 | 1335 |
1302 // Sort the collection in ascending/descending order by document order | 1336 // Sort the collection in ascending/descending order by document order |
1303 void sort(bool reverse = false); | 1337 void sort(bool reverse = false); |
1304 | 1338 |
1305 // Get first node in the collection by document order | 1339 // Get first node in the collection by document order |
1306 xpath_node first() const; | 1340 xpath_node first() const; |
1307 | 1341 |
1308 // Check if collection is empty | 1342 // Check if collection is empty |
1309 bool empty() const; | 1343 bool empty() const; |
1310 | 1344 |
1311 private: | 1345 private: |
1312 type_t _type; | 1346 type_t _type; |
1313 | 1347 |
1314 xpath_node _storage; | 1348 xpath_node _storage; |
1315 | 1349 |
1316 xpath_node* _begin; | 1350 xpath_node* _begin; |
1317 xpath_node* _end; | 1351 xpath_node* _end; |
1318 | 1352 |
1319 void _assign(const_iterator begin, const_iterator end, type_t type); | 1353 void _assign(const_iterator begin, const_iterator end, type_t type); |
1320 void _move(xpath_node_set& rhs); | 1354 void _move(xpath_node_set& rhs); |
1323 | 1357 |
1324 #ifndef PUGIXML_NO_STL | 1358 #ifndef PUGIXML_NO_STL |
1325 // Convert wide string to UTF8 | 1359 // Convert wide string to UTF8 |
1326 std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const wchar_t* str); | 1360 std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const wchar_t* str); |
1327 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); | 1361 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); |
1328 | 1362 |
1329 // Convert UTF8 to wide string | 1363 // Convert UTF8 to wide string |
1330 std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const char* str); | 1364 std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const char* str); |
1331 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); | 1365 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); |
1332 #endif | 1366 #endif |
1333 | 1367 |
1334 // Memory allocation function interface; returns pointer to allocated memory or NULL on failure | 1368 // Memory allocation function interface; returns pointer to allocated memory or NULL on failure |
1335 typedef void* (*allocation_function)(size_t size); | 1369 typedef void* (*allocation_function)(size_t size); |
1336 | 1370 |
1337 // Memory deallocation function interface | 1371 // Memory deallocation function interface |
1338 typedef void (*deallocation_function)(void* ptr); | 1372 typedef void (*deallocation_function)(void* ptr); |
1339 | 1373 |
1340 // Override default memory management functions. All subsequent allocations/deallocations will be performed via supplied functions. | 1374 // Override default memory management functions. All subsequent allocations/deallocations will be performed via supplied functions. |
1341 void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate); | 1375 void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate); |
1342 | 1376 |
1343 // Get current memory management functions | 1377 // Get current memory management functions |
1344 allocation_function PUGIXML_FUNCTION get_memory_allocation_function(); | 1378 allocation_function PUGIXML_FUNCTION get_memory_allocation_function(); |
1345 deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function(); | 1379 deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function(); |
1346 } | 1380 } |
1347 | 1381 |
1373 # define PUGIXML_SOURCE "pugixml.cpp" | 1407 # define PUGIXML_SOURCE "pugixml.cpp" |
1374 # include PUGIXML_SOURCE | 1408 # include PUGIXML_SOURCE |
1375 #endif | 1409 #endif |
1376 | 1410 |
1377 /** | 1411 /** |
1378 * Copyright (c) 2006-2015 Arseny Kapoulkine | 1412 * Copyright (c) 2006-2016 Arseny Kapoulkine |
1379 * | 1413 * |
1380 * Permission is hereby granted, free of charge, to any person | 1414 * Permission is hereby granted, free of charge, to any person |
1381 * obtaining a copy of this software and associated documentation | 1415 * obtaining a copy of this software and associated documentation |
1382 * files (the "Software"), to deal in the Software without | 1416 * files (the "Software"), to deal in the Software without |
1383 * restriction, including without limitation the rights to use, | 1417 * restriction, including without limitation the rights to use, |
1386 * Software is furnished to do so, subject to the following | 1420 * Software is furnished to do so, subject to the following |
1387 * conditions: | 1421 * conditions: |
1388 * | 1422 * |
1389 * The above copyright notice and this permission notice shall be | 1423 * The above copyright notice and this permission notice shall be |
1390 * included in all copies or substantial portions of the Software. | 1424 * included in all copies or substantial portions of the Software. |
1391 * | 1425 * |
1392 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | 1426 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
1393 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | 1427 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
1394 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | 1428 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
1395 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | 1429 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
1396 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | 1430 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |