--- /dev/null
+/**\r
+ * pugixml parser - version 1.4\r
+ * --------------------------------------------------------\r
+ * Report bugs and download new versions at http://pugixml.org/\r
+ *\r
+ * This library is distributed under the MIT License. See notice at the end\r
+ * of this file.\r
+ *\r
+ * This work is based on the pugxml parser, which is:\r
+ */\r
+\r
+#ifndef PUGIXML_VERSION\r
+// Define version macro; evaluates to major * 100 + minor so that it's safe to use in less-than comparisons\r
+# define PUGIXML_VERSION 140\r
+#endif\r
+\r
+// Include user configuration file (this can define various configuration macros)\r
+#include "pugiconfig.hpp"\r
+\r
+#ifndef HEADER_PUGIXML_HPP\r
+#define HEADER_PUGIXML_HPP\r
+\r
+// Include stddef.h for size_t and ptrdiff_t\r
+#include <stddef.h>\r
+\r
+// Include exception header for XPath\r
+#if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)\r
+# include <exception>\r
+#endif\r
+\r
+// Include STL headers\r
+#ifndef PUGIXML_NO_STL\r
+# include <iterator>\r
+# include <iosfwd>\r
+# include <string>\r
+#endif\r
+\r
+// Macro for deprecated features\r
+#ifndef PUGIXML_DEPRECATED\r
+# if defined(__GNUC__)\r
+# define PUGIXML_DEPRECATED __attribute__((deprecated))\r
+# elif defined(_MSC_VER) && _MSC_VER >= 1300\r
+# define PUGIXML_DEPRECATED __declspec(deprecated)\r
+# else\r
+# define PUGIXML_DEPRECATED\r
+# endif\r
+#endif\r
+\r
+// If no API is defined, assume default\r
+#ifndef PUGIXML_API\r
+# define PUGIXML_API\r
+#endif\r
+\r
+// If no API for classes is defined, assume default\r
+#ifndef PUGIXML_CLASS\r
+# define PUGIXML_CLASS PUGIXML_API\r
+#endif\r
+\r
+// If no API for functions is defined, assume default\r
+#ifndef PUGIXML_FUNCTION\r
+# define PUGIXML_FUNCTION PUGIXML_API\r
+#endif\r
+\r
+// If the platform is known to have long long support, enable long long functions\r
+#ifndef PUGIXML_HAS_LONG_LONG\r
+# if defined(__cplusplus) && __cplusplus >= 201103\r
+# define PUGIXML_HAS_LONG_LONG\r
+# elif defined(_MSC_VER) && _MSC_VER >= 1400\r
+# define PUGIXML_HAS_LONG_LONG\r
+# endif\r
+#endif\r
+\r
+// Character interface macros\r
+#ifdef PUGIXML_WCHAR_MODE\r
+# define PUGIXML_TEXT(t) L ## t\r
+# define PUGIXML_CHAR wchar_t\r
+#else\r
+# define PUGIXML_TEXT(t) t\r
+# define PUGIXML_CHAR char\r
+#endif\r
+\r
+namespace pugi\r
+{\r
+ // Character type used for all internal storage and operations; depends on PUGIXML_WCHAR_MODE\r
+ typedef PUGIXML_CHAR char_t;\r
+\r
+#ifndef PUGIXML_NO_STL\r
+ // String type used for operations that work with STL string; depends on PUGIXML_WCHAR_MODE\r
+ typedef std::basic_string<PUGIXML_CHAR, std::char_traits<PUGIXML_CHAR>, std::allocator<PUGIXML_CHAR> > string_t;\r
+#endif\r
+}\r
+\r
+// The PugiXML namespace\r
+namespace pugi\r
+{\r
+ // Tree node types\r
+ enum xml_node_type\r
+ {\r
+ node_null, // Empty (null) node handle\r
+ node_document, // A document tree's absolute root\r
+ node_element, // Element tag, i.e. '<node/>'\r
+ node_pcdata, // Plain character data, i.e. 'text'\r
+ node_cdata, // Character data, i.e. '<![CDATA[text]]>'\r
+ node_comment, // Comment tag, i.e. '<!-- text -->'\r
+ node_pi, // Processing instruction, i.e. '<?name?>'\r
+ node_declaration, // Document declaration, i.e. '<?xml version="1.0"?>'\r
+ node_doctype // Document type declaration, i.e. '<!DOCTYPE doc>'\r
+ };\r
+\r
+ // Parsing options\r
+\r
+ // Minimal parsing mode (equivalent to turning all other flags off).\r
+ // Only elements and PCDATA sections are added to the DOM tree, no text conversions are performed.\r
+ const unsigned int parse_minimal = 0x0000;\r
+\r
+ // This flag determines if processing instructions (node_pi) are added to the DOM tree. This flag is off by default.\r
+ const unsigned int parse_pi = 0x0001;\r
+\r
+ // This flag determines if comments (node_comment) are added to the DOM tree. This flag is off by default.\r
+ const unsigned int parse_comments = 0x0002;\r
+\r
+ // This flag determines if CDATA sections (node_cdata) are added to the DOM tree. This flag is on by default.\r
+ const unsigned int parse_cdata = 0x0004;\r
+\r
+ // This flag determines if plain character data (node_pcdata) that consist only of whitespace are added to the DOM tree.\r
+ // This flag is off by default; turning it on usually results in slower parsing and more memory consumption.\r
+ const unsigned int parse_ws_pcdata = 0x0008;\r
+\r
+ // This flag determines if character and entity references are expanded during parsing. This flag is on by default.\r
+ const unsigned int parse_escapes = 0x0010;\r
+\r
+ // This flag determines if EOL characters are normalized (converted to #xA) during parsing. This flag is on by default.\r
+ const unsigned int parse_eol = 0x0020;\r
+ \r
+ // This flag determines if attribute values are normalized using CDATA normalization rules during parsing. This flag is on by default.\r
+ const unsigned int parse_wconv_attribute = 0x0040;\r
+\r
+ // This flag determines if attribute values are normalized using NMTOKENS normalization rules during parsing. This flag is off by default.\r
+ const unsigned int parse_wnorm_attribute = 0x0080;\r
+ \r
+ // This flag determines if document declaration (node_declaration) is added to the DOM tree. This flag is off by default.\r
+ const unsigned int parse_declaration = 0x0100;\r
+\r
+ // This flag determines if document type declaration (node_doctype) is added to the DOM tree. This flag is off by default.\r
+ const unsigned int parse_doctype = 0x0200;\r
+\r
+ // This flag determines if plain character data (node_pcdata) that is the only child of the parent node and that consists only\r
+ // of whitespace is added to the DOM tree.\r
+ // This flag is off by default; turning it on may result in slower parsing and more memory consumption.\r
+ const unsigned int parse_ws_pcdata_single = 0x0400;\r
+\r
+ // This flag determines if leading and trailing whitespace is to be removed from plain character data. This flag is off by default.\r
+ const unsigned int parse_trim_pcdata = 0x0800;\r
+\r
+ // This flag determines if plain character data that does not have a parent node is added to the DOM tree, and if an empty document\r
+ // is a valid document. This flag is off by default.\r
+ const unsigned int parse_fragment = 0x1000;\r
+\r
+ // The default parsing mode.\r
+ // Elements, PCDATA and CDATA sections are added to the DOM tree, character/reference entities are expanded,\r
+ // End-of-Line characters are normalized, attribute values are normalized using CDATA normalization rules.\r
+ const unsigned int parse_default = parse_cdata | parse_escapes | parse_wconv_attribute | parse_eol;\r
+\r
+ // The full parsing mode.\r
+ // Nodes of all types are added to the DOM tree, character/reference entities are expanded,\r
+ // End-of-Line characters are normalized, attribute values are normalized using CDATA normalization rules.\r
+ const unsigned int parse_full = parse_default | parse_pi | parse_comments | parse_declaration | parse_doctype;\r
+\r
+ // These flags determine the encoding of input data for XML document\r
+ enum xml_encoding\r
+ {\r
+ encoding_auto, // Auto-detect input encoding using BOM or < / <? detection; use UTF8 if BOM is not found\r
+ encoding_utf8, // UTF8 encoding\r
+ encoding_utf16_le, // Little-endian UTF16\r
+ encoding_utf16_be, // Big-endian UTF16\r
+ encoding_utf16, // UTF16 with native endianness\r
+ encoding_utf32_le, // Little-endian UTF32\r
+ encoding_utf32_be, // Big-endian UTF32\r
+ encoding_utf32, // UTF32 with native endianness\r
+ encoding_wchar, // The same encoding wchar_t has (either UTF16 or UTF32)\r
+ encoding_latin1\r
+ };\r
+\r
+ // Formatting flags\r
+ \r
+ // Indent the nodes that are written to output stream with as many indentation strings as deep the node is in DOM tree. This flag is on by default.\r
+ const unsigned int format_indent = 0x01;\r
+ \r
+ // Write encoding-specific BOM to the output stream. This flag is off by default.\r
+ const unsigned int format_write_bom = 0x02;\r
+\r
+ // Use raw output mode (no indentation and no line breaks are written). This flag is off by default.\r
+ const unsigned int format_raw = 0x04;\r
+ \r
+ // Omit default XML declaration even if there is no declaration in the document. This flag is off by default.\r
+ const unsigned int format_no_declaration = 0x08;\r
+\r
+ // Don't escape attribute values and PCDATA contents. This flag is off by default.\r
+ const unsigned int format_no_escapes = 0x10;\r
+\r
+ // Open file using text mode in xml_document::save_file. This enables special character (i.e. new-line) conversions on some systems. This flag is off by default.\r
+ const unsigned int format_save_file_text = 0x20;\r
+\r
+ // The default set of formatting flags.\r
+ // Nodes are indented depending on their depth in DOM tree, a default declaration is output if document has none.\r
+ const unsigned int format_default = format_indent;\r
+ \r
+ // Forward declarations\r
+ struct xml_attribute_struct;\r
+ struct xml_node_struct;\r
+\r
+ class xml_node_iterator;\r
+ class xml_attribute_iterator;\r
+ class xml_named_node_iterator;\r
+\r
+ class xml_tree_walker;\r
+\r
+ struct xml_parse_result;\r
+\r
+ class xml_node;\r
+\r
+ class xml_text;\r
+ \r
+ #ifndef PUGIXML_NO_XPATH\r
+ class xpath_node;\r
+ class xpath_node_set;\r
+ class xpath_query;\r
+ class xpath_variable_set;\r
+ #endif\r
+\r
+ // Range-based for loop support\r
+ template <typename It> class xml_object_range\r
+ {\r
+ public:\r
+ typedef It const_iterator;\r
+ typedef It iterator;\r
+\r
+ xml_object_range(It b, It e): _begin(b), _end(e)\r
+ {\r
+ }\r
+\r
+ It begin() const { return _begin; }\r
+ It end() const { return _end; }\r
+\r
+ private:\r
+ It _begin, _end;\r
+ };\r
+\r
+ // Writer interface for node printing (see xml_node::print)\r
+ class PUGIXML_CLASS xml_writer\r
+ {\r
+ public:\r
+ virtual ~xml_writer() {}\r
+\r
+ // Write memory chunk into stream/file/whatever\r
+ virtual void write(const void* data, size_t size) = 0;\r
+ };\r
+\r
+ // xml_writer implementation for FILE*\r
+ class PUGIXML_CLASS xml_writer_file: public xml_writer\r
+ {\r
+ public:\r
+ // Construct writer from a FILE* object; void* is used to avoid header dependencies on stdio\r
+ xml_writer_file(void* file);\r
+\r
+ virtual void write(const void* data, size_t size);\r
+\r
+ private:\r
+ void* file;\r
+ };\r
+\r
+ #ifndef PUGIXML_NO_STL\r
+ // xml_writer implementation for streams\r
+ class PUGIXML_CLASS xml_writer_stream: public xml_writer\r
+ {\r
+ public:\r
+ // Construct writer from an output stream object\r
+ xml_writer_stream(std::basic_ostream<char, std::char_traits<char> >& stream);\r
+ xml_writer_stream(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream);\r
+\r
+ virtual void write(const void* data, size_t size);\r
+\r
+ private:\r
+ std::basic_ostream<char, std::char_traits<char> >* narrow_stream;\r
+ std::basic_ostream<wchar_t, std::char_traits<wchar_t> >* wide_stream;\r
+ };\r
+ #endif\r
+\r
+ // A light-weight handle for manipulating attributes in DOM tree\r
+ class PUGIXML_CLASS xml_attribute\r
+ {\r
+ friend class xml_attribute_iterator;\r
+ friend class xml_node;\r
+\r
+ private:\r
+ xml_attribute_struct* _attr;\r
+ \r
+ typedef void (*unspecified_bool_type)(xml_attribute***);\r
+\r
+ public:\r
+ // Default constructor. Constructs an empty attribute.\r
+ xml_attribute();\r
+ \r
+ // Constructs attribute from internal pointer\r
+ explicit xml_attribute(xml_attribute_struct* attr);\r
+\r
+ // Safe bool conversion operator\r
+ operator unspecified_bool_type() const;\r
+\r
+ // Borland C++ workaround\r
+ bool operator!() const;\r
+\r
+ // Comparison operators (compares wrapped attribute pointers)\r
+ bool operator==(const xml_attribute& r) const;\r
+ bool operator!=(const xml_attribute& r) const;\r
+ bool operator<(const xml_attribute& r) const;\r
+ bool operator>(const xml_attribute& r) const;\r
+ bool operator<=(const xml_attribute& r) const;\r
+ bool operator>=(const xml_attribute& r) const;\r
+\r
+ // Check if attribute is empty\r
+ bool empty() const;\r
+\r
+ // Get attribute name/value, or "" if attribute is empty\r
+ const char_t* name() const;\r
+ const char_t* value() const;\r
+\r
+ // Get attribute value, or the default value if attribute is empty\r
+ const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;\r
+\r
+ // Get attribute value as a number, or the default value if conversion did not succeed or attribute is empty\r
+ int as_int(int def = 0) const;\r
+ unsigned int as_uint(unsigned int def = 0) const;\r
+ double as_double(double def = 0) const;\r
+ float as_float(float def = 0) const;\r
+\r
+ #ifdef PUGIXML_HAS_LONG_LONG\r
+ long long as_llong(long long def = 0) const;\r
+ unsigned long long as_ullong(unsigned long long def = 0) const;\r
+ #endif\r
+\r
+ // Get attribute value as bool (returns true if first character is in '1tTyY' set), or the default value if attribute is empty\r
+ bool as_bool(bool def = false) const;\r
+\r
+ // Set attribute name/value (returns false if attribute is empty or there is not enough memory)\r
+ bool set_name(const char_t* rhs);\r
+ bool set_value(const char_t* rhs);\r
+\r
+ // Set attribute value with type conversion (numbers are converted to strings, boolean is converted to "true"/"false")\r
+ bool set_value(int rhs);\r
+ bool set_value(unsigned int rhs);\r
+ bool set_value(double rhs);\r
+ bool set_value(bool rhs);\r
+\r
+ #ifdef PUGIXML_HAS_LONG_LONG\r
+ bool set_value(long long rhs);\r
+ bool set_value(unsigned long long rhs);\r
+ #endif\r
+\r
+ // Set attribute value (equivalent to set_value without error checking)\r
+ xml_attribute& operator=(const char_t* rhs);\r
+ xml_attribute& operator=(int rhs);\r
+ xml_attribute& operator=(unsigned int rhs);\r
+ xml_attribute& operator=(double rhs);\r
+ xml_attribute& operator=(bool rhs);\r
+\r
+ #ifdef PUGIXML_HAS_LONG_LONG\r
+ xml_attribute& operator=(long long rhs);\r
+ xml_attribute& operator=(unsigned long long rhs);\r
+ #endif\r
+\r
+ // Get next/previous attribute in the attribute list of the parent node\r
+ xml_attribute next_attribute() const;\r
+ xml_attribute previous_attribute() const;\r
+\r
+ // Get hash value (unique for handles to the same object)\r
+ size_t hash_value() const;\r
+\r
+ // Get internal pointer\r
+ xml_attribute_struct* internal_object() const;\r
+ };\r
+\r
+#ifdef __BORLANDC__\r
+ // Borland C++ workaround\r
+ bool PUGIXML_FUNCTION operator&&(const xml_attribute& lhs, bool rhs);\r
+ bool PUGIXML_FUNCTION operator||(const xml_attribute& lhs, bool rhs);\r
+#endif\r
+\r
+ // A light-weight handle for manipulating nodes in DOM tree\r
+ class PUGIXML_CLASS xml_node\r
+ {\r
+ friend class xml_attribute_iterator;\r
+ friend class xml_node_iterator;\r
+ friend class xml_named_node_iterator;\r
+\r
+ protected:\r
+ xml_node_struct* _root;\r
+\r
+ typedef void (*unspecified_bool_type)(xml_node***);\r
+\r
+ public:\r
+ // Default constructor. Constructs an empty node.\r
+ xml_node();\r
+\r
+ // Constructs node from internal pointer\r
+ explicit xml_node(xml_node_struct* p);\r
+\r
+ // Safe bool conversion operator\r
+ operator unspecified_bool_type() const;\r
+\r
+ // Borland C++ workaround\r
+ bool operator!() const;\r
+ \r
+ // Comparison operators (compares wrapped node pointers)\r
+ bool operator==(const xml_node& r) const;\r
+ bool operator!=(const xml_node& r) const;\r
+ bool operator<(const xml_node& r) const;\r
+ bool operator>(const xml_node& r) const;\r
+ bool operator<=(const xml_node& r) const;\r
+ bool operator>=(const xml_node& r) const;\r
+\r
+ // Check if node is empty.\r
+ bool empty() const;\r
+\r
+ // Get node type\r
+ xml_node_type type() const;\r
+\r
+ // Get node name, or "" if node is empty or it has no name\r
+ const char_t* name() const;\r
+\r
+ // Get node value, or "" if node is empty or it has no value\r
+ // Note: For <node>text</node> node.value() does not return "text"! Use child_value() or text() methods to access text inside nodes.\r
+ const char_t* value() const;\r
+ \r
+ // Get attribute list\r
+ xml_attribute first_attribute() const;\r
+ xml_attribute last_attribute() const;\r
+\r
+ // Get children list\r
+ xml_node first_child() const;\r
+ xml_node last_child() const;\r
+\r
+ // Get next/previous sibling in the children list of the parent node\r
+ xml_node next_sibling() const;\r
+ xml_node previous_sibling() const;\r
+ \r
+ // Get parent node\r
+ xml_node parent() const;\r
+\r
+ // Get root of DOM tree this node belongs to\r
+ xml_node root() const;\r
+\r
+ // Get text object for the current node\r
+ xml_text text() const;\r
+\r
+ // Get child, attribute or next/previous sibling with the specified name\r
+ xml_node child(const char_t* name) const;\r
+ xml_attribute attribute(const char_t* name) const;\r
+ xml_node next_sibling(const char_t* name) const;\r
+ xml_node previous_sibling(const char_t* name) const;\r
+\r
+ // Get child value of current node; that is, value of the first child node of type PCDATA/CDATA\r
+ const char_t* child_value() const;\r
+\r
+ // Get child value of child with specified name. Equivalent to child(name).child_value().\r
+ const char_t* child_value(const char_t* name) const;\r
+\r
+ // Set node name/value (returns false if node is empty, there is not enough memory, or node can not have name/value)\r
+ bool set_name(const char_t* rhs);\r
+ bool set_value(const char_t* rhs);\r
+ \r
+ // Add attribute with specified name. Returns added attribute, or empty attribute on errors.\r
+ xml_attribute append_attribute(const char_t* name);\r
+ xml_attribute prepend_attribute(const char_t* name);\r
+ xml_attribute insert_attribute_after(const char_t* name, const xml_attribute& attr);\r
+ xml_attribute insert_attribute_before(const char_t* name, const xml_attribute& attr);\r
+\r
+ // Add a copy of the specified attribute. Returns added attribute, or empty attribute on errors.\r
+ xml_attribute append_copy(const xml_attribute& proto);\r
+ xml_attribute prepend_copy(const xml_attribute& proto);\r
+ xml_attribute insert_copy_after(const xml_attribute& proto, const xml_attribute& attr);\r
+ xml_attribute insert_copy_before(const xml_attribute& proto, const xml_attribute& attr);\r
+\r
+ // Add child node with specified type. Returns added node, or empty node on errors.\r
+ xml_node append_child(xml_node_type type = node_element);\r
+ xml_node prepend_child(xml_node_type type = node_element);\r
+ xml_node insert_child_after(xml_node_type type, const xml_node& node);\r
+ xml_node insert_child_before(xml_node_type type, const xml_node& node);\r
+\r
+ // Add child element with specified name. Returns added node, or empty node on errors.\r
+ xml_node append_child(const char_t* name);\r
+ xml_node prepend_child(const char_t* name);\r
+ xml_node insert_child_after(const char_t* name, const xml_node& node);\r
+ xml_node insert_child_before(const char_t* name, const xml_node& node);\r
+\r
+ // Add a copy of the specified node as a child. Returns added node, or empty node on errors.\r
+ xml_node append_copy(const xml_node& proto);\r
+ xml_node prepend_copy(const xml_node& proto);\r
+ xml_node insert_copy_after(const xml_node& proto, const xml_node& node);\r
+ xml_node insert_copy_before(const xml_node& proto, const xml_node& node);\r
+\r
+ // Remove specified attribute\r
+ bool remove_attribute(const xml_attribute& a);\r
+ bool remove_attribute(const char_t* name);\r
+\r
+ // Remove specified child\r
+ bool remove_child(const xml_node& n);\r
+ bool remove_child(const char_t* name);\r
+\r
+ // Parses buffer as an XML document fragment and appends all nodes as children of the current node.\r
+ // Copies/converts the buffer, so it may be deleted or changed after the function returns.\r
+ // Note: append_buffer allocates memory that has the lifetime of the owning document; removing the appended nodes does not immediately reclaim that memory.\r
+ xml_parse_result append_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);\r
+\r
+ // Find attribute using predicate. Returns first attribute for which predicate returned true.\r
+ template <typename Predicate> xml_attribute find_attribute(Predicate pred) const\r
+ {\r
+ if (!_root) return xml_attribute();\r
+ \r
+ for (xml_attribute attrib = first_attribute(); attrib; attrib = attrib.next_attribute())\r
+ if (pred(attrib))\r
+ return attrib;\r
+ \r
+ return xml_attribute();\r
+ }\r
+\r
+ // Find child node using predicate. Returns first child for which predicate returned true.\r
+ template <typename Predicate> xml_node find_child(Predicate pred) const\r
+ {\r
+ if (!_root) return xml_node();\r
+ \r
+ for (xml_node node = first_child(); node; node = node.next_sibling())\r
+ if (pred(node))\r
+ return node;\r
+ \r
+ return xml_node();\r
+ }\r
+\r
+ // Find node from subtree using predicate. Returns first node from subtree (depth-first), for which predicate returned true.\r
+ template <typename Predicate> xml_node find_node(Predicate pred) const\r
+ {\r
+ if (!_root) return xml_node();\r
+\r
+ xml_node cur = first_child();\r
+ \r
+ while (cur._root && cur._root != _root)\r
+ {\r
+ if (pred(cur)) return cur;\r
+\r
+ if (cur.first_child()) cur = cur.first_child();\r
+ else if (cur.next_sibling()) cur = cur.next_sibling();\r
+ else\r
+ {\r
+ while (!cur.next_sibling() && cur._root != _root) cur = cur.parent();\r
+\r
+ if (cur._root != _root) cur = cur.next_sibling();\r
+ }\r
+ }\r
+\r
+ return xml_node();\r
+ }\r
+\r
+ // Find child node by attribute name/value\r
+ xml_node find_child_by_attribute(const char_t* name, const char_t* attr_name, const char_t* attr_value) const;\r
+ xml_node find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const;\r
+\r
+ #ifndef PUGIXML_NO_STL\r
+ // Get the absolute node path from root as a text string.\r
+ string_t path(char_t delimiter = '/') const;\r
+ #endif\r
+\r
+ // Search for a node by path consisting of node names and . or .. elements.\r
+ xml_node first_element_by_path(const char_t* path, char_t delimiter = '/') const;\r
+\r
+ // Recursively traverse subtree with xml_tree_walker\r
+ bool traverse(xml_tree_walker& walker);\r
+ \r
+ #ifndef PUGIXML_NO_XPATH\r
+ // Select single node by evaluating XPath query. Returns first node from the resulting node set.\r
+ xpath_node select_single_node(const char_t* query, xpath_variable_set* variables = 0) const;\r
+ xpath_node select_single_node(const xpath_query& query) const;\r
+\r
+ // Select node set by evaluating XPath query\r
+ xpath_node_set select_nodes(const char_t* query, xpath_variable_set* variables = 0) const;\r
+ xpath_node_set select_nodes(const xpath_query& query) const;\r
+ #endif\r
+ \r
+ // Print subtree using a writer object\r
+ void print(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;\r
+\r
+ #ifndef PUGIXML_NO_STL\r
+ // Print subtree to stream\r
+ void print(std::basic_ostream<char, std::char_traits<char> >& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const;\r
+ void print(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& os, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, unsigned int depth = 0) const;\r
+ #endif\r
+\r
+ // Child nodes iterators\r
+ typedef xml_node_iterator iterator;\r
+\r
+ iterator begin() const;\r
+ iterator end() const;\r
+\r
+ // Attribute iterators\r
+ typedef xml_attribute_iterator attribute_iterator;\r
+\r
+ attribute_iterator attributes_begin() const;\r
+ attribute_iterator attributes_end() const;\r
+\r
+ // Range-based for support\r
+ xml_object_range<xml_node_iterator> children() const;\r
+ xml_object_range<xml_named_node_iterator> children(const char_t* name) const;\r
+ xml_object_range<xml_attribute_iterator> attributes() const;\r
+\r
+ // Get node offset in parsed file/string (in char_t units) for debugging purposes\r
+ ptrdiff_t offset_debug() const;\r
+\r
+ // Get hash value (unique for handles to the same object)\r
+ size_t hash_value() const;\r
+\r
+ // Get internal pointer\r
+ xml_node_struct* internal_object() const;\r
+ };\r
+\r
+#ifdef __BORLANDC__\r
+ // Borland C++ workaround\r
+ bool PUGIXML_FUNCTION operator&&(const xml_node& lhs, bool rhs);\r
+ bool PUGIXML_FUNCTION operator||(const xml_node& lhs, bool rhs);\r
+#endif\r
+\r
+ // A helper for working with text inside PCDATA nodes\r
+ class PUGIXML_CLASS xml_text\r
+ {\r
+ friend class xml_node;\r
+\r
+ xml_node_struct* _root;\r
+\r
+ typedef void (*unspecified_bool_type)(xml_text***);\r
+\r
+ explicit xml_text(xml_node_struct* root);\r
+\r
+ xml_node_struct* _data_new();\r
+ xml_node_struct* _data() const;\r
+\r
+ public:\r
+ // Default constructor. Constructs an empty object.\r
+ xml_text();\r
+\r
+ // Safe bool conversion operator\r
+ operator unspecified_bool_type() const;\r
+\r
+ // Borland C++ workaround\r
+ bool operator!() const;\r
+\r
+ // Check if text object is empty\r
+ bool empty() const;\r
+\r
+ // Get text, or "" if object is empty\r
+ const char_t* get() const;\r
+\r
+ // Get text, or the default value if object is empty\r
+ const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;\r
+\r
+ // Get text as a number, or the default value if conversion did not succeed or object is empty\r
+ int as_int(int def = 0) const;\r
+ unsigned int as_uint(unsigned int def = 0) const;\r
+ double as_double(double def = 0) const;\r
+ float as_float(float def = 0) const;\r
+\r
+ #ifdef PUGIXML_HAS_LONG_LONG\r
+ long long as_llong(long long def = 0) const;\r
+ unsigned long long as_ullong(unsigned long long def = 0) const;\r
+ #endif\r
+\r
+ // Get text as bool (returns true if first character is in '1tTyY' set), or the default value if object is empty\r
+ bool as_bool(bool def = false) const;\r
+\r
+ // Set text (returns false if object is empty or there is not enough memory)\r
+ bool set(const char_t* rhs);\r
+\r
+ // Set text with type conversion (numbers are converted to strings, boolean is converted to "true"/"false")\r
+ bool set(int rhs);\r
+ bool set(unsigned int rhs);\r
+ bool set(double rhs);\r
+ bool set(bool rhs);\r
+\r
+ #ifdef PUGIXML_HAS_LONG_LONG\r
+ bool set(long long rhs);\r
+ bool set(unsigned long long rhs);\r
+ #endif\r
+\r
+ // Set text (equivalent to set without error checking)\r
+ xml_text& operator=(const char_t* rhs);\r
+ xml_text& operator=(int rhs);\r
+ xml_text& operator=(unsigned int rhs);\r
+ xml_text& operator=(double rhs);\r
+ xml_text& operator=(bool rhs);\r
+\r
+ #ifdef PUGIXML_HAS_LONG_LONG\r
+ xml_text& operator=(long long rhs);\r
+ xml_text& operator=(unsigned long long rhs);\r
+ #endif\r
+\r
+ // Get the data node (node_pcdata or node_cdata) for this object\r
+ xml_node data() const;\r
+ };\r
+\r
+#ifdef __BORLANDC__\r
+ // Borland C++ workaround\r
+ bool PUGIXML_FUNCTION operator&&(const xml_text& lhs, bool rhs);\r
+ bool PUGIXML_FUNCTION operator||(const xml_text& lhs, bool rhs);\r
+#endif\r
+\r
+ // Child node iterator (a bidirectional iterator over a collection of xml_node)\r
+ class PUGIXML_CLASS xml_node_iterator\r
+ {\r
+ friend class xml_node;\r
+\r
+ private:\r
+ mutable xml_node _wrap;\r
+ xml_node _parent;\r
+\r
+ xml_node_iterator(xml_node_struct* ref, xml_node_struct* parent);\r
+\r
+ public:\r
+ // Iterator traits\r
+ typedef ptrdiff_t difference_type;\r
+ typedef xml_node value_type;\r
+ typedef xml_node* pointer;\r
+ typedef xml_node& reference;\r
+\r
+ #ifndef PUGIXML_NO_STL\r
+ typedef std::bidirectional_iterator_tag iterator_category;\r
+ #endif\r
+\r
+ // Default constructor\r
+ xml_node_iterator();\r
+\r
+ // Construct an iterator which points to the specified node\r
+ xml_node_iterator(const xml_node& node);\r
+\r
+ // Iterator operators\r
+ bool operator==(const xml_node_iterator& rhs) const;\r
+ bool operator!=(const xml_node_iterator& rhs) const;\r
+\r
+ xml_node& operator*() const;\r
+ xml_node* operator->() const;\r
+\r
+ const xml_node_iterator& operator++();\r
+ xml_node_iterator operator++(int);\r
+\r
+ const xml_node_iterator& operator--();\r
+ xml_node_iterator operator--(int);\r
+ };\r
+\r
+ // Attribute iterator (a bidirectional iterator over a collection of xml_attribute)\r
+ class PUGIXML_CLASS xml_attribute_iterator\r
+ {\r
+ friend class xml_node;\r
+\r
+ private:\r
+ mutable xml_attribute _wrap;\r
+ xml_node _parent;\r
+\r
+ xml_attribute_iterator(xml_attribute_struct* ref, xml_node_struct* parent);\r
+\r
+ public:\r
+ // Iterator traits\r
+ typedef ptrdiff_t difference_type;\r
+ typedef xml_attribute value_type;\r
+ typedef xml_attribute* pointer;\r
+ typedef xml_attribute& reference;\r
+\r
+ #ifndef PUGIXML_NO_STL\r
+ typedef std::bidirectional_iterator_tag iterator_category;\r
+ #endif\r
+\r
+ // Default constructor\r
+ xml_attribute_iterator();\r
+\r
+ // Construct an iterator which points to the specified attribute\r
+ xml_attribute_iterator(const xml_attribute& attr, const xml_node& parent);\r
+\r
+ // Iterator operators\r
+ bool operator==(const xml_attribute_iterator& rhs) const;\r
+ bool operator!=(const xml_attribute_iterator& rhs) const;\r
+\r
+ xml_attribute& operator*() const;\r
+ xml_attribute* operator->() const;\r
+\r
+ const xml_attribute_iterator& operator++();\r
+ xml_attribute_iterator operator++(int);\r
+\r
+ const xml_attribute_iterator& operator--();\r
+ xml_attribute_iterator operator--(int);\r
+ };\r
+\r
+ // Named node range helper\r
+ class PUGIXML_CLASS xml_named_node_iterator\r
+ {\r
+ friend class xml_node;\r
+\r
+ public:\r
+ // Iterator traits\r
+ typedef ptrdiff_t difference_type;\r
+ typedef xml_node value_type;\r
+ typedef xml_node* pointer;\r
+ typedef xml_node& reference;\r
+\r
+ #ifndef PUGIXML_NO_STL\r
+ typedef std::bidirectional_iterator_tag iterator_category;\r
+ #endif\r
+\r
+ // Default constructor\r
+ xml_named_node_iterator();\r
+\r
+ // Construct an iterator which points to the specified node\r
+ xml_named_node_iterator(const xml_node& node, const char_t* name);\r
+\r
+ // Iterator operators\r
+ bool operator==(const xml_named_node_iterator& rhs) const;\r
+ bool operator!=(const xml_named_node_iterator& rhs) const;\r
+\r
+ xml_node& operator*() const;\r
+ xml_node* operator->() const;\r
+\r
+ const xml_named_node_iterator& operator++();\r
+ xml_named_node_iterator operator++(int);\r
+\r
+ const xml_named_node_iterator& operator--();\r
+ xml_named_node_iterator operator--(int);\r
+\r
+ private:\r
+ mutable xml_node _wrap;\r
+ xml_node _parent;\r
+ const char_t* _name;\r
+\r
+ xml_named_node_iterator(xml_node_struct* ref, xml_node_struct* parent, const char_t* name);\r
+ };\r
+\r
+ // Abstract tree walker class (see xml_node::traverse)\r
+ class PUGIXML_CLASS xml_tree_walker\r
+ {\r
+ friend class xml_node;\r
+\r
+ private:\r
+ int _depth;\r
+ \r
+ protected:\r
+ // Get current traversal depth\r
+ int depth() const;\r
+ \r
+ public:\r
+ xml_tree_walker();\r
+ virtual ~xml_tree_walker();\r
+\r
+ // Callback that is called when traversal begins\r
+ virtual bool begin(xml_node& node);\r
+\r
+ // Callback that is called for each node traversed\r
+ virtual bool for_each(xml_node& node) = 0;\r
+\r
+ // Callback that is called when traversal ends\r
+ virtual bool end(xml_node& node);\r
+ };\r
+\r
+ // Parsing status, returned as part of xml_parse_result object\r
+ enum xml_parse_status\r
+ {\r
+ status_ok = 0, // No error\r
+\r
+ status_file_not_found, // File was not found during load_file()\r
+ status_io_error, // Error reading from file/stream\r
+ status_out_of_memory, // Could not allocate memory\r
+ status_internal_error, // Internal error occurred\r
+\r
+ status_unrecognized_tag, // Parser could not determine tag type\r
+\r
+ status_bad_pi, // Parsing error occurred while parsing document declaration/processing instruction\r
+ status_bad_comment, // Parsing error occurred while parsing comment\r
+ status_bad_cdata, // Parsing error occurred while parsing CDATA section\r
+ status_bad_doctype, // Parsing error occurred while parsing document type declaration\r
+ status_bad_pcdata, // Parsing error occurred while parsing PCDATA section\r
+ status_bad_start_element, // Parsing error occurred while parsing start element tag\r
+ status_bad_attribute, // Parsing error occurred while parsing element attribute\r
+ status_bad_end_element, // Parsing error occurred while parsing end element tag\r
+ status_end_element_mismatch,// There was a mismatch of start-end tags (closing tag had incorrect name, some tag was not closed or there was an excessive closing tag)\r
+\r
+ status_append_invalid_root, // Unable to append nodes since root type is not node_element or node_document (exclusive to xml_node::append_buffer)\r
+\r
+ status_no_document_element // Parsing resulted in a document without element nodes\r
+ };\r
+\r
+ // Parsing result\r
+ struct PUGIXML_CLASS xml_parse_result\r
+ {\r
+ // Parsing status (see xml_parse_status)\r
+ xml_parse_status status;\r
+\r
+ // Last parsed offset (in char_t units from start of input data)\r
+ ptrdiff_t offset;\r
+\r
+ // Source document encoding\r
+ xml_encoding encoding;\r
+\r
+ // Default constructor, initializes object to failed state\r
+ xml_parse_result();\r
+\r
+ // Cast to bool operator\r
+ operator bool() const;\r
+\r
+ // Get error description\r
+ const char* description() const;\r
+ };\r
+\r
+ // Document class (DOM tree root)\r
+ class PUGIXML_CLASS xml_document: public xml_node\r
+ {\r
+ private:\r
+ char_t* _buffer;\r
+\r
+ char _memory[192];\r
+ \r
+ // Non-copyable semantics\r
+ xml_document(const xml_document&);\r
+ const xml_document& operator=(const xml_document&);\r
+\r
+ void create();\r
+ void destroy();\r
+\r
+ public:\r
+ // Default constructor, makes empty document\r
+ xml_document();\r
+\r
+ // Destructor, invalidates all node/attribute handles to this document\r
+ ~xml_document();\r
+\r
+ // Removes all nodes, leaving the empty document\r
+ void reset();\r
+\r
+ // Removes all nodes, then copies the entire contents of the specified document\r
+ void reset(const xml_document& proto);\r
+\r
+ #ifndef PUGIXML_NO_STL\r
+ // Load document from stream.\r
+ xml_parse_result load(std::basic_istream<char, std::char_traits<char> >& stream, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);\r
+ xml_parse_result load(std::basic_istream<wchar_t, std::char_traits<wchar_t> >& stream, unsigned int options = parse_default);\r
+ #endif\r
+\r
+ // Load document from zero-terminated string. No encoding conversions are applied.\r
+ xml_parse_result load(const char_t* contents, unsigned int options = parse_default);\r
+\r
+ // Load document from file\r
+ xml_parse_result load_file(const char* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);\r
+ xml_parse_result load_file(const wchar_t* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);\r
+\r
+ // Load document from buffer. Copies/converts the buffer, so it may be deleted or changed after the function returns.\r
+ xml_parse_result load_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);\r
+\r
+ // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data).\r
+ // You should ensure that buffer data will persist throughout the document's lifetime, and free the buffer memory manually once document is destroyed.\r
+ xml_parse_result load_buffer_inplace(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);\r
+\r
+ // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data).\r
+ // You should allocate the buffer with pugixml allocation function; document will free the buffer when it is no longer needed (you can't use it anymore).\r
+ xml_parse_result load_buffer_inplace_own(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);\r
+\r
+ // Save XML document to writer (semantics is slightly different from xml_node::print, see documentation for details).\r
+ void save(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;\r
+\r
+ #ifndef PUGIXML_NO_STL\r
+ // Save XML document to stream (semantics is slightly different from xml_node::print, see documentation for details).\r
+ void save(std::basic_ostream<char, std::char_traits<char> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;\r
+ void save(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default) const;\r
+ #endif\r
+\r
+ // Save XML to file\r
+ bool save_file(const char* path, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;\r
+ bool save_file(const wchar_t* path, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;\r
+\r
+ // Get document element\r
+ xml_node document_element() const;\r
+ };\r
+\r
+#ifndef PUGIXML_NO_XPATH\r
+ // XPath query return type\r
+ enum xpath_value_type\r
+ {\r
+ xpath_type_none, // Unknown type (query failed to compile)\r
+ xpath_type_node_set, // Node set (xpath_node_set)\r
+ xpath_type_number, // Number\r
+ xpath_type_string, // String\r
+ xpath_type_boolean // Boolean\r
+ };\r
+\r
+ // XPath parsing result\r
+ struct PUGIXML_CLASS xpath_parse_result\r
+ {\r
+ // Error message (0 if no error)\r
+ const char* error;\r
+\r
+ // Last parsed offset (in char_t units from string start)\r
+ ptrdiff_t offset;\r
+\r
+ // Default constructor, initializes object to failed state\r
+ xpath_parse_result();\r
+\r
+ // Cast to bool operator\r
+ operator bool() const;\r
+\r
+ // Get error description\r
+ const char* description() const;\r
+ };\r
+\r
+ // A single XPath variable\r
+ class PUGIXML_CLASS xpath_variable\r
+ {\r
+ friend class xpath_variable_set;\r
+\r
+ protected:\r
+ xpath_value_type _type;\r
+ xpath_variable* _next;\r
+\r
+ xpath_variable();\r
+\r
+ // Non-copyable semantics\r
+ xpath_variable(const xpath_variable&);\r
+ xpath_variable& operator=(const xpath_variable&);\r
+ \r
+ public:\r
+ // Get variable name\r
+ const char_t* name() const;\r
+\r
+ // Get variable type\r
+ xpath_value_type type() const;\r
+\r
+ // Get variable value; no type conversion is performed, default value (false, NaN, empty string, empty node set) is returned on type mismatch error\r
+ bool get_boolean() const;\r
+ double get_number() const;\r
+ const char_t* get_string() const;\r
+ const xpath_node_set& get_node_set() const;\r
+\r
+ // Set variable value; no type conversion is performed, false is returned on type mismatch error\r
+ bool set(bool value);\r
+ bool set(double value);\r
+ bool set(const char_t* value);\r
+ bool set(const xpath_node_set& value);\r
+ };\r
+\r
+ // A set of XPath variables\r
+ class PUGIXML_CLASS xpath_variable_set\r
+ {\r
+ private:\r
+ xpath_variable* _data[64];\r
+\r
+ // Non-copyable semantics\r
+ xpath_variable_set(const xpath_variable_set&);\r
+ xpath_variable_set& operator=(const xpath_variable_set&);\r
+\r
+ xpath_variable* find(const char_t* name) const;\r
+\r
+ public:\r
+ // Default constructor/destructor\r
+ xpath_variable_set();\r
+ ~xpath_variable_set();\r
+\r
+ // Add a new variable or get the existing one, if the types match\r
+ xpath_variable* add(const char_t* name, xpath_value_type type);\r
+\r
+ // Set value of an existing variable; no type conversion is performed, false is returned if there is no such variable or if types mismatch\r
+ bool set(const char_t* name, bool value);\r
+ bool set(const char_t* name, double value);\r
+ bool set(const char_t* name, const char_t* value);\r
+ bool set(const char_t* name, const xpath_node_set& value);\r
+\r
+ // Get existing variable by name\r
+ xpath_variable* get(const char_t* name);\r
+ const xpath_variable* get(const char_t* name) const;\r
+ };\r
+\r
+ // A compiled XPath query object\r
+ class PUGIXML_CLASS xpath_query\r
+ {\r
+ private:\r
+ void* _impl;\r
+ xpath_parse_result _result;\r
+\r
+ typedef void (*unspecified_bool_type)(xpath_query***);\r
+\r
+ // Non-copyable semantics\r
+ xpath_query(const xpath_query&);\r
+ xpath_query& operator=(const xpath_query&);\r
+\r
+ public:\r
+ // Construct a compiled object from XPath expression.\r
+ // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on compilation errors.\r
+ explicit xpath_query(const char_t* query, xpath_variable_set* variables = 0);\r
+\r
+ // Destructor\r
+ ~xpath_query();\r
+\r
+ // Get query expression return type\r
+ xpath_value_type return_type() const;\r
+ \r
+ // Evaluate expression as boolean value in the specified context; performs type conversion if necessary.\r
+ // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.\r
+ bool evaluate_boolean(const xpath_node& n) const;\r
+ \r
+ // Evaluate expression as double value in the specified context; performs type conversion if necessary.\r
+ // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.\r
+ double evaluate_number(const xpath_node& n) const;\r
+ \r
+ #ifndef PUGIXML_NO_STL\r
+ // Evaluate expression as string value in the specified context; performs type conversion if necessary.\r
+ // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.\r
+ string_t evaluate_string(const xpath_node& n) const;\r
+ #endif\r
+ \r
+ // Evaluate expression as string value in the specified context; performs type conversion if necessary.\r
+ // At most capacity characters are written to the destination buffer, full result size is returned (includes terminating zero).\r
+ // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors.\r
+ // If PUGIXML_NO_EXCEPTIONS is defined, returns empty set instead.\r
+ size_t evaluate_string(char_t* buffer, size_t capacity, const xpath_node& n) const;\r
+\r
+ // Evaluate expression as node set in the specified context.\r
+ // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception on type mismatch and std::bad_alloc on out of memory errors.\r
+ // If PUGIXML_NO_EXCEPTIONS is defined, returns empty node set instead.\r
+ xpath_node_set evaluate_node_set(const xpath_node& n) const;\r
+\r
+ // Get parsing result (used to get compilation errors in PUGIXML_NO_EXCEPTIONS mode)\r
+ const xpath_parse_result& result() const;\r
+\r
+ // Safe bool conversion operator\r
+ operator unspecified_bool_type() const;\r
+\r
+ // Borland C++ workaround\r
+ bool operator!() const;\r
+ };\r
+ \r
+ #ifndef PUGIXML_NO_EXCEPTIONS\r
+ // XPath exception class\r
+ class PUGIXML_CLASS xpath_exception: public std::exception\r
+ {\r
+ private:\r
+ xpath_parse_result _result;\r
+\r
+ public:\r
+ // Construct exception from parse result\r
+ explicit xpath_exception(const xpath_parse_result& result);\r
+\r
+ // Get error message\r
+ virtual const char* what() const throw();\r
+\r
+ // Get parse result\r
+ const xpath_parse_result& result() const;\r
+ };\r
+ #endif\r
+ \r
+ // XPath node class (either xml_node or xml_attribute)\r
+ class PUGIXML_CLASS xpath_node\r
+ {\r
+ private:\r
+ xml_node _node;\r
+ xml_attribute _attribute;\r
+ \r
+ typedef void (*unspecified_bool_type)(xpath_node***);\r
+\r
+ public:\r
+ // Default constructor; constructs empty XPath node\r
+ xpath_node();\r
+ \r
+ // Construct XPath node from XML node/attribute\r
+ xpath_node(const xml_node& node);\r
+ xpath_node(const xml_attribute& attribute, const xml_node& parent);\r
+\r
+ // Get node/attribute, if any\r
+ xml_node node() const;\r
+ xml_attribute attribute() const;\r
+ \r
+ // Get parent of contained node/attribute\r
+ xml_node parent() const;\r
+\r
+ // Safe bool conversion operator\r
+ operator unspecified_bool_type() const;\r
+ \r
+ // Borland C++ workaround\r
+ bool operator!() const;\r
+\r
+ // Comparison operators\r
+ bool operator==(const xpath_node& n) const;\r
+ bool operator!=(const xpath_node& n) const;\r
+ };\r
+\r
+#ifdef __BORLANDC__\r
+ // Borland C++ workaround\r
+ bool PUGIXML_FUNCTION operator&&(const xpath_node& lhs, bool rhs);\r
+ bool PUGIXML_FUNCTION operator||(const xpath_node& lhs, bool rhs);\r
+#endif\r
+\r
+ // A fixed-size collection of XPath nodes\r
+ class PUGIXML_CLASS xpath_node_set\r
+ {\r
+ public:\r
+ // Collection type\r
+ enum type_t\r
+ {\r
+ type_unsorted, // Not ordered\r
+ type_sorted, // Sorted by document order (ascending)\r
+ type_sorted_reverse // Sorted by document order (descending)\r
+ };\r
+ \r
+ // Constant iterator type\r
+ typedef const xpath_node* const_iterator;\r
+ \r
+ // Default constructor. Constructs empty set.\r
+ xpath_node_set();\r
+\r
+ // Constructs a set from iterator range; data is not checked for duplicates and is not sorted according to provided type, so be careful\r
+ xpath_node_set(const_iterator begin, const_iterator end, type_t type = type_unsorted);\r
+\r
+ // Destructor\r
+ ~xpath_node_set();\r
+ \r
+ // Copy constructor/assignment operator\r
+ xpath_node_set(const xpath_node_set& ns);\r
+ xpath_node_set& operator=(const xpath_node_set& ns);\r
+\r
+ // Get collection type\r
+ type_t type() const;\r
+ \r
+ // Get collection size\r
+ size_t size() const;\r
+\r
+ // Indexing operator\r
+ const xpath_node& operator[](size_t index) const;\r
+ \r
+ // Collection iterators\r
+ const_iterator begin() const;\r
+ const_iterator end() const;\r
+\r
+ // Sort the collection in ascending/descending order by document order\r
+ void sort(bool reverse = false);\r
+ \r
+ // Get first node in the collection by document order\r
+ xpath_node first() const;\r
+ \r
+ // Check if collection is empty\r
+ bool empty() const;\r
+ \r
+ private:\r
+ type_t _type;\r
+ \r
+ xpath_node _storage;\r
+ \r
+ xpath_node* _begin;\r
+ xpath_node* _end;\r
+\r
+ void _assign(const_iterator begin, const_iterator end);\r
+ };\r
+#endif\r
+\r
+#ifndef PUGIXML_NO_STL\r
+ // Convert wide string to UTF8\r
+ std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const wchar_t* str);\r
+ std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >& str);\r
+ \r
+ // Convert UTF8 to wide string\r
+ std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const char* str);\r
+ std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const std::basic_string<char, std::char_traits<char>, std::allocator<char> >& str);\r
+#endif\r
+\r
+ // Memory allocation function interface; returns pointer to allocated memory or NULL on failure\r
+ typedef void* (*allocation_function)(size_t size);\r
+ \r
+ // Memory deallocation function interface\r
+ typedef void (*deallocation_function)(void* ptr);\r
+\r
+ // Override default memory management functions. All subsequent allocations/deallocations will be performed via supplied functions.\r
+ void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate);\r
+ \r
+ // Get current memory management functions\r
+ allocation_function PUGIXML_FUNCTION get_memory_allocation_function();\r
+ deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function();\r
+}\r
+\r
+#if !defined(PUGIXML_NO_STL) && (defined(_MSC_VER) || defined(__ICC))\r
+namespace std\r
+{\r
+ // Workarounds for (non-standard) iterator category detection for older versions (MSVC7/IC8 and earlier)\r
+ std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_node_iterator&);\r
+ std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_attribute_iterator&);\r
+ std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_named_node_iterator&);\r
+}\r
+#endif\r
+\r
+#if !defined(PUGIXML_NO_STL) && defined(__SUNPRO_CC)\r
+namespace std\r
+{\r
+ // Workarounds for (non-standard) iterator category detection\r
+ std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_node_iterator&);\r
+ std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_attribute_iterator&);\r
+ std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_named_node_iterator&);\r
+}\r
+#endif\r
+\r
+#endif\r
+\r
+/**\r
+ * Copyright (c) 2006-2014 Arseny Kapoulkine\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person\r
+ * obtaining a copy of this software and associated documentation\r
+ * files (the "Software"), to deal in the Software without\r
+ * restriction, including without limitation the rights to use,\r
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ * copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following\r
+ * conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be\r
+ * included in all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\r
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\r
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\r
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r
+ * OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r