pugixml.hpp
Go to the documentation of this file.
00001 
00014 #ifndef PUGIXML_VERSION
00015 // Define version macro; evaluates to major * 100 + minor so that it's safe to use in less-than comparisons
00016 #       define PUGIXML_VERSION 170
00017 #endif
00018 
00019 // Include user configuration file (this can define various configuration macros)
00020 #include "pugiconfig.hpp"
00021 
00022 #ifndef HEADER_PUGIXML_HPP
00023 #define HEADER_PUGIXML_HPP
00024 
00025 // Include stddef.h for size_t and ptrdiff_t
00026 #include <stddef.h>
00027 
00028 // Include exception header for XPath
00029 #if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
00030 #       include <exception>
00031 #endif
00032 
00033 // Include STL headers
00034 #ifndef PUGIXML_NO_STL
00035 #       include <iterator>
00036 #       include <iosfwd>
00037 #       include <string>
00038 #endif
00039 
00040 // Macro for deprecated features
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 // If no API is defined, assume default
00052 #ifndef PUGIXML_API
00053 #       define PUGIXML_API
00054 #endif
00055 
00056 // If no API for classes is defined, assume default
00057 #ifndef PUGIXML_CLASS
00058 #       define PUGIXML_CLASS PUGIXML_API
00059 #endif
00060 
00061 // If no API for functions is defined, assume default
00062 #ifndef PUGIXML_FUNCTION
00063 #       define PUGIXML_FUNCTION PUGIXML_API
00064 #endif
00065 
00066 // If the platform is known to have long long support, enable long long functions
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 // Character interface macros
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         // Character type used for all internal storage and operations; depends on PUGIXML_WCHAR_MODE
00087         typedef PUGIXML_CHAR char_t;
00088 
00089 #ifndef PUGIXML_NO_STL
00090         // String type used for operations that work with STL string; depends on PUGIXML_WCHAR_MODE
00091         typedef std::basic_string<PUGIXML_CHAR, std::char_traits<PUGIXML_CHAR>, std::allocator<PUGIXML_CHAR> > string_t;
00092 #endif
00093 }
00094 
00095 // The PugiXML namespace
00096 namespace pugi
00097 {
00098         // Tree node types
00099         enum xml_node_type
00100         {
00101                 node_null,                      // Empty (null) node handle
00102                 node_document,          // A document tree's absolute root
00103                 node_element,           // Element tag, i.e. '<node/>'
00104                 node_pcdata,            // Plain character data, i.e. 'text'
00105                 node_cdata,                     // Character data, i.e. '<![CDATA[text]]>'
00106                 node_comment,           // Comment tag, i.e. '<!-- text -->'
00107                 node_pi,                        // Processing instruction, i.e. '<?name?>'
00108                 node_declaration,       // Document declaration, i.e. '<?xml version="1.0"?>'
00109                 node_doctype            // Document type declaration, i.e. '<!DOCTYPE doc>'
00110         };
00111 
00112         // Parsing options
00113 
00114         // Minimal parsing mode (equivalent to turning all other flags off).
00115         // Only elements and PCDATA sections are added to the DOM tree, no text conversions are performed.
00116         const unsigned int parse_minimal = 0x0000;
00117 
00118         // This flag determines if processing instructions (node_pi) are added to the DOM tree. This flag is off by default.
00119         const unsigned int parse_pi = 0x0001;
00120 
00121         // This flag determines if comments (node_comment) are added to the DOM tree. This flag is off by default.
00122         const unsigned int parse_comments = 0x0002;
00123 
00124         // This flag determines if CDATA sections (node_cdata) are added to the DOM tree. This flag is on by default.
00125         const unsigned int parse_cdata = 0x0004;
00126 
00127         // This flag determines if plain character data (node_pcdata) that consist only of whitespace are added to the DOM tree.
00128         // This flag is off by default; turning it on usually results in slower parsing and more memory consumption.
00129         const unsigned int parse_ws_pcdata = 0x0008;
00130 
00131         // This flag determines if character and entity references are expanded during parsing. This flag is on by default.
00132         const unsigned int parse_escapes = 0x0010;
00133 
00134         // This flag determines if EOL characters are normalized (converted to #xA) during parsing. This flag is on by default.
00135         const unsigned int parse_eol = 0x0020;
00136         
00137         // This flag determines if attribute values are normalized using CDATA normalization rules during parsing. This flag is on by default.
00138         const unsigned int parse_wconv_attribute = 0x0040;
00139 
00140         // This flag determines if attribute values are normalized using NMTOKENS normalization rules during parsing. This flag is off by default.
00141         const unsigned int parse_wnorm_attribute = 0x0080;
00142         
00143         // This flag determines if document declaration (node_declaration) is added to the DOM tree. This flag is off by default.
00144         const unsigned int parse_declaration = 0x0100;
00145 
00146         // This flag determines if document type declaration (node_doctype) is added to the DOM tree. This flag is off by default.
00147         const unsigned int parse_doctype = 0x0200;
00148 
00149         // This flag determines if plain character data (node_pcdata) that is the only child of the parent node and that consists only
00150         // of whitespace is added to the DOM tree.
00151         // This flag is off by default; turning it on may result in slower parsing and more memory consumption.
00152         const unsigned int parse_ws_pcdata_single = 0x0400;
00153 
00154         // This flag determines if leading and trailing whitespace is to be removed from plain character data. This flag is off by default.
00155         const unsigned int parse_trim_pcdata = 0x0800;
00156 
00157         // 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
00158         // is a valid document. This flag is off by default.
00159         const unsigned int parse_fragment = 0x1000;
00160 
00161         // The default parsing mode.
00162         // Elements, PCDATA and CDATA sections are added to the DOM tree, character/reference entities are expanded,
00163         // End-of-Line characters are normalized, attribute values are normalized using CDATA normalization rules.
00164         const unsigned int parse_default = parse_cdata | parse_escapes | parse_wconv_attribute | parse_eol;
00165 
00166         // The full parsing mode.
00167         // Nodes of all types are added to the DOM tree, character/reference entities are expanded,
00168         // End-of-Line characters are normalized, attribute values are normalized using CDATA normalization rules.
00169         const unsigned int parse_full = parse_default | parse_pi | parse_comments | parse_declaration | parse_doctype;
00170 
00171         // These flags determine the encoding of input data for XML document
00172         enum xml_encoding
00173         {
00174                 encoding_auto,          // Auto-detect input encoding using BOM or < / <? detection; use UTF8 if BOM is not found
00175                 encoding_utf8,          // UTF8 encoding
00176                 encoding_utf16_le,      // Little-endian UTF16
00177                 encoding_utf16_be,      // Big-endian UTF16
00178                 encoding_utf16,         // UTF16 with native endianness
00179                 encoding_utf32_le,      // Little-endian UTF32
00180                 encoding_utf32_be,      // Big-endian UTF32
00181                 encoding_utf32,         // UTF32 with native endianness
00182                 encoding_wchar,         // The same encoding wchar_t has (either UTF16 or UTF32)
00183                 encoding_latin1
00184         };
00185 
00186         // Formatting flags
00187         
00188         // 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.
00189         const unsigned int format_indent = 0x01;
00190         
00191         // Write encoding-specific BOM to the output stream. This flag is off by default.
00192         const unsigned int format_write_bom = 0x02;
00193 
00194         // Use raw output mode (no indentation and no line breaks are written). This flag is off by default.
00195         const unsigned int format_raw = 0x04;
00196         
00197         // Omit default XML declaration even if there is no declaration in the document. This flag is off by default.
00198         const unsigned int format_no_declaration = 0x08;
00199 
00200         // Don't escape attribute values and PCDATA contents. This flag is off by default.
00201         const unsigned int format_no_escapes = 0x10;
00202 
00203         // 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.
00204         const unsigned int format_save_file_text = 0x20;
00205 
00206         // Write every attribute on a new line with appropriate indentation. This flag is off by default.
00207         const unsigned int format_indent_attributes = 0x40;
00208 
00209         // The default set of formatting flags.
00210         // Nodes are indented depending on their depth in DOM tree, a default declaration is output if document has none.
00211         const unsigned int format_default = format_indent;
00212 
00213         // Forward declarations
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         // Range-based for loop support
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         // Writer interface for node printing (see xml_node::print)
00255         class PUGIXML_CLASS xml_writer
00256         {
00257         public:
00258                 virtual ~xml_writer() {}
00259 
00260                 // Write memory chunk into stream/file/whatever
00261                 virtual void write(const void* data, size_t size) = 0;
00262         };
00263 
00264         // xml_writer implementation for FILE*
00265         class PUGIXML_CLASS xml_writer_file: public xml_writer
00266         {
00267         public:
00268                 // Construct writer from a FILE* object; void* is used to avoid header dependencies on stdio
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         // xml_writer implementation for streams
00279         class PUGIXML_CLASS xml_writer_stream: public xml_writer
00280         {
00281         public:
00282                 // Construct writer from an output stream object
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         // A light-weight handle for manipulating attributes in DOM tree
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                 // Default constructor. Constructs an empty attribute.
00307                 xml_attribute();
00308                 
00309                 // Constructs attribute from internal pointer
00310                 explicit xml_attribute(xml_attribute_struct* attr);
00311 
00312                 // Safe bool conversion operator
00313                 operator unspecified_bool_type() const;
00314 
00315                 // Borland C++ workaround
00316                 bool operator!() const;
00317 
00318                 // Comparison operators (compares wrapped attribute pointers)
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                 // Check if attribute is empty
00327                 bool empty() const;
00328 
00329                 // Get attribute name/value, or "" if attribute is empty
00330                 const char_t* name() const;
00331                 const char_t* value() const;
00332 
00333                 // Get attribute value, or the default value if attribute is empty
00334                 const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;
00335 
00336                 // Get attribute value as a number, or the default value if conversion did not succeed or attribute is empty
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                 // Get attribute value as bool (returns true if first character is in '1tTyY' set), or the default value if attribute is empty
00348                 bool as_bool(bool def = false) const;
00349 
00350                 // Set attribute name/value (returns false if attribute is empty or there is not enough memory)
00351                 bool set_name(const char_t* rhs);
00352                 bool set_value(const char_t* rhs);
00353 
00354                 // Set attribute value with type conversion (numbers are converted to strings, boolean is converted to "true"/"false")
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                 // Set attribute value (equivalent to set_value without error checking)
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                 // Get next/previous attribute in the attribute list of the parent node
00380                 xml_attribute next_attribute() const;
00381                 xml_attribute previous_attribute() const;
00382 
00383                 // Get hash value (unique for handles to the same object)
00384                 size_t hash_value() const;
00385 
00386                 // Get internal pointer
00387                 xml_attribute_struct* internal_object() const;
00388         };
00389 
00390 #ifdef __BORLANDC__
00391         // Borland C++ workaround
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         // A light-weight handle for manipulating nodes in DOM tree
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                 // Default constructor. Constructs an empty node.
00410                 xml_node();
00411 
00412                 // Constructs node from internal pointer
00413                 explicit xml_node(xml_node_struct* p);
00414 
00415                 // Safe bool conversion operator
00416                 operator unspecified_bool_type() const;
00417 
00418                 // Borland C++ workaround
00419                 bool operator!() const;
00420         
00421                 // Comparison operators (compares wrapped node pointers)
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                 // Check if node is empty.
00430                 bool empty() const;
00431 
00432                 // Get node type
00433                 xml_node_type type() const;
00434 
00435                 // Get node name, or "" if node is empty or it has no name
00436                 const char_t* name() const;
00437 
00438                 // Get node value, or "" if node is empty or it has no value
00439                 // Note: For <node>text</node> node.value() does not return "text"! Use child_value() or text() methods to access text inside nodes.
00440                 const char_t* value() const;
00441         
00442                 // Get attribute list
00443                 xml_attribute first_attribute() const;
00444                 xml_attribute last_attribute() const;
00445 
00446                 // Get children list
00447                 xml_node first_child() const;
00448                 xml_node last_child() const;
00449 
00450                 // Get next/previous sibling in the children list of the parent node
00451                 xml_node next_sibling() const;
00452                 xml_node previous_sibling() const;
00453                 
00454                 // Get parent node
00455                 xml_node parent() const;
00456 
00457                 // Get root of DOM tree this node belongs to
00458                 xml_node root() const;
00459 
00460                 // Get text object for the current node
00461                 xml_text text() const;
00462 
00463                 // Get child, attribute or next/previous sibling with the specified name
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                 // Get attribute, starting the search from a hint (and updating hint so that searching for a sequence of attributes is fast)
00470                 xml_attribute attribute(const char_t* name, xml_attribute& hint) const;
00471 
00472                 // Get child value of current node; that is, value of the first child node of type PCDATA/CDATA
00473                 const char_t* child_value() const;
00474 
00475                 // Get child value of child with specified name. Equivalent to child(name).child_value().
00476                 const char_t* child_value(const char_t* name) const;
00477 
00478                 // Set node name/value (returns false if node is empty, there is not enough memory, or node can not have name/value)
00479                 bool set_name(const char_t* rhs);
00480                 bool set_value(const char_t* rhs);
00481                 
00482                 // Add attribute with specified name. Returns added attribute, or empty attribute on errors.
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                 // Add a copy of the specified attribute. Returns added attribute, or empty attribute on errors.
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                 // Add child node with specified type. Returns added node, or empty node on errors.
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                 // Add child element with specified name. Returns added node, or empty node on errors.
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                 // Add a copy of the specified node as a child. Returns added node, or empty node on errors.
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                 // Move the specified node to become a child of this node. Returns moved node, or empty node on errors.
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                 // Remove specified attribute
00519                 bool remove_attribute(const xml_attribute& a);
00520                 bool remove_attribute(const char_t* name);
00521 
00522                 // Remove specified child
00523                 bool remove_child(const xml_node& n);
00524                 bool remove_child(const char_t* name);
00525 
00526                 // Parses buffer as an XML document fragment and appends all nodes as children of the current node.
00527                 // Copies/converts the buffer, so it may be deleted or changed after the function returns.
00528                 // Note: append_buffer allocates memory that has the lifetime of the owning document; removing the appended nodes does not immediately reclaim that memory.
00529                 xml_parse_result append_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
00530 
00531                 // Find attribute using predicate. Returns first attribute for which predicate returned true.
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                 // Find child node using predicate. Returns first child for which predicate returned true.
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                 // Find node from subtree using predicate. Returns first node from subtree (depth-first), for which predicate returned true.
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                 // Find child node by attribute name/value
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                 // Get the absolute node path from root as a text string.
00585                 string_t path(char_t delimiter = '/') const;
00586         #endif
00587 
00588                 // Search for a node by path consisting of node names and . or .. elements.
00589                 xml_node first_element_by_path(const char_t* path, char_t delimiter = '/') const;
00590 
00591                 // Recursively traverse subtree with xml_tree_walker
00592                 bool traverse(xml_tree_walker& walker);
00593         
00594         #ifndef PUGIXML_NO_XPATH
00595                 // Select single node by evaluating XPath query. Returns first node from the resulting node set.
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                 // Select node set by evaluating XPath query
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                 // (deprecated: use select_node instead) Select single node by evaluating XPath query.
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                 // Print subtree using a writer object
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                 // Print subtree to stream
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                 // Child nodes iterators
00619                 typedef xml_node_iterator iterator;
00620 
00621                 iterator begin() const;
00622                 iterator end() const;
00623 
00624                 // Attribute iterators
00625                 typedef xml_attribute_iterator attribute_iterator;
00626 
00627                 attribute_iterator attributes_begin() const;
00628                 attribute_iterator attributes_end() const;
00629 
00630                 // Range-based for support
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                 // Get node offset in parsed file/string (in char_t units) for debugging purposes
00636                 ptrdiff_t offset_debug() const;
00637 
00638                 // Get hash value (unique for handles to the same object)
00639                 size_t hash_value() const;
00640 
00641                 // Get internal pointer
00642                 xml_node_struct* internal_object() const;
00643         };
00644 
00645 #ifdef __BORLANDC__
00646         // Borland C++ workaround
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         // A helper for working with text inside PCDATA nodes
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                 // Default constructor. Constructs an empty object.
00667                 xml_text();
00668 
00669                 // Safe bool conversion operator
00670                 operator unspecified_bool_type() const;
00671 
00672                 // Borland C++ workaround
00673                 bool operator!() const;
00674 
00675                 // Check if text object is empty
00676                 bool empty() const;
00677 
00678                 // Get text, or "" if object is empty
00679                 const char_t* get() const;
00680 
00681                 // Get text, or the default value if object is empty
00682                 const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;
00683 
00684                 // Get text as a number, or the default value if conversion did not succeed or object is empty
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                 // Get text as bool (returns true if first character is in '1tTyY' set), or the default value if object is empty
00696                 bool as_bool(bool def = false) const;
00697 
00698                 // Set text (returns false if object is empty or there is not enough memory)
00699                 bool set(const char_t* rhs);
00700 
00701                 // Set text with type conversion (numbers are converted to strings, boolean is converted to "true"/"false")
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                 // Set text (equivalent to set without error checking)
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                 // Get the data node (node_pcdata or node_cdata) for this object
00727                 xml_node data() const;
00728         };
00729 
00730 #ifdef __BORLANDC__
00731         // Borland C++ workaround
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         // Child node iterator (a bidirectional iterator over a collection of xml_node)
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                 // Iterator traits
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                 // Default constructor
00759                 xml_node_iterator();
00760 
00761                 // Construct an iterator which points to the specified node
00762                 xml_node_iterator(const xml_node& node);
00763 
00764                 // Iterator operators
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         // Attribute iterator (a bidirectional iterator over a collection of xml_attribute)
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                 // Iterator traits
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                 // Default constructor
00801                 xml_attribute_iterator();
00802 
00803                 // Construct an iterator which points to the specified attribute
00804                 xml_attribute_iterator(const xml_attribute& attr, const xml_node& parent);
00805 
00806                 // Iterator operators
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         // Named node range helper
00821         class PUGIXML_CLASS xml_named_node_iterator
00822         {
00823                 friend class xml_node;
00824 
00825         public:
00826                 // Iterator traits
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                 // Default constructor
00837                 xml_named_node_iterator();
00838 
00839                 // Construct an iterator which points to the specified node
00840                 xml_named_node_iterator(const xml_node& node, const char_t* name);
00841 
00842                 // Iterator operators
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         // Abstract tree walker class (see xml_node::traverse)
00864         class PUGIXML_CLASS xml_tree_walker
00865         {
00866                 friend class xml_node;
00867 
00868         private:
00869                 int _depth;
00870         
00871         protected:
00872                 // Get current traversal depth
00873                 int depth() const;
00874         
00875         public:
00876                 xml_tree_walker();
00877                 virtual ~xml_tree_walker();
00878 
00879                 // Callback that is called when traversal begins
00880                 virtual bool begin(xml_node& node);
00881 
00882                 // Callback that is called for each node traversed
00883                 virtual bool for_each(xml_node& node) = 0;
00884 
00885                 // Callback that is called when traversal ends
00886                 virtual bool end(xml_node& node);
00887         };
00888 
00889         // Parsing status, returned as part of xml_parse_result object
00890         enum xml_parse_status
00891         {
00892                 status_ok = 0,                          // No error
00893 
00894                 status_file_not_found,          // File was not found during load_file()
00895                 status_io_error,                        // Error reading from file/stream
00896                 status_out_of_memory,           // Could not allocate memory
00897                 status_internal_error,          // Internal error occurred
00898 
00899                 status_unrecognized_tag,        // Parser could not determine tag type
00900 
00901                 status_bad_pi,                          // Parsing error occurred while parsing document declaration/processing instruction
00902                 status_bad_comment,                     // Parsing error occurred while parsing comment
00903                 status_bad_cdata,                       // Parsing error occurred while parsing CDATA section
00904                 status_bad_doctype,                     // Parsing error occurred while parsing document type declaration
00905                 status_bad_pcdata,                      // Parsing error occurred while parsing PCDATA section
00906                 status_bad_start_element,       // Parsing error occurred while parsing start element tag
00907                 status_bad_attribute,           // Parsing error occurred while parsing element attribute
00908                 status_bad_end_element,         // Parsing error occurred while parsing end element tag
00909                 status_end_element_mismatch,// There was a mismatch of start-end tags (closing tag had incorrect name, some tag was not closed or there was an excessive closing tag)
00910 
00911                 status_append_invalid_root,     // Unable to append nodes since root type is not node_element or node_document (exclusive to xml_node::append_buffer)
00912 
00913                 status_no_document_element      // Parsing resulted in a document without element nodes
00914         };
00915 
00916         // Parsing result
00917         struct PUGIXML_CLASS xml_parse_result
00918         {
00919                 // Parsing status (see xml_parse_status)
00920                 xml_parse_status status;
00921 
00922                 // Last parsed offset (in char_t units from start of input data)
00923                 ptrdiff_t offset;
00924 
00925                 // Source document encoding
00926                 xml_encoding encoding;
00927 
00928                 // Default constructor, initializes object to failed state
00929                 xml_parse_result();
00930 
00931                 // Cast to bool operator
00932                 operator bool() const;
00933 
00934                 // Get error description
00935                 const char* description() const;
00936         };
00937 
00938         // Document class (DOM tree root)
00939         class PUGIXML_CLASS xml_document: public xml_node
00940         {
00941         private:
00942                 char_t* _buffer;
00943 
00944                 char _memory[192];
00945                 
00946                 // Non-copyable semantics
00947                 xml_document(const xml_document&);
00948                 xml_document& operator=(const xml_document&);
00949 
00950                 void create();
00951                 void destroy();
00952 
00953         public:
00954                 // Default constructor, makes empty document
00955                 xml_document();
00956 
00957                 // Destructor, invalidates all node/attribute handles to this document
00958                 ~xml_document();
00959 
00960                 // Removes all nodes, leaving the empty document
00961                 void reset();
00962 
00963                 // Removes all nodes, then copies the entire contents of the specified document
00964                 void reset(const xml_document& proto);
00965 
00966         #ifndef PUGIXML_NO_STL
00967                 // Load document from stream.
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                 // (deprecated: use load_string instead) Load document from zero-terminated string. No encoding conversions are applied.
00973                 xml_parse_result load(const char_t* contents, unsigned int options = parse_default);
00974 
00975                 // Load document from zero-terminated string. No encoding conversions are applied.
00976                 xml_parse_result load_string(const char_t* contents, unsigned int options = parse_default);
00977 
00978                 // Load document from file
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                 // Load document from buffer. Copies/converts the buffer, so it may be deleted or changed after the function returns.
00983                 xml_parse_result load_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
00984 
00985                 // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data).
00986                 // You should ensure that buffer data will persist throughout the document's lifetime, and free the buffer memory manually once document is destroyed.
00987                 xml_parse_result load_buffer_inplace(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
00988 
00989                 // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data).
00990                 // You should allocate the buffer with pugixml allocation function; document will free the buffer when it is no longer needed (you can't use it anymore).
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                 // Save XML document to writer (semantics is slightly different from xml_node::print, see documentation for details).
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                 // Save XML document to stream (semantics is slightly different from xml_node::print, see documentation for details).
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                 // Save XML to file
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                 // Get document element
01007                 xml_node document_element() const;
01008         };
01009 
01010 #ifndef PUGIXML_NO_XPATH
01011         // XPath query return type
01012         enum xpath_value_type
01013         {
01014                 xpath_type_none,          // Unknown type (query failed to compile)
01015                 xpath_type_node_set,  // Node set (xpath_node_set)
01016                 xpath_type_number,        // Number
01017                 xpath_type_string,        // String
01018                 xpath_type_boolean        // Boolean
01019         };
01020 
01021         // XPath parsing result
01022         struct PUGIXML_CLASS xpath_parse_result
01023         {
01024                 // Error message (0 if no error)
01025                 const char* error;
01026 
01027                 // Last parsed offset (in char_t units from string start)
01028                 ptrdiff_t offset;
01029 
01030                 // Default constructor, initializes object to failed state
01031                 xpath_parse_result();
01032 
01033                 // Cast to bool operator
01034                 operator bool() const;
01035 
01036                 // Get error description
01037                 const char* description() const;
01038         };
01039 
01040         // A single XPath variable
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                 // Non-copyable semantics
01052                 xpath_variable(const xpath_variable&);
01053                 xpath_variable& operator=(const xpath_variable&);
01054                 
01055         public:
01056                 // Get variable name
01057                 const char_t* name() const;
01058 
01059                 // Get variable type
01060                 xpath_value_type type() const;
01061 
01062                 // Get variable value; no type conversion is performed, default value (false, NaN, empty string, empty node set) is returned on type mismatch error
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                 // Set variable value; no type conversion is performed, false is returned on type mismatch error
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         // A set of XPath variables
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                 // Default constructor/destructor
01091                 xpath_variable_set();
01092                 ~xpath_variable_set();
01093 
01094                 // Copy constructor/assignment operator
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                 // Move semantics support
01100                 xpath_variable_set(xpath_variable_set&& rhs);
01101                 xpath_variable_set& operator=(xpath_variable_set&& rhs);
01102         #endif
01103 
01104                 // Add a new variable or get the existing one, if the types match
01105                 xpath_variable* add(const char_t* name, xpath_value_type type);
01106 
01107                 // Set value of an existing variable; no type conversion is performed, false is returned if there is no such variable or if types mismatch
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                 // Get existing variable by name
01114                 xpath_variable* get(const char_t* name);
01115                 const xpath_variable* get(const char_t* name) const;
01116         };
01117 
01118         // A compiled XPath query object
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                 // Non-copyable semantics
01128                 xpath_query(const xpath_query&);
01129                 xpath_query& operator=(const xpath_query&);
01130 
01131         public:
01132                 // Construct a compiled object from XPath expression.
01133                 // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on compilation errors.
01134                 explicit xpath_query(const char_t* query, xpath_variable_set* variables = 0);
01135 
01136                 // Constructor
01137                 xpath_query();
01138 
01139                 // Destructor
01140                 ~xpath_query();
01141 
01142         #if __cplusplus >= 201103
01143                 // Move semantics support
01144                 xpath_query(xpath_query&& rhs);
01145                 xpath_query& operator=(xpath_query&& rhs);
01146         #endif
01147 
01148                 // Get query expression return type
01149                 xpath_value_type return_type() const;
01150                 
01151                 // Evaluate expression as boolean value in the specified context; performs type conversion if necessary.
01152                 // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
01153                 bool evaluate_boolean(const xpath_node& n) const;
01154                 
01155                 // Evaluate expression as double value in the specified context; performs type conversion if necessary.
01156                 // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
01157                 double evaluate_number(const xpath_node& n) const;
01158                 
01159         #ifndef PUGIXML_NO_STL
01160                 // Evaluate expression as string value in the specified context; performs type conversion if necessary.
01161                 // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
01162                 string_t evaluate_string(const xpath_node& n) const;
01163         #endif
01164                 
01165                 // Evaluate expression as string value in the specified context; performs type conversion if necessary.
01166                 // At most capacity characters are written to the destination buffer, full result size is returned (includes terminating zero).
01167                 // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.
01168                 // If PUGIXML_NO_EXCEPTIONS is defined, returns empty  set instead.
01169                 size_t evaluate_string(char_t* buffer, size_t capacity, const xpath_node& n) const;
01170 
01171                 // Evaluate expression as node set in the specified context.
01172                 // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on type mismatch and std::bad_alloc on out of memory errors.
01173                 // If PUGIXML_NO_EXCEPTIONS is defined, returns empty node set instead.
01174                 xpath_node_set evaluate_node_set(const xpath_node& n) const;
01175 
01176                 // Evaluate expression as node set in the specified context.
01177                 // Return first node in document order, or empty node if node set is empty.
01178                 // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on type mismatch and std::bad_alloc on out of memory errors.
01179                 // If PUGIXML_NO_EXCEPTIONS is defined, returns empty node instead.
01180                 xpath_node evaluate_node(const xpath_node& n) const;
01181 
01182                 // Get parsing result (used to get compilation errors in PUGIXML_NO_EXCEPTIONS mode)
01183                 const xpath_parse_result& result() const;
01184 
01185                 // Safe bool conversion operator
01186                 operator unspecified_bool_type() const;
01187 
01188                 // Borland C++ workaround
01189                 bool operator!() const;
01190         };
01191         
01192         #ifndef PUGIXML_NO_EXCEPTIONS
01193         // XPath exception class
01194         class PUGIXML_CLASS xpath_exception: public std::exception
01195         {
01196         private:
01197                 xpath_parse_result _result;
01198 
01199         public:
01200                 // Construct exception from parse result
01201                 explicit xpath_exception(const xpath_parse_result& result);
01202 
01203                 // Get error message
01204                 virtual const char* what() const throw();
01205 
01206                 // Get parse result
01207                 const xpath_parse_result& result() const;
01208         };
01209         #endif
01210         
01211         // XPath node class (either xml_node or xml_attribute)
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                 // Default constructor; constructs empty XPath node
01222                 xpath_node();
01223                 
01224                 // Construct XPath node from XML node/attribute
01225                 xpath_node(const xml_node& node);
01226                 xpath_node(const xml_attribute& attribute, const xml_node& parent);
01227 
01228                 // Get node/attribute, if any
01229                 xml_node node() const;
01230                 xml_attribute attribute() const;
01231                 
01232                 // Get parent of contained node/attribute
01233                 xml_node parent() const;
01234 
01235                 // Safe bool conversion operator
01236                 operator unspecified_bool_type() const;
01237                 
01238                 // Borland C++ workaround
01239                 bool operator!() const;
01240 
01241                 // Comparison operators
01242                 bool operator==(const xpath_node& n) const;
01243                 bool operator!=(const xpath_node& n) const;
01244         };
01245 
01246 #ifdef __BORLANDC__
01247         // Borland C++ workaround
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         // A fixed-size collection of XPath nodes
01253         class PUGIXML_CLASS xpath_node_set
01254         {
01255         public:
01256                 // Collection type
01257                 enum type_t
01258                 {
01259                         type_unsorted,                  // Not ordered
01260                         type_sorted,                    // Sorted by document order (ascending)
01261                         type_sorted_reverse             // Sorted by document order (descending)
01262                 };
01263                 
01264                 // Constant iterator type
01265                 typedef const xpath_node* const_iterator;
01266 
01267                 // We define non-constant iterator to be the same as constant iterator so that various generic algorithms (i.e. boost foreach) work
01268                 typedef const xpath_node* iterator;
01269         
01270                 // Default constructor. Constructs empty set.
01271                 xpath_node_set();
01272 
01273                 // Constructs a set from iterator range; data is not checked for duplicates and is not sorted according to provided type, so be careful
01274                 xpath_node_set(const_iterator begin, const_iterator end, type_t type = type_unsorted);
01275 
01276                 // Destructor
01277                 ~xpath_node_set();
01278                 
01279                 // Copy constructor/assignment operator
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                 // Move semantics support
01285                 xpath_node_set(xpath_node_set&& rhs);
01286                 xpath_node_set& operator=(xpath_node_set&& rhs);
01287         #endif
01288 
01289                 // Get collection type
01290                 type_t type() const;
01291                 
01292                 // Get collection size
01293                 size_t size() const;
01294 
01295                 // Indexing operator
01296                 const xpath_node& operator[](size_t index) const;
01297                 
01298                 // Collection iterators
01299                 const_iterator begin() const;
01300                 const_iterator end() const;
01301 
01302                 // Sort the collection in ascending/descending order by document order
01303                 void sort(bool reverse = false);
01304                 
01305                 // Get first node in the collection by document order
01306                 xpath_node first() const;
01307                 
01308                 // Check if collection is empty
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         // Convert wide string to UTF8
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         // Convert UTF8 to wide string
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         // Memory allocation function interface; returns pointer to allocated memory or NULL on failure
01335         typedef void* (*allocation_function)(size_t size);
01336         
01337         // Memory deallocation function interface
01338         typedef void (*deallocation_function)(void* ptr);
01339 
01340         // Override default memory management functions. All subsequent allocations/deallocations will be performed via supplied functions.
01341         void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate);
01342         
01343         // Get current memory management functions
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         // Workarounds for (non-standard) iterator category detection for older versions (MSVC7/IC8 and earlier)
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         // Workarounds for (non-standard) iterator category detection
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 // Make sure implementation is included in header-only mode
01371 // Use macro expansion in #include to work around QMake (QTBUG-11923)
01372 #if defined(PUGIXML_HEADER_ONLY) && !defined(PUGIXML_SOURCE)
01373 #       define PUGIXML_SOURCE "pugixml.cpp"
01374 #       include PUGIXML_SOURCE
01375 #endif
01376 


pugixml
Author(s): Jose Luis Sanchez-Lopez
autogenerated on Thu Jun 6 2019 21:00:00