00001
00014 #ifndef PUGIXML_VERSION
00015
00016 # define PUGIXML_VERSION 170
00017 #endif
00018
00019
00020 #include "pugiconfig.hpp"
00021
00022 #ifndef HEADER_PUGIXML_HPP
00023 #define HEADER_PUGIXML_HPP
00024
00025
00026 #include <stddef.h>
00027
00028
00029 #if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
00030 # include <exception>
00031 #endif
00032
00033
00034 #ifndef PUGIXML_NO_STL
00035 # include <iterator>
00036 # include <iosfwd>
00037 # include <string>
00038 #endif
00039
00040
00041 #ifndef PUGIXML_DEPRECATED
00042 # if defined(__GNUC__)
00043 # define PUGIXML_DEPRECATED __attribute__((deprecated))
00044 # elif defined(_MSC_VER) && _MSC_VER >= 1300
00045 # define PUGIXML_DEPRECATED __declspec(deprecated)
00046 # else
00047 # define PUGIXML_DEPRECATED
00048 # endif
00049 #endif
00050
00051
00052 #ifndef PUGIXML_API
00053 # define PUGIXML_API
00054 #endif
00055
00056
00057 #ifndef PUGIXML_CLASS
00058 # define PUGIXML_CLASS PUGIXML_API
00059 #endif
00060
00061
00062 #ifndef PUGIXML_FUNCTION
00063 # define PUGIXML_FUNCTION PUGIXML_API
00064 #endif
00065
00066
00067 #ifndef PUGIXML_HAS_LONG_LONG
00068 # if __cplusplus >= 201103
00069 # define PUGIXML_HAS_LONG_LONG
00070 # elif defined(_MSC_VER) && _MSC_VER >= 1400
00071 # define PUGIXML_HAS_LONG_LONG
00072 # endif
00073 #endif
00074
00075
00076 #ifdef PUGIXML_WCHAR_MODE
00077 # define PUGIXML_TEXT(t) L ## t
00078 # define PUGIXML_CHAR wchar_t
00079 #else
00080 # define PUGIXML_TEXT(t) t
00081 # define PUGIXML_CHAR char
00082 #endif
00083
00084 namespace pugi
00085 {
00086
00087 typedef PUGIXML_CHAR char_t;
00088
00089 #ifndef PUGIXML_NO_STL
00090
00091 typedef std::basic_string<PUGIXML_CHAR, std::char_traits<PUGIXML_CHAR>, std::allocator<PUGIXML_CHAR> > string_t;
00092 #endif
00093 }
00094
00095
00096 namespace pugi
00097 {
00098
00099 enum xml_node_type
00100 {
00101 node_null,
00102 node_document,
00103 node_element,
00104 node_pcdata,
00105 node_cdata,
00106 node_comment,
00107 node_pi,
00108 node_declaration,
00109 node_doctype
00110 };
00111
00112
00113
00114
00115
00116 const unsigned int parse_minimal = 0x0000;
00117
00118
00119 const unsigned int parse_pi = 0x0001;
00120
00121
00122 const unsigned int parse_comments = 0x0002;
00123
00124
00125 const unsigned int parse_cdata = 0x0004;
00126
00127
00128
00129 const unsigned int parse_ws_pcdata = 0x0008;
00130
00131
00132 const unsigned int parse_escapes = 0x0010;
00133
00134
00135 const unsigned int parse_eol = 0x0020;
00136
00137
00138 const unsigned int parse_wconv_attribute = 0x0040;
00139
00140
00141 const unsigned int parse_wnorm_attribute = 0x0080;
00142
00143
00144 const unsigned int parse_declaration = 0x0100;
00145
00146
00147 const unsigned int parse_doctype = 0x0200;
00148
00149
00150
00151
00152 const unsigned int parse_ws_pcdata_single = 0x0400;
00153
00154
00155 const unsigned int parse_trim_pcdata = 0x0800;
00156
00157
00158
00159 const unsigned int parse_fragment = 0x1000;
00160
00161
00162
00163
00164 const unsigned int parse_default = parse_cdata | parse_escapes | parse_wconv_attribute | parse_eol;
00165
00166
00167
00168
00169 const unsigned int parse_full = parse_default | parse_pi | parse_comments | parse_declaration | parse_doctype;
00170
00171
00172 enum xml_encoding
00173 {
00174 encoding_auto,
00175 encoding_utf8,
00176 encoding_utf16_le,
00177 encoding_utf16_be,
00178 encoding_utf16,
00179 encoding_utf32_le,
00180 encoding_utf32_be,
00181 encoding_utf32,
00182 encoding_wchar,
00183 encoding_latin1
00184 };
00185
00186
00187
00188
00189 const unsigned int format_indent = 0x01;
00190
00191
00192 const unsigned int format_write_bom = 0x02;
00193
00194
00195 const unsigned int format_raw = 0x04;
00196
00197
00198 const unsigned int format_no_declaration = 0x08;
00199
00200
00201 const unsigned int format_no_escapes = 0x10;
00202
00203
00204 const unsigned int format_save_file_text = 0x20;
00205
00206
00207 const unsigned int format_indent_attributes = 0x40;
00208
00209
00210
00211 const unsigned int format_default = format_indent;
00212
00213
00214 struct xml_attribute_struct;
00215 struct xml_node_struct;
00216
00217 class xml_node_iterator;
00218 class xml_attribute_iterator;
00219 class xml_named_node_iterator;
00220
00221 class xml_tree_walker;
00222
00223 struct xml_parse_result;
00224
00225 class xml_node;
00226
00227 class xml_text;
00228
00229 #ifndef PUGIXML_NO_XPATH
00230 class xpath_node;
00231 class xpath_node_set;
00232 class xpath_query;
00233 class xpath_variable_set;
00234 #endif
00235
00236
00237 template <typename It> class xml_object_range
00238 {
00239 public:
00240 typedef It const_iterator;
00241 typedef It iterator;
00242
00243 xml_object_range(It b, It e): _begin(b), _end(e)
00244 {
00245 }
00246
00247 It begin() const { return _begin; }
00248 It end() const { return _end; }
00249
00250 private:
00251 It _begin, _end;
00252 };
00253
00254
00255 class PUGIXML_CLASS xml_writer
00256 {
00257 public:
00258 virtual ~xml_writer() {}
00259
00260
00261 virtual void write(const void* data, size_t size) = 0;
00262 };
00263
00264
00265 class PUGIXML_CLASS xml_writer_file: public xml_writer
00266 {
00267 public:
00268
00269 xml_writer_file(void* file);
00270
00271 virtual void write(const void* data, size_t size);
00272
00273 private:
00274 void* file;
00275 };
00276
00277 #ifndef PUGIXML_NO_STL
00278
00279 class PUGIXML_CLASS xml_writer_stream: public xml_writer
00280 {
00281 public:
00282
00283 xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream);
00284 xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream);
00285
00286 virtual void write(const void* data, size_t size);
00287
00288 private:
00289 std::basic_ostream<char, std::char_traits<char> >* narrow_stream;
00290 std::basic_ostream<wchar_t, std::char_traits<wchar_t> >* wide_stream;
00291 };
00292 #endif
00293
00294
00295 class PUGIXML_CLASS xml_attribute
00296 {
00297 friend class xml_attribute_iterator;
00298 friend class xml_node;
00299
00300 private:
00301 xml_attribute_struct* _attr;
00302
00303 typedef void (*unspecified_bool_type)(xml_attribute***);
00304
00305 public:
00306
00307 xml_attribute();
00308
00309
00310 explicit xml_attribute(xml_attribute_struct* attr);
00311
00312
00313 operator unspecified_bool_type() const;
00314
00315
00316 bool operator!() const;
00317
00318
00319 bool operator==(const xml_attribute& r) const;
00320 bool operator!=(const xml_attribute& r) const;
00321 bool operator<(const xml_attribute& r) const;
00322 bool operator>(const xml_attribute& r) const;
00323 bool operator<=(const xml_attribute& r) const;
00324 bool operator>=(const xml_attribute& r) const;
00325
00326
00327 bool empty() const;
00328
00329
00330 const char_t* name() const;
00331 const char_t* value() const;
00332
00333
00334 const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;
00335
00336
00337 int as_int(int def = 0) const;
00338 unsigned int as_uint(unsigned int def = 0) const;
00339 double as_double(double def = 0) const;
00340 float as_float(float def = 0) const;
00341
00342 #ifdef PUGIXML_HAS_LONG_LONG
00343 long long as_llong(long long def = 0) const;
00344 unsigned long long as_ullong(unsigned long long def = 0) const;
00345 #endif
00346
00347
00348 bool as_bool(bool def = false) const;
00349
00350
00351 bool set_name(const char_t* rhs);
00352 bool set_value(const char_t* rhs);
00353
00354
00355 bool set_value(int rhs);
00356 bool set_value(unsigned int rhs);
00357 bool set_value(double rhs);
00358 bool set_value(float rhs);
00359 bool set_value(bool rhs);
00360
00361 #ifdef PUGIXML_HAS_LONG_LONG
00362 bool set_value(long long rhs);
00363 bool set_value(unsigned long long rhs);
00364 #endif
00365
00366
00367 xml_attribute& operator=(const char_t* rhs);
00368 xml_attribute& operator=(int rhs);
00369 xml_attribute& operator=(unsigned int rhs);
00370 xml_attribute& operator=(double rhs);
00371 xml_attribute& operator=(float rhs);
00372 xml_attribute& operator=(bool rhs);
00373
00374 #ifdef PUGIXML_HAS_LONG_LONG
00375 xml_attribute& operator=(long long rhs);
00376 xml_attribute& operator=(unsigned long long rhs);
00377 #endif
00378
00379
00380 xml_attribute next_attribute() const;
00381 xml_attribute previous_attribute() const;
00382
00383
00384 size_t hash_value() const;
00385
00386
00387 xml_attribute_struct* internal_object() const;
00388 };
00389
00390 #ifdef __BORLANDC__
00391
00392 bool PUGIXML_FUNCTION operator&&(const xml_attribute& lhs, bool rhs);
00393 bool PUGIXML_FUNCTION operator||(const xml_attribute& lhs, bool rhs);
00394 #endif
00395
00396
00397 class PUGIXML_CLASS xml_node
00398 {
00399 friend class xml_attribute_iterator;
00400 friend class xml_node_iterator;
00401 friend class xml_named_node_iterator;
00402
00403 protected:
00404 xml_node_struct* _root;
00405
00406 typedef void (*unspecified_bool_type)(xml_node***);
00407
00408 public:
00409
00410 xml_node();
00411
00412
00413 explicit xml_node(xml_node_struct* p);
00414
00415
00416 operator unspecified_bool_type() const;
00417
00418
00419 bool operator!() const;
00420
00421
00422 bool operator==(const xml_node& r) const;
00423 bool operator!=(const xml_node& r) const;
00424 bool operator<(const xml_node& r) const;
00425 bool operator>(const xml_node& r) const;
00426 bool operator<=(const xml_node& r) const;
00427 bool operator>=(const xml_node& r) const;
00428
00429
00430 bool empty() const;
00431
00432
00433 xml_node_type type() const;
00434
00435
00436 const char_t* name() const;
00437
00438
00439
00440 const char_t* value() const;
00441
00442
00443 xml_attribute first_attribute() const;
00444 xml_attribute last_attribute() const;
00445
00446
00447 xml_node first_child() const;
00448 xml_node last_child() const;
00449
00450
00451 xml_node next_sibling() const;
00452 xml_node previous_sibling() const;
00453
00454
00455 xml_node parent() const;
00456
00457
00458 xml_node root() const;
00459
00460
00461 xml_text text() const;
00462
00463
00464 xml_node child(const char_t* name) const;
00465 xml_attribute attribute(const char_t* name) const;
00466 xml_node next_sibling(const char_t* name) const;
00467 xml_node previous_sibling(const char_t* name) const;
00468
00469
00470 xml_attribute attribute(const char_t* name, xml_attribute& hint) const;
00471
00472
00473 const char_t* child_value() const;
00474
00475
00476 const char_t* child_value(const char_t* name) const;
00477
00478
00479 bool set_name(const char_t* rhs);
00480 bool set_value(const char_t* rhs);
00481
00482
00483 xml_attribute append_attribute(const char_t* name);
00484 xml_attribute prepend_attribute(const char_t* name);
00485 xml_attribute insert_attribute_after(const char_t* name, const xml_attribute& attr);
00486 xml_attribute insert_attribute_before(const char_t* name, const xml_attribute& attr);
00487
00488
00489 xml_attribute append_copy(const xml_attribute& proto);
00490 xml_attribute prepend_copy(const xml_attribute& proto);
00491 xml_attribute insert_copy_after(const xml_attribute& proto, const xml_attribute& attr);
00492 xml_attribute insert_copy_before(const xml_attribute& proto, const xml_attribute& attr);
00493
00494
00495 xml_node append_child(xml_node_type type = node_element);
00496 xml_node prepend_child(xml_node_type type = node_element);
00497 xml_node insert_child_after(xml_node_type type, const xml_node& node);
00498 xml_node insert_child_before(xml_node_type type, const xml_node& node);
00499
00500
00501 xml_node append_child(const char_t* name);
00502 xml_node prepend_child(const char_t* name);
00503 xml_node insert_child_after(const char_t* name, const xml_node& node);
00504 xml_node insert_child_before(const char_t* name, const xml_node& node);
00505
00506
00507 xml_node append_copy(const xml_node& proto);
00508 xml_node prepend_copy(const xml_node& proto);
00509 xml_node insert_copy_after(const xml_node& proto, const xml_node& node);
00510 xml_node insert_copy_before(const xml_node& proto, const xml_node& node);
00511
00512
00513 xml_node append_move(const xml_node& moved);
00514 xml_node prepend_move(const xml_node& moved);
00515 xml_node insert_move_after(const xml_node& moved, const xml_node& node);
00516 xml_node insert_move_before(const xml_node& moved, const xml_node& node);
00517
00518
00519 bool remove_attribute(const xml_attribute& a);
00520 bool remove_attribute(const char_t* name);
00521
00522
00523 bool remove_child(const xml_node& n);
00524 bool remove_child(const char_t* name);
00525
00526
00527
00528
00529 xml_parse_result append_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
00530
00531
00532 template <typename Predicate> xml_attribute find_attribute(Predicate pred) const
00533 {
00534 if (!_root) return xml_attribute();
00535
00536 for (xml_attribute attrib = first_attribute(); attrib; attrib = attrib.next_attribute())
00537 if (pred(attrib))
00538 return attrib;
00539
00540 return xml_attribute();
00541 }
00542
00543
00544 template <typename Predicate> xml_node find_child(Predicate pred) const
00545 {
00546 if (!_root) return xml_node();
00547
00548 for (xml_node node = first_child(); node; node = node.next_sibling())
00549 if (pred(node))
00550 return node;
00551
00552 return xml_node();
00553 }
00554
00555
00556 template <typename Predicate> xml_node find_node(Predicate pred) const
00557 {
00558 if (!_root) return xml_node();
00559
00560 xml_node cur = first_child();
00561
00562 while (cur._root && cur._root != _root)
00563 {
00564 if (pred(cur)) return cur;
00565
00566 if (cur.first_child()) cur = cur.first_child();
00567 else if (cur.next_sibling()) cur = cur.next_sibling();
00568 else
00569 {
00570 while (!cur.next_sibling() && cur._root != _root) cur = cur.parent();
00571
00572 if (cur._root != _root) cur = cur.next_sibling();
00573 }
00574 }
00575
00576 return xml_node();
00577 }
00578
00579
00580 xml_node find_child_by_attribute(const char_t* name, const char_t* attr_name, const char_t* attr_value) const;
00581 xml_node find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const;
00582
00583 #ifndef PUGIXML_NO_STL
00584
00585 string_t path(char_t delimiter = '/') const;
00586 #endif
00587
00588
00589 xml_node first_element_by_path(const char_t* path, char_t delimiter = '/') const;
00590
00591
00592 bool traverse(xml_tree_walker& walker);
00593
00594 #ifndef PUGIXML_NO_XPATH
00595
00596 xpath_node select_node(const char_t* query, xpath_variable_set* variables = 0) const;
00597 xpath_node select_node(const xpath_query& query) const;
00598
00599
00600 xpath_node_set select_nodes(const char_t* query, xpath_variable_set* variables = 0) const;
00601 xpath_node_set select_nodes(const xpath_query& query) const;
00602
00603
00604 xpath_node select_single_node(const char_t* query, xpath_variable_set* variables = 0) const;
00605 xpath_node select_single_node(const xpath_query& query) const;
00606
00607 #endif
00608
00609
00610 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;
00611
00612 #ifndef PUGIXML_NO_STL
00613
00614 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;
00615 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;
00616 #endif
00617
00618
00619 typedef xml_node_iterator iterator;
00620
00621 iterator begin() const;
00622 iterator end() const;
00623
00624
00625 typedef xml_attribute_iterator attribute_iterator;
00626
00627 attribute_iterator attributes_begin() const;
00628 attribute_iterator attributes_end() const;
00629
00630
00631 xml_object_range<xml_node_iterator> children() const;
00632 xml_object_range<xml_named_node_iterator> children(const char_t* name) const;
00633 xml_object_range<xml_attribute_iterator> attributes() const;
00634
00635
00636 ptrdiff_t offset_debug() const;
00637
00638
00639 size_t hash_value() const;
00640
00641
00642 xml_node_struct* internal_object() const;
00643 };
00644
00645 #ifdef __BORLANDC__
00646
00647 bool PUGIXML_FUNCTION operator&&(const xml_node& lhs, bool rhs);
00648 bool PUGIXML_FUNCTION operator||(const xml_node& lhs, bool rhs);
00649 #endif
00650
00651
00652 class PUGIXML_CLASS xml_text
00653 {
00654 friend class xml_node;
00655
00656 xml_node_struct* _root;
00657
00658 typedef void (*unspecified_bool_type)(xml_text***);
00659
00660 explicit xml_text(xml_node_struct* root);
00661
00662 xml_node_struct* _data_new();
00663 xml_node_struct* _data() const;
00664
00665 public:
00666
00667 xml_text();
00668
00669
00670 operator unspecified_bool_type() const;
00671
00672
00673 bool operator!() const;
00674
00675
00676 bool empty() const;
00677
00678
00679 const char_t* get() const;
00680
00681
00682 const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;
00683
00684
00685 int as_int(int def = 0) const;
00686 unsigned int as_uint(unsigned int def = 0) const;
00687 double as_double(double def = 0) const;
00688 float as_float(float def = 0) const;
00689
00690 #ifdef PUGIXML_HAS_LONG_LONG
00691 long long as_llong(long long def = 0) const;
00692 unsigned long long as_ullong(unsigned long long def = 0) const;
00693 #endif
00694
00695
00696 bool as_bool(bool def = false) const;
00697
00698
00699 bool set(const char_t* rhs);
00700
00701
00702 bool set(int rhs);
00703 bool set(unsigned int rhs);
00704 bool set(double rhs);
00705 bool set(float rhs);
00706 bool set(bool rhs);
00707
00708 #ifdef PUGIXML_HAS_LONG_LONG
00709 bool set(long long rhs);
00710 bool set(unsigned long long rhs);
00711 #endif
00712
00713
00714 xml_text& operator=(const char_t* rhs);
00715 xml_text& operator=(int rhs);
00716 xml_text& operator=(unsigned int rhs);
00717 xml_text& operator=(double rhs);
00718 xml_text& operator=(float rhs);
00719 xml_text& operator=(bool rhs);
00720
00721 #ifdef PUGIXML_HAS_LONG_LONG
00722 xml_text& operator=(long long rhs);
00723 xml_text& operator=(unsigned long long rhs);
00724 #endif
00725
00726
00727 xml_node data() const;
00728 };
00729
00730 #ifdef __BORLANDC__
00731
00732 bool PUGIXML_FUNCTION operator&&(const xml_text& lhs, bool rhs);
00733 bool PUGIXML_FUNCTION operator||(const xml_text& lhs, bool rhs);
00734 #endif
00735
00736
00737 class PUGIXML_CLASS xml_node_iterator
00738 {
00739 friend class xml_node;
00740
00741 private:
00742 mutable xml_node _wrap;
00743 xml_node _parent;
00744
00745 xml_node_iterator(xml_node_struct* ref, xml_node_struct* parent);
00746
00747 public:
00748
00749 typedef ptrdiff_t difference_type;
00750 typedef xml_node value_type;
00751 typedef xml_node* pointer;
00752 typedef xml_node& reference;
00753
00754 #ifndef PUGIXML_NO_STL
00755 typedef std::bidirectional_iterator_tag iterator_category;
00756 #endif
00757
00758
00759 xml_node_iterator();
00760
00761
00762 xml_node_iterator(const xml_node& node);
00763
00764
00765 bool operator==(const xml_node_iterator& rhs) const;
00766 bool operator!=(const xml_node_iterator& rhs) const;
00767
00768 xml_node& operator*() const;
00769 xml_node* operator->() const;
00770
00771 const xml_node_iterator& operator++();
00772 xml_node_iterator operator++(int);
00773
00774 const xml_node_iterator& operator--();
00775 xml_node_iterator operator--(int);
00776 };
00777
00778
00779 class PUGIXML_CLASS xml_attribute_iterator
00780 {
00781 friend class xml_node;
00782
00783 private:
00784 mutable xml_attribute _wrap;
00785 xml_node _parent;
00786
00787 xml_attribute_iterator(xml_attribute_struct* ref, xml_node_struct* parent);
00788
00789 public:
00790
00791 typedef ptrdiff_t difference_type;
00792 typedef xml_attribute value_type;
00793 typedef xml_attribute* pointer;
00794 typedef xml_attribute& reference;
00795
00796 #ifndef PUGIXML_NO_STL
00797 typedef std::bidirectional_iterator_tag iterator_category;
00798 #endif
00799
00800
00801 xml_attribute_iterator();
00802
00803
00804 xml_attribute_iterator(const xml_attribute& attr, const xml_node& parent);
00805
00806
00807 bool operator==(const xml_attribute_iterator& rhs) const;
00808 bool operator!=(const xml_attribute_iterator& rhs) const;
00809
00810 xml_attribute& operator*() const;
00811 xml_attribute* operator->() const;
00812
00813 const xml_attribute_iterator& operator++();
00814 xml_attribute_iterator operator++(int);
00815
00816 const xml_attribute_iterator& operator--();
00817 xml_attribute_iterator operator--(int);
00818 };
00819
00820
00821 class PUGIXML_CLASS xml_named_node_iterator
00822 {
00823 friend class xml_node;
00824
00825 public:
00826
00827 typedef ptrdiff_t difference_type;
00828 typedef xml_node value_type;
00829 typedef xml_node* pointer;
00830 typedef xml_node& reference;
00831
00832 #ifndef PUGIXML_NO_STL
00833 typedef std::bidirectional_iterator_tag iterator_category;
00834 #endif
00835
00836
00837 xml_named_node_iterator();
00838
00839
00840 xml_named_node_iterator(const xml_node& node, const char_t* name);
00841
00842
00843 bool operator==(const xml_named_node_iterator& rhs) const;
00844 bool operator!=(const xml_named_node_iterator& rhs) const;
00845
00846 xml_node& operator*() const;
00847 xml_node* operator->() const;
00848
00849 const xml_named_node_iterator& operator++();
00850 xml_named_node_iterator operator++(int);
00851
00852 const xml_named_node_iterator& operator--();
00853 xml_named_node_iterator operator--(int);
00854
00855 private:
00856 mutable xml_node _wrap;
00857 xml_node _parent;
00858 const char_t* _name;
00859
00860 xml_named_node_iterator(xml_node_struct* ref, xml_node_struct* parent, const char_t* name);
00861 };
00862
00863
00864 class PUGIXML_CLASS xml_tree_walker
00865 {
00866 friend class xml_node;
00867
00868 private:
00869 int _depth;
00870
00871 protected:
00872
00873 int depth() const;
00874
00875 public:
00876 xml_tree_walker();
00877 virtual ~xml_tree_walker();
00878
00879
00880 virtual bool begin(xml_node& node);
00881
00882
00883 virtual bool for_each(xml_node& node) = 0;
00884
00885
00886 virtual bool end(xml_node& node);
00887 };
00888
00889
00890 enum xml_parse_status
00891 {
00892 status_ok = 0,
00893
00894 status_file_not_found,
00895 status_io_error,
00896 status_out_of_memory,
00897 status_internal_error,
00898
00899 status_unrecognized_tag,
00900
00901 status_bad_pi,
00902 status_bad_comment,
00903 status_bad_cdata,
00904 status_bad_doctype,
00905 status_bad_pcdata,
00906 status_bad_start_element,
00907 status_bad_attribute,
00908 status_bad_end_element,
00909 status_end_element_mismatch,
00910
00911 status_append_invalid_root,
00912
00913 status_no_document_element
00914 };
00915
00916
00917 struct PUGIXML_CLASS xml_parse_result
00918 {
00919
00920 xml_parse_status status;
00921
00922
00923 ptrdiff_t offset;
00924
00925
00926 xml_encoding encoding;
00927
00928
00929 xml_parse_result();
00930
00931
00932 operator bool() const;
00933
00934
00935 const char* description() const;
00936 };
00937
00938
00939 class PUGIXML_CLASS xml_document: public xml_node
00940 {
00941 private:
00942 char_t* _buffer;
00943
00944 char _memory[192];
00945
00946
00947 xml_document(const xml_document&);
00948 xml_document& operator=(const xml_document&);
00949
00950 void create();
00951 void destroy();
00952
00953 public:
00954
00955 xml_document();
00956
00957
00958 ~xml_document();
00959
00960
00961 void reset();
00962
00963
00964 void reset(const xml_document& proto);
00965
00966 #ifndef PUGIXML_NO_STL
00967
00968 xml_parse_result load(std::basic_istream<char, std::char_traits<char> >& stream, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
00969 xml_parse_result load(std::basic_istream<wchar_t, std::char_traits<wchar_t> >& stream, unsigned int options = parse_default);
00970 #endif
00971
00972
00973 xml_parse_result load(const char_t* contents, unsigned int options = parse_default);
00974
00975
00976 xml_parse_result load_string(const char_t* contents, unsigned int options = parse_default);
00977
00978
00979 xml_parse_result load_file(const char* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
00980 xml_parse_result load_file(const wchar_t* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
00981
00982
00983 xml_parse_result load_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
00984
00985
00986
00987 xml_parse_result load_buffer_inplace(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
00988
00989
00990
00991 xml_parse_result load_buffer_inplace_own(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
00992
00993
00994 void save(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
00995
00996 #ifndef PUGIXML_NO_STL
00997
00998 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;
00999 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;
01000 #endif
01001
01002
01003 bool save_file(const char* path, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
01004 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;
01005
01006
01007 xml_node document_element() const;
01008 };
01009
01010 #ifndef PUGIXML_NO_XPATH
01011
01012 enum xpath_value_type
01013 {
01014 xpath_type_none,
01015 xpath_type_node_set,
01016 xpath_type_number,
01017 xpath_type_string,
01018 xpath_type_boolean
01019 };
01020
01021
01022 struct PUGIXML_CLASS xpath_parse_result
01023 {
01024
01025 const char* error;
01026
01027
01028 ptrdiff_t offset;
01029
01030
01031 xpath_parse_result();
01032
01033
01034 operator bool() const;
01035
01036
01037 const char* description() const;
01038 };
01039
01040
01041 class PUGIXML_CLASS xpath_variable
01042 {
01043 friend class xpath_variable_set;
01044
01045 protected:
01046 xpath_value_type _type;
01047 xpath_variable* _next;
01048
01049 xpath_variable(xpath_value_type type);
01050
01051
01052 xpath_variable(const xpath_variable&);
01053 xpath_variable& operator=(const xpath_variable&);
01054
01055 public:
01056
01057 const char_t* name() const;
01058
01059
01060 xpath_value_type type() const;
01061
01062
01063 bool get_boolean() const;
01064 double get_number() const;
01065 const char_t* get_string() const;
01066 const xpath_node_set& get_node_set() const;
01067
01068
01069 bool set(bool value);
01070 bool set(double value);
01071 bool set(const char_t* value);
01072 bool set(const xpath_node_set& value);
01073 };
01074
01075
01076 class PUGIXML_CLASS xpath_variable_set
01077 {
01078 private:
01079 xpath_variable* _data[64];
01080
01081 void _assign(const xpath_variable_set& rhs);
01082 void _swap(xpath_variable_set& rhs);
01083
01084 xpath_variable* _find(const char_t* name) const;
01085
01086 static bool _clone(xpath_variable* var, xpath_variable** out_result);
01087 static void _destroy(xpath_variable* var);
01088
01089 public:
01090
01091 xpath_variable_set();
01092 ~xpath_variable_set();
01093
01094
01095 xpath_variable_set(const xpath_variable_set& rhs);
01096 xpath_variable_set& operator=(const xpath_variable_set& rhs);
01097
01098 #if __cplusplus >= 201103
01099
01100 xpath_variable_set(xpath_variable_set&& rhs);
01101 xpath_variable_set& operator=(xpath_variable_set&& rhs);
01102 #endif
01103
01104
01105 xpath_variable* add(const char_t* name, xpath_value_type type);
01106
01107
01108 bool set(const char_t* name, bool value);
01109 bool set(const char_t* name, double value);
01110 bool set(const char_t* name, const char_t* value);
01111 bool set(const char_t* name, const xpath_node_set& value);
01112
01113
01114 xpath_variable* get(const char_t* name);
01115 const xpath_variable* get(const char_t* name) const;
01116 };
01117
01118
01119 class PUGIXML_CLASS xpath_query
01120 {
01121 private:
01122 void* _impl;
01123 xpath_parse_result _result;
01124
01125 typedef void (*unspecified_bool_type)(xpath_query***);
01126
01127
01128 xpath_query(const xpath_query&);
01129 xpath_query& operator=(const xpath_query&);
01130
01131 public:
01132
01133
01134 explicit xpath_query(const char_t* query, xpath_variable_set* variables = 0);
01135
01136
01137 xpath_query();
01138
01139
01140 ~xpath_query();
01141
01142 #if __cplusplus >= 201103
01143
01144 xpath_query(xpath_query&& rhs);
01145 xpath_query& operator=(xpath_query&& rhs);
01146 #endif
01147
01148
01149 xpath_value_type return_type() const;
01150
01151
01152
01153 bool evaluate_boolean(const xpath_node& n) const;
01154
01155
01156
01157 double evaluate_number(const xpath_node& n) const;
01158
01159 #ifndef PUGIXML_NO_STL
01160
01161
01162 string_t evaluate_string(const xpath_node& n) const;
01163 #endif
01164
01165
01166
01167
01168
01169 size_t evaluate_string(char_t* buffer, size_t capacity, const xpath_node& n) const;
01170
01171
01172
01173
01174 xpath_node_set evaluate_node_set(const xpath_node& n) const;
01175
01176
01177
01178
01179
01180 xpath_node evaluate_node(const xpath_node& n) const;
01181
01182
01183 const xpath_parse_result& result() const;
01184
01185
01186 operator unspecified_bool_type() const;
01187
01188
01189 bool operator!() const;
01190 };
01191
01192 #ifndef PUGIXML_NO_EXCEPTIONS
01193
01194 class PUGIXML_CLASS xpath_exception: public std::exception
01195 {
01196 private:
01197 xpath_parse_result _result;
01198
01199 public:
01200
01201 explicit xpath_exception(const xpath_parse_result& result);
01202
01203
01204 virtual const char* what() const throw();
01205
01206
01207 const xpath_parse_result& result() const;
01208 };
01209 #endif
01210
01211
01212 class PUGIXML_CLASS xpath_node
01213 {
01214 private:
01215 xml_node _node;
01216 xml_attribute _attribute;
01217
01218 typedef void (*unspecified_bool_type)(xpath_node***);
01219
01220 public:
01221
01222 xpath_node();
01223
01224
01225 xpath_node(const xml_node& node);
01226 xpath_node(const xml_attribute& attribute, const xml_node& parent);
01227
01228
01229 xml_node node() const;
01230 xml_attribute attribute() const;
01231
01232
01233 xml_node parent() const;
01234
01235
01236 operator unspecified_bool_type() const;
01237
01238
01239 bool operator!() const;
01240
01241
01242 bool operator==(const xpath_node& n) const;
01243 bool operator!=(const xpath_node& n) const;
01244 };
01245
01246 #ifdef __BORLANDC__
01247
01248 bool PUGIXML_FUNCTION operator&&(const xpath_node& lhs, bool rhs);
01249 bool PUGIXML_FUNCTION operator||(const xpath_node& lhs, bool rhs);
01250 #endif
01251
01252
01253 class PUGIXML_CLASS xpath_node_set
01254 {
01255 public:
01256
01257 enum type_t
01258 {
01259 type_unsorted,
01260 type_sorted,
01261 type_sorted_reverse
01262 };
01263
01264
01265 typedef const xpath_node* const_iterator;
01266
01267
01268 typedef const xpath_node* iterator;
01269
01270
01271 xpath_node_set();
01272
01273
01274 xpath_node_set(const_iterator begin, const_iterator end, type_t type = type_unsorted);
01275
01276
01277 ~xpath_node_set();
01278
01279
01280 xpath_node_set(const xpath_node_set& ns);
01281 xpath_node_set& operator=(const xpath_node_set& ns);
01282
01283 #if __cplusplus >= 201103
01284
01285 xpath_node_set(xpath_node_set&& rhs);
01286 xpath_node_set& operator=(xpath_node_set&& rhs);
01287 #endif
01288
01289
01290 type_t type() const;
01291
01292
01293 size_t size() const;
01294
01295
01296 const xpath_node& operator[](size_t index) const;
01297
01298
01299 const_iterator begin() const;
01300 const_iterator end() const;
01301
01302
01303 void sort(bool reverse = false);
01304
01305
01306 xpath_node first() const;
01307
01308
01309 bool empty() const;
01310
01311 private:
01312 type_t _type;
01313
01314 xpath_node _storage;
01315
01316 xpath_node* _begin;
01317 xpath_node* _end;
01318
01319 void _assign(const_iterator begin, const_iterator end, type_t type);
01320 void _move(xpath_node_set& rhs);
01321 };
01322 #endif
01323
01324 #ifndef PUGIXML_NO_STL
01325
01326 std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const wchar_t* str);
01327 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);
01328
01329
01330 std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const char* str);
01331 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);
01332 #endif
01333
01334
01335 typedef void* (*allocation_function)(size_t size);
01336
01337
01338 typedef void (*deallocation_function)(void* ptr);
01339
01340
01341 void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate);
01342
01343
01344 allocation_function PUGIXML_FUNCTION get_memory_allocation_function();
01345 deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function();
01346 }
01347
01348 #if !defined(PUGIXML_NO_STL) && (defined(_MSC_VER) || defined(__ICC))
01349 namespace std
01350 {
01351
01352 std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_node_iterator&);
01353 std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_attribute_iterator&);
01354 std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_named_node_iterator&);
01355 }
01356 #endif
01357
01358 #if !defined(PUGIXML_NO_STL) && defined(__SUNPRO_CC)
01359 namespace std
01360 {
01361
01362 std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_node_iterator&);
01363 std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_attribute_iterator&);
01364 std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_named_node_iterator&);
01365 }
01366 #endif
01367
01368 #endif
01369
01370
01371
01372 #if defined(PUGIXML_HEADER_ONLY) && !defined(PUGIXML_SOURCE)
01373 # define PUGIXML_SOURCE "pugixml.cpp"
01374 # include PUGIXML_SOURCE
01375 #endif
01376