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