pugiconfig.hpp   pugiconfig.hpp 
/** /**
* pugixml parser - version 1.0 * pugixml parser - version 1.2
* -------------------------------------------------------- * --------------------------------------------------------
* Copyright (C) 2006-2010, by Arseny Kapoulkine (arseny.kapoulkine@gmail.c om) * Copyright (C) 2006-2012, by Arseny Kapoulkine (arseny.kapoulkine@gmail.c om)
* Report bugs and download new versions at http://pugixml.org/ * Report bugs and download new versions at http://pugixml.org/
* *
* This library is distributed under the MIT License. See notice at the end * This library is distributed under the MIT License. See notice at the end
* of this file. * of this file.
* *
* This work is based on the pugxml parser, which is: * This work is based on the pugxml parser, which is:
* Copyright (C) 2003, by Kristen Wegner (kristen@tima.net) * Copyright (C) 2003, by Kristen Wegner (kristen@tima.net)
*/ */
#ifndef HEADER_PUGICONFIG_HPP #ifndef HEADER_PUGICONFIG_HPP
#define HEADER_PUGICONFIG_HPP #define HEADER_PUGICONFIG_HPP
// Uncomment this to enable wchar_t mode // Uncomment this to enable wchar_t mode
// #define PUGIXML_WCHAR_MODE // #define PUGIXML_WCHAR_MODE
// Uncomment this to disable XPath // Uncomment this to disable XPath
// #define PUGIXML_NO_XPATH // #define PUGIXML_NO_XPATH
// Uncomment this to disable STL // Uncomment this to disable STL
// Note: you can't use XPath with PUGIXML_NO_STL
// #define PUGIXML_NO_STL // #define PUGIXML_NO_STL
// Uncomment this to disable exceptions // Uncomment this to disable exceptions
// Note: you can't use XPath with PUGIXML_NO_EXCEPTIONS
// #define PUGIXML_NO_EXCEPTIONS // #define PUGIXML_NO_EXCEPTIONS
// Set this to control attributes for public classes/functions, i.e.: // Set this to control attributes for public classes/functions, i.e.:
// #define PUGIXML_API __declspec(dllexport) // to export all public symbol s from DLL // #define PUGIXML_API __declspec(dllexport) // to export all public symbol s from DLL
// #define PUGIXML_CLASS __declspec(dllimport) // to import all classes fro m DLL // #define PUGIXML_CLASS __declspec(dllimport) // to import all classes fro m DLL
// #define PUGIXML_FUNCTION __fastcall // to set calling conventions to all public functions to fastcall // #define PUGIXML_FUNCTION __fastcall // to set calling conventions to all public functions to fastcall
// In absence of PUGIXML_CLASS/PUGIXML_FUNCTION definitions PUGIXML_API is used instead // In absence of PUGIXML_CLASS/PUGIXML_FUNCTION definitions PUGIXML_API is used instead
// Uncomment this to switch to header-only version
// #define PUGIXML_HEADER_ONLY
// #include "pugixml.cpp"
// Tune these constants to adjust memory-related behavior
// #define PUGIXML_MEMORY_PAGE_SIZE 32768
// #define PUGIXML_MEMORY_OUTPUT_STACK 10240
// #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096
#endif #endif
/** /**
* Copyright (c) 2006-2010 Arseny Kapoulkine * Copyright (c) 2006-2012 Arseny Kapoulkine
* *
* Permission is hereby granted, free of charge, to any person * Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation * obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without * files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, * restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell * copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the * copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following * Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
 End of changes. 6 change blocks. 
5 lines changed or deleted 12 lines changed or added


 pugixml.hpp   pugixml.hpp 
/** /**
* pugixml parser - version 1.0 * pugixml parser - version 1.2
* -------------------------------------------------------- * --------------------------------------------------------
* Copyright (C) 2006-2010, by Arseny Kapoulkine (arseny.kapoulkine@gmail.c om) * Copyright (C) 2006-2012, by Arseny Kapoulkine (arseny.kapoulkine@gmail.c om)
* Report bugs and download new versions at http://pugixml.org/ * Report bugs and download new versions at http://pugixml.org/
* *
* This library is distributed under the MIT License. See notice at the end * This library is distributed under the MIT License. See notice at the end
* of this file. * of this file.
* *
* This work is based on the pugxml parser, which is: * This work is based on the pugxml parser, which is:
* Copyright (C) 2003, by Kristen Wegner (kristen@tima.net) * Copyright (C) 2003, by Kristen Wegner (kristen@tima.net)
*/ */
#ifndef HEADER_PUGIXML_HPP #ifndef PUGIXML_VERSION
#define HEADER_PUGIXML_HPP // Define version macro; evaluates to major * 100 + minor so that it's safe
to use in less-than comparisons
# define PUGIXML_VERSION 120
#endif
// Include user configuration file (this can define various configuration m acros)
#include "pugiconfig.hpp" #include "pugiconfig.hpp"
#ifndef PUGIXML_NO_STL #ifndef HEADER_PUGIXML_HPP
namespace std #define HEADER_PUGIXML_HPP
{
struct bidirectional_iterator_tag;
#ifdef __SUNPRO_CC // Include stddef.h for size_t and ptrdiff_t
// Sun C++ compiler has a bug which forces template argument names i #include <stddef.h>
n forward declarations to be the same as in actual definitions
template <class _T> class allocator;
template <class _charT> struct char_traits;
template <class _charT, class _Traits> class basic_istream;
template <class _charT, class _Traits> class basic_ostream;
template <class _charT, class _Traits, class _Allocator> class basic
_string;
#else
// Borland C++ compiler has a bug which forces template argument nam
es in forward declarations to be the same as in actual definitions
template <class _Ty> class allocator;
template <class _Ty> struct char_traits;
template <class _Elem, class _Traits> class basic_istream;
template <class _Elem, class _Traits> class basic_ostream;
template <class _Elem, class _Traits, class _Ax> class basic_string;
#endif
// Digital Mars compiler has a bug which requires a forward declarat // Include exception header for XPath
ion for explicit instantiation (otherwise type selection is messed up later #if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
, producing link errors) # include <exception>
// Also note that we have to declare char_traits as a class here, si
nce it's defined that way
#ifdef __DMC__
template <> class char_traits<char>;
#endif #endif
}
// Include STL headers
#ifndef PUGIXML_NO_STL
# include <iterator>
# include <iosfwd>
# include <string>
#endif #endif
// Macro for deprecated features // Macro for deprecated features
#ifndef PUGIXML_DEPRECATED #ifndef PUGIXML_DEPRECATED
# if defined(__GNUC__) # if defined(__GNUC__)
# define PUGIXML_DEPRECATED __attribute__((deprecated)) # define PUGIXML_DEPRECATED __attribute__((deprecated))
# elif defined(_MSC_VER) && _MSC_VER >= 1300 # elif defined(_MSC_VER) && _MSC_VER >= 1300
# define PUGIXML_DEPRECATED __declspec(deprecated) # define PUGIXML_DEPRECATED __declspec(deprecated)
# else # else
# define PUGIXML_DEPRECATED # define PUGIXML_DEPRECATED
# endif # endif
#endif #endif
// Include exception header for XPath
#if !defined(PUGIXML_NO_XPATH) && !defined(PUGIXML_NO_EXCEPTIONS)
# include <exception>
#endif
// If no API is defined, assume default // If no API is defined, assume default
#ifndef PUGIXML_API #ifndef PUGIXML_API
# define PUGIXML_API # define PUGIXML_API
#endif #endif
// If no API for classes is defined, assume default // If no API for classes is defined, assume default
#ifndef PUGIXML_CLASS #ifndef PUGIXML_CLASS
# define PUGIXML_CLASS PUGIXML_API # define PUGIXML_CLASS PUGIXML_API
#endif #endif
// If no API for functions is defined, assume default // If no API for functions is defined, assume default
#ifndef PUGIXML_FUNCTION #ifndef PUGIXML_FUNCTION
# define PUGIXML_FUNCTION PUGIXML_API # define PUGIXML_FUNCTION PUGIXML_API
#endif #endif
#include <stddef.h>
// Character interface macros // Character interface macros
#ifdef PUGIXML_WCHAR_MODE #ifdef PUGIXML_WCHAR_MODE
# define PUGIXML_TEXT(t) L ## t # define PUGIXML_TEXT(t) L ## t
# define PUGIXML_CHAR wchar_t # define PUGIXML_CHAR wchar_t
#else #else
# define PUGIXML_TEXT(t) t # define PUGIXML_TEXT(t) t
# define PUGIXML_CHAR char # define PUGIXML_CHAR char
#endif #endif
namespace pugi namespace pugi
skipping to change at line 107 skipping to change at line 92
typedef std::basic_string<PUGIXML_CHAR, std::char_traits<PUGIXML_CHA R>, std::allocator<PUGIXML_CHAR> > string_t; typedef std::basic_string<PUGIXML_CHAR, std::char_traits<PUGIXML_CHA R>, std::allocator<PUGIXML_CHAR> > string_t;
#endif #endif
} }
// The PugiXML namespace // The PugiXML namespace
namespace pugi namespace pugi
{ {
// Tree node types // Tree node types
enum xml_node_type enum xml_node_type
{ {
node_null, // Empty (null) node handle node_null, // Empty (null) node handle
node_document, // A document tree's absolute root node_document, // A document tree's absolute root
node_element, // Element tag, i.e. '<node/>' node_element, // Element tag, i.e. '<node/>'
node_pcdata, // Plain character data, i.e. 'text' node_pcdata, // Plain character data, i.e. 'text'
node_cdata, // Character data, i.e. '<![ CDATA[text]]>' node_cdata, // Character data, i.e. '<![ CDATA[text]]>'
node_comment, // Comment tag, i.e. '<!-- text -->' node_comment, // Comment tag, i.e. '<!-- text -->'
node_pi, // Processing instruction, i .e. '<?name?>' node_pi, // Processing instruction, i .e. '<?name?>'
node_declaration, // Document declaration, i.e. '<?xml version="1.0"?>' node_declaration, // Document declaration, i.e. '<?xml version="1.0"?>'
node_doctype // Document type declaration, i.e. '<!DOCTYPE d oc>' node_doctype // Document type declaration, i.e. ' <!DOCTYPE doc>'
}; };
// Parsing options // Parsing options
// Minimal parsing mode (equivalent to turning all other flags off). // Minimal parsing mode (equivalent to turning all other flags off).
// Only elements and PCDATA sections are added to the DOM tree, no text conversions are performed. // Only elements and PCDATA sections are added to the DOM tree, no t ext conversions are performed.
const unsigned int parse_minimal = 0x0000; const unsigned int parse_minimal = 0x0000;
// This flag determines if processing instructions (node_pi) are add ed to the DOM tree. This flag is off by default. // This flag determines if processing instructions (node_pi) are add ed to the DOM tree. This flag is off by default.
const unsigned int parse_pi = 0x0001; const unsigned int parse_pi = 0x0001;
// This flag determines if comments (node_comment) are added to the DOM tree. This flag is off by default. // This flag determines if comments (node_comment) are added to the DOM tree. This flag is off by default.
const unsigned int parse_comments = 0x0002; const unsigned int parse_comments = 0x0002;
// This flag determines if CDATA sections (node_cdata) are added to the DOM tree. This flag is on by default. // This flag determines if CDATA sections (node_cdata) are added to the DOM tree. This flag is on by default.
const unsigned int parse_cdata = 0x0004; const unsigned int parse_cdata = 0x0004;
// This flag determines if plain character data (node_pcdata) that c onsist only of whitespace are added to the DOM tree. // This flag determines if plain character data (node_pcdata) that c onsist only of whitespace are added to the DOM tree.
// This flag is off by default; turning it on usually results in slower parsing and more memory consumption. // This flag is off by default; turning it on usually results in slo wer parsing and more memory consumption.
const unsigned int parse_ws_pcdata = 0x0008; const unsigned int parse_ws_pcdata = 0x0008;
// This flag determines if character and entity references are expan ded during parsing. This flag is on by default. // This flag determines if character and entity references are expan ded during parsing. This flag is on by default.
const unsigned int parse_escapes = 0x0010; const unsigned int parse_escapes = 0x0010;
// This flag determines if EOL characters are normalized (converted to #xA) during parsing. This flag is on by default. // This flag determines if EOL characters are normalized (converted to #xA) during parsing. This flag is on by default.
const unsigned int parse_eol = 0x0020; const unsigned int parse_eol = 0x0020;
// This flag determines if attribute values are normalized using CDA // This flag determines if attribute values are normalized using CDA
TA normalization rules during parsing. This flag is on by default. TA normalization rules during parsing. This flag is on by default.
const unsigned int parse_wconv_attribute = 0x0040; const unsigned int parse_wconv_attribute = 0x0040;
// This flag determines if attribute values are normalized using NMT // This flag determines if attribute values are normalized using NMT
OKENS normalization rules during parsing. This flag is off by default. OKENS normalization rules during parsing. This flag is off by default.
const unsigned int parse_wnorm_attribute = 0x0080; const unsigned int parse_wnorm_attribute = 0x0080;
// This flag determines if document declaration (node_declaration) is a dded to the DOM tree. This flag is off by default. // This flag determines if document declaration (node_declaration) i s added to the DOM tree. This flag is off by default.
const unsigned int parse_declaration = 0x0100; const unsigned int parse_declaration = 0x0100;
// This flag determines if document type declaration (node_doctype) is added to the DOM tree. This flag is off by default. // This flag determines if document type declaration (node_doctype) is added to the DOM tree. This flag is off by default.
const unsigned int parse_doctype = 0x0200; const unsigned int parse_doctype = 0x0200;
// This flag determines if plain character data (node_pcdata) that i
s the only child of the parent node and that consists only
// of whitespace is added to the DOM tree.
// This flag is off by default; turning it on may result in slower p
arsing and more memory consumption.
const unsigned int parse_ws_pcdata_single = 0x0400;
// The default parsing mode. // The default parsing mode.
// Elements, PCDATA and CDATA sections are added to the DOM tree, chara // Elements, PCDATA and CDATA sections are added to the DOM tree, ch
cter/reference entities are expanded, aracter/reference entities are expanded,
// End-of-Line characters are normalized, attribute values are normaliz // End-of-Line characters are normalized, attribute values are norma
ed using CDATA normalization rules. lized using CDATA normalization rules.
const unsigned int parse_default = parse_cdata | parse_escapes | par se_wconv_attribute | parse_eol; const unsigned int parse_default = parse_cdata | parse_escapes | par se_wconv_attribute | parse_eol;
// The full parsing mode. // The full parsing mode.
// Nodes of all types are added to the DOM tree, character/reference en // Nodes of all types are added to the DOM tree, character/reference
tities are expanded, entities are expanded,
// End-of-Line characters are normalized, attribute values are normaliz // End-of-Line characters are normalized, attribute values are norma
ed using CDATA normalization rules. lized using CDATA normalization rules.
const unsigned int parse_full = parse_default | parse_pi | parse_commen const unsigned int parse_full = parse_default | parse_pi | parse_com
ts | parse_declaration | parse_doctype; ments | parse_declaration | parse_doctype;
// These flags determine the encoding of input data for XML document // These flags determine the encoding of input data for XML document
enum xml_encoding enum xml_encoding
{ {
encoding_auto, // Auto-detect input encoding using BOM encoding_auto, // Auto-detect input encoding using
or < / <? detection; use UTF8 if BOM is not found BOM or < / <? detection; use UTF8 if BOM is not found
encoding_utf8, // UTF8 encoding encoding_utf8, // UTF8 encoding
encoding_utf16_le, // Little-endian UTF16 encoding_utf16_le, // Little-endian UTF16
encoding_utf16_be, // Big-endian UTF16 encoding_utf16_be, // Big-endian UTF16
encoding_utf16, // UTF16 with native endianness encoding_utf16, // UTF16 with native endianness
encoding_utf32_le, // Little-endian UTF32 encoding_utf32_le, // Little-endian UTF32
encoding_utf32_be, // Big-endian UTF32 encoding_utf32_be, // Big-endian UTF32
encoding_utf32, // UTF32 with native endianness encoding_utf32, // UTF32 with native endianness
encoding_wchar // The same encoding wchar_t has (either encoding_wchar, // The same encoding wchar_t has (ei
UTF16 or UTF32) ther UTF16 or UTF32)
encoding_latin1
}; };
// Formatting flags // Formatting flags
// Indent the nodes that are written to output stream with as many i ndentation strings as deep the node is in DOM tree. This flag is on by defa ult. // Indent the nodes that are written to output stream with as many i ndentation strings as deep the node is in DOM tree. This flag is on by defa ult.
const unsigned int format_indent = 0x01; const unsigned int format_indent = 0x01;
// Write encoding-specific BOM to the output stream. This flag is of f by default. // Write encoding-specific BOM to the output stream. This flag is of f by default.
const unsigned int format_write_bom = 0x02; const unsigned int format_write_bom = 0x02;
// Use raw output mode (no indentation and no line breaks are writte n). This flag is off by default. // Use raw output mode (no indentation and no line breaks are writte n). This flag is off by default.
const unsigned int format_raw = 0x04; const unsigned int format_raw = 0x04;
// Omit default XML declaration even if there is no declaration in t he document. This flag is off by default. // Omit default XML declaration even if there is no declaration in t he document. This flag is off by default.
const unsigned int format_no_declaration = 0x08; const unsigned int format_no_declaration = 0x08;
// Don't escape attribute values and PCDATA contents. This flag is o
ff by default.
const unsigned int format_no_escapes = 0x10;
// Open file using text mode in xml_document::save_file. This enable
s special character (i.e. new-line) conversions on some systems. This flag
is off by default.
const unsigned int format_save_file_text = 0x20;
// The default set of formatting flags. // The default set of formatting flags.
// Nodes are indented depending on their depth in DOM tree, a default d eclaration is output if document has none. // Nodes are indented depending on their depth in DOM tree, a defaul t declaration is output if document has none.
const unsigned int format_default = format_indent; const unsigned int format_default = format_indent;
// Forward declarations // Forward declarations
struct xml_attribute_struct; struct xml_attribute_struct;
struct xml_node_struct; struct xml_node_struct;
class xml_node_iterator; class xml_node_iterator;
class xml_attribute_iterator; class xml_attribute_iterator;
class xml_named_node_iterator;
class xml_tree_walker; class xml_tree_walker;
class xml_node; class xml_node;
class xml_text;
#ifndef PUGIXML_NO_XPATH #ifndef PUGIXML_NO_XPATH
class xpath_node; class xpath_node;
class xpath_node_set; class xpath_node_set;
class xpath_query; class xpath_query;
class xpath_variable_set; class xpath_variable_set;
#endif #endif
// Range-based for loop support
template <typename It> class xml_object_range
{
public:
typedef It const_iterator;
xml_object_range(It b, It e): _begin(b), _end(e)
{
}
It begin() const { return _begin; }
It end() const { return _end; }
private:
It _begin, _end;
};
// Writer interface for node printing (see xml_node::print) // Writer interface for node printing (see xml_node::print)
class PUGIXML_CLASS xml_writer class PUGIXML_CLASS xml_writer
{ {
public: public:
virtual ~xml_writer() {} virtual ~xml_writer() {}
// Write memory chunk into stream/file/whatever // Write memory chunk into stream/file/whatever
virtual void write(const void* data, size_t size) = 0; virtual void write(const void* data, size_t size) = 0;
}; };
// xml_writer implementation for FILE* // xml_writer implementation for FILE*
class PUGIXML_CLASS xml_writer_file: public xml_writer class PUGIXML_CLASS xml_writer_file: public xml_writer
{ {
public: public:
// Construct writer from a FILE* object; void* is used to avoid hea der dependencies on stdio // Construct writer from a FILE* object; void* is used to av oid header dependencies on stdio
xml_writer_file(void* file); xml_writer_file(void* file);
virtual void write(const void* data, size_t size); virtual void write(const void* data, size_t size);
private: private:
void* file; void* file;
}; };
#ifndef PUGIXML_NO_STL #ifndef PUGIXML_NO_STL
// xml_writer implementation for streams // xml_writer implementation for streams
class PUGIXML_CLASS xml_writer_stream: public xml_writer class PUGIXML_CLASS xml_writer_stream: public xml_writer
{ {
public: public:
// Construct writer from an output stream object // Construct writer from an output stream object
xml_writer_stream(std::basic_ostream<char, std::char_traits< char> >& stream); xml_writer_stream(std::basic_ostream<char, std::char_traits< char> >& stream);
xml_writer_stream(std::basic_ostream<wchar_t, std::char_trai ts<wchar_t> >& stream); xml_writer_stream(std::basic_ostream<wchar_t, std::char_trai ts<wchar_t> >& stream);
virtual void write(const void* data, size_t size); virtual void write(const void* data, size_t size);
private: private:
std::basic_ostream<char, std::char_traits<char> >* narrow_st ream; std::basic_ostream<char, std::char_traits<char> >* narrow_st ream;
std::basic_ostream<wchar_t, std::char_traits<wchar_t> >* wid e_stream; std::basic_ostream<wchar_t, std::char_traits<wchar_t> >* wid e_stream;
}; };
#endif #endif
// A light-weight handle for manipulating attributes in DOM tree // A light-weight handle for manipulating attributes in DOM tree
class PUGIXML_CLASS xml_attribute class PUGIXML_CLASS xml_attribute
{ {
friend class xml_attribute_iterator; friend class xml_attribute_iterator;
friend class xml_node; friend class xml_node;
private: private:
xml_attribute_struct* _attr; xml_attribute_struct* _attr;
typedef xml_attribute_struct* xml_attribute::*unspecified_bool_type; typedef void (*unspecified_bool_type)(xml_attribute***);
public: public:
// Default constructor. Constructs an empty attribute. // Default constructor. Constructs an empty attribute.
xml_attribute(); xml_attribute();
// Constructs attribute from internal pointer // Constructs attribute from internal pointer
explicit xml_attribute(xml_attribute_struct* attr); explicit xml_attribute(xml_attribute_struct* attr);
// Safe bool conversion operator // Safe bool conversion operator
operator unspecified_bool_type() const; operator unspecified_bool_type() const;
// Borland C++ workaround // Borland C++ workaround
bool operator!() const; bool operator!() const;
// Comparison operators (compares wrapped attribute pointers ) // Comparison operators (compares wrapped attribute pointers )
bool operator==(const xml_attribute& r) const; bool operator==(const xml_attribute& r) const;
bool operator!=(const xml_attribute& r) const; bool operator!=(const xml_attribute& r) const;
bool operator<(const xml_attribute& r) const; bool operator<(const xml_attribute& r) const;
bool operator>(const xml_attribute& r) const; bool operator>(const xml_attribute& r) const;
bool operator<=(const xml_attribute& r) const; bool operator<=(const xml_attribute& r) const;
bool operator>=(const xml_attribute& r) const; bool operator>=(const xml_attribute& r) const;
// Check if attribute is empty // Check if attribute is empty
bool empty() const; bool empty() const;
// Get attribute name/value, or "" if attribute is empty // Get attribute name/value, or "" if attribute is empty
const char_t* name() const; const char_t* name() const;
const char_t* value() const; const char_t* value() const;
// Get attribute value as a number, or 0 if conversion did n // Get attribute value, or the default value if attribute is
ot succeed or attribute is empty empty
int as_int() const; const char_t* as_string(const char_t* def = PUGIXML_TEXT("")
unsigned int as_uint() const; ) const;
double as_double() const;
float as_float() const; // Get attribute value as a number, or the default value if
conversion did not succeed or attribute is empty
int as_int(int def = 0) const;
unsigned int as_uint(unsigned int def = 0) const;
double as_double(double def = 0) const;
float as_float(float def = 0) const;
// Get attribute value as bool (returns true if first character is // Get attribute value as bool (returns true if first charac
in '1tTyY' set), or false if attribute is empty ter is in '1tTyY' set), or the default value if attribute is empty
bool as_bool() const; bool as_bool(bool def = false) const;
// Set attribute name/value (returns false if attribute is empty or there is not enough memory) // Set attribute name/value (returns false if attribute is e mpty or there is not enough memory)
bool set_name(const char_t* rhs); bool set_name(const char_t* rhs);
bool set_value(const char_t* rhs); bool set_value(const char_t* rhs);
// Set attribute value with type conversion (numbers are converted to strings, boolean is converted to "true"/"false") // Set attribute value with type conversion (numbers are con verted to strings, boolean is converted to "true"/"false")
bool set_value(int rhs); bool set_value(int rhs);
bool set_value(unsigned int rhs); bool set_value(unsigned int rhs);
bool set_value(double rhs); bool set_value(double rhs);
bool set_value(bool rhs); bool set_value(bool rhs);
// Set attribute value (equivalent to set_value without erro r checking) // Set attribute value (equivalent to set_value without erro r checking)
xml_attribute& operator=(const char_t* rhs); xml_attribute& operator=(const char_t* rhs);
xml_attribute& operator=(int rhs); xml_attribute& operator=(int rhs);
xml_attribute& operator=(unsigned int rhs); xml_attribute& operator=(unsigned int rhs);
xml_attribute& operator=(double rhs); xml_attribute& operator=(double rhs);
xml_attribute& operator=(bool rhs); xml_attribute& operator=(bool rhs);
// Get next/previous attribute in the attribute list of the parent // Get next/previous attribute in the attribute list of the
node parent node
xml_attribute next_attribute() const; xml_attribute next_attribute() const;
xml_attribute previous_attribute() const; xml_attribute previous_attribute() const;
// Get hash value (unique for handles to the same object) // Get hash value (unique for handles to the same object)
size_t hash_value() const; size_t hash_value() const;
// Get internal pointer // Get internal pointer
xml_attribute_struct* internal_object() const; xml_attribute_struct* internal_object() const;
}; };
#ifdef __BORLANDC__ #ifdef __BORLANDC__
// Borland C++ workaround // Borland C++ workaround
bool PUGIXML_FUNCTION operator&&(const xml_attribute& lhs, bool rhs) ; bool PUGIXML_FUNCTION operator&&(const xml_attribute& lhs, bool rhs) ;
bool PUGIXML_FUNCTION operator||(const xml_attribute& lhs, bool rhs) ; bool PUGIXML_FUNCTION operator||(const xml_attribute& lhs, bool rhs) ;
#endif #endif
// A light-weight handle for manipulating nodes in DOM tree // A light-weight handle for manipulating nodes in DOM tree
class PUGIXML_CLASS xml_node class PUGIXML_CLASS xml_node
{ {
friend class xml_attribute_iterator; friend class xml_attribute_iterator;
friend class xml_node_iterator; friend class xml_node_iterator;
friend class xml_named_node_iterator;
protected: protected:
xml_node_struct* _root; xml_node_struct* _root;
typedef xml_node_struct* xml_node::*unspecified_bool_type; typedef void (*unspecified_bool_type)(xml_node***);
public: public:
// Default constructor. Constructs an empty node. // Default constructor. Constructs an empty node.
xml_node(); xml_node();
// Constructs node from internal pointer // Constructs node from internal pointer
explicit xml_node(xml_node_struct* p); explicit xml_node(xml_node_struct* p);
// Safe bool conversion operator // Safe bool conversion operator
operator unspecified_bool_type() const; operator unspecified_bool_type() const;
// Borland C++ workaround // Borland C++ workaround
bool operator!() const; bool operator!() const;
// Comparison operators (compares wrapped node pointers) // Comparison operators (compares wrapped node pointers)
bool operator==(const xml_node& r) const; bool operator==(const xml_node& r) const;
bool operator!=(const xml_node& r) const; bool operator!=(const xml_node& r) const;
bool operator<(const xml_node& r) const; bool operator<(const xml_node& r) const;
bool operator>(const xml_node& r) const; bool operator>(const xml_node& r) const;
skipping to change at line 381 skipping to change at line 402
// Get node type // Get node type
xml_node_type type() const; xml_node_type type() const;
// Get node name/value, or "" if node is empty or it has no name/value // Get node name/value, or "" if node is empty or it has no name/value
const char_t* name() const; const char_t* name() const;
const char_t* value() const; const char_t* value() const;
// Get attribute list // Get attribute list
xml_attribute first_attribute() const; xml_attribute first_attribute() const;
xml_attribute last_attribute() const; xml_attribute last_attribute() const;
// Get children list // Get children list
xml_node first_child() const; xml_node first_child() const;
xml_node last_child() const; xml_node last_child() const;
// Get next/previous sibling in the children list of the parent nod e // Get next/previous sibling in the children list of the par ent node
xml_node next_sibling() const; xml_node next_sibling() const;
xml_node previous_sibling() const; xml_node previous_sibling() const;
// Get parent node // Get parent node
xml_node parent() const; xml_node parent() const;
// Get root of DOM tree this node belongs to // Get root of DOM tree this node belongs to
xml_node root() const; xml_node root() const;
// Get text object for the current node
xml_text text() const;
// Get child, attribute or next/previous sibling with the sp ecified name // Get child, attribute or next/previous sibling with the sp ecified name
xml_node child(const char_t* name) const; xml_node child(const char_t* name) const;
xml_attribute attribute(const char_t* name) const; xml_attribute attribute(const char_t* name) const;
xml_node next_sibling(const char_t* name) const; xml_node next_sibling(const char_t* name) const;
xml_node previous_sibling(const char_t* name) const; xml_node previous_sibling(const char_t* name) const;
// Get child value of current node; that is, value of the fi rst child node of type PCDATA/CDATA // Get child value of current node; that is, value of the fi rst child node of type PCDATA/CDATA
const char_t* child_value() const; const char_t* child_value() const;
// Get child value of child with specified name. Equivalent to child(name).child_value(). // Get child value of child with specified name. Equivalent to child(name).child_value().
skipping to change at line 472 skipping to change at line 496
// Find child node using predicate. Returns first child for which predicate returned true. // Find child node using predicate. Returns first child for which predicate returned true.
template <typename Predicate> xml_node find_child(Predicate pred) const template <typename Predicate> xml_node find_child(Predicate pred) const
{ {
if (!_root) return xml_node(); if (!_root) return xml_node();
for (xml_node node = first_child(); node; node = nod e.next_sibling()) for (xml_node node = first_child(); node; node = nod e.next_sibling())
if (pred(node)) if (pred(node))
return node; return node;
return xml_node(); return xml_node();
} }
// Find node from subtree using predicate. Returns first nod e from subtree (depth-first), for which predicate returned true. // Find node from subtree using predicate. Returns first nod e from subtree (depth-first), for which predicate returned true.
template <typename Predicate> xml_node find_node(Predicate p red) const template <typename Predicate> xml_node find_node(Predicate p red) const
{ {
if (!_root) return xml_node(); if (!_root) return xml_node();
xml_node cur = first_child(); xml_node cur = first_child();
while (cur._root && cur._root != _root) while (cur._root && cur._root != _root)
skipping to change at line 545 skipping to change at line 569
iterator begin() const; iterator begin() const;
iterator end() const; iterator end() const;
// Attribute iterators // Attribute iterators
typedef xml_attribute_iterator attribute_iterator; typedef xml_attribute_iterator attribute_iterator;
attribute_iterator attributes_begin() const; attribute_iterator attributes_begin() const;
attribute_iterator attributes_end() const; attribute_iterator attributes_end() const;
// Range-based for support
xml_object_range<xml_node_iterator> children() const;
xml_object_range<xml_named_node_iterator> children(const cha
r_t* name) const;
xml_object_range<xml_attribute_iterator> attributes() const;
// Get node offset in parsed file/string (in char_t units) f or debugging purposes // Get node offset in parsed file/string (in char_t units) f or debugging purposes
ptrdiff_t offset_debug() const; ptrdiff_t offset_debug() const;
// Get hash value (unique for handles to the same object) // Get hash value (unique for handles to the same object)
size_t hash_value() const; size_t hash_value() const;
// Get internal pointer // Get internal pointer
xml_node_struct* internal_object() const; xml_node_struct* internal_object() const;
}; };
#ifdef __BORLANDC__ #ifdef __BORLANDC__
// Borland C++ workaround // Borland C++ workaround
bool PUGIXML_FUNCTION operator&&(const xml_node& lhs, bool rhs); bool PUGIXML_FUNCTION operator&&(const xml_node& lhs, bool rhs);
bool PUGIXML_FUNCTION operator||(const xml_node& lhs, bool rhs); bool PUGIXML_FUNCTION operator||(const xml_node& lhs, bool rhs);
#endif #endif
// A helper for working with text inside PCDATA nodes
class PUGIXML_CLASS xml_text
{
friend class xml_node;
xml_node_struct* _root;
typedef void (*unspecified_bool_type)(xml_text***);
explicit xml_text(xml_node_struct* root);
xml_node_struct* _data_new();
xml_node_struct* _data() const;
public:
// Default constructor. Constructs an empty object.
xml_text();
// Safe bool conversion operator
operator unspecified_bool_type() const;
// Borland C++ workaround
bool operator!() const;
// Check if text object is empty
bool empty() const;
// Get text, or "" if object is empty
const char_t* get() const;
// Get text, or the default value if object is empty
const char_t* as_string(const char_t* def = PUGIXML_TEXT("")
) const;
// Get text as a number, or the default value if conversion
did not succeed or object is empty
int as_int(int def = 0) const;
unsigned int as_uint(unsigned int def = 0) const;
double as_double(double def = 0) const;
float as_float(float def = 0) const;
// Get text as bool (returns true if first character is in '
1tTyY' set), or the default value if object is empty
bool as_bool(bool def = false) const;
// Set text (returns false if object is empty or there is no
t enough memory)
bool set(const char_t* rhs);
// Set text with type conversion (numbers are converted to s
trings, boolean is converted to "true"/"false")
bool set(int rhs);
bool set(unsigned int rhs);
bool set(double rhs);
bool set(bool rhs);
// Set text (equivalent to set without error checking)
xml_text& operator=(const char_t* rhs);
xml_text& operator=(int rhs);
xml_text& operator=(unsigned int rhs);
xml_text& operator=(double rhs);
xml_text& operator=(bool rhs);
// Get the data node (node_pcdata or node_cdata) for this ob
ject
xml_node data() const;
};
#ifdef __BORLANDC__
// Borland C++ workaround
bool PUGIXML_FUNCTION operator&&(const xml_text& lhs, bool rhs);
bool PUGIXML_FUNCTION operator||(const xml_text& lhs, bool rhs);
#endif
// Child node iterator (a bidirectional iterator over a collection o f xml_node) // Child node iterator (a bidirectional iterator over a collection o f xml_node)
class PUGIXML_CLASS xml_node_iterator class PUGIXML_CLASS xml_node_iterator
{ {
friend class xml_node; friend class xml_node;
private: private:
xml_node _wrap; mutable xml_node _wrap;
xml_node _parent; xml_node _parent;
xml_node_iterator(xml_node_struct* ref, xml_node_struct* par ent); xml_node_iterator(xml_node_struct* ref, xml_node_struct* par ent);
public: public:
// Iterator traits // Iterator traits
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef xml_node value_type; typedef xml_node value_type;
typedef xml_node* pointer; typedef xml_node* pointer;
typedef xml_node& reference; typedef xml_node& reference;
#ifndef PUGIXML_NO_STL #ifndef PUGIXML_NO_STL
typedef std::bidirectional_iterator_tag iterator_category; typedef std::bidirectional_iterator_tag iterator_category;
#endif #endif
// Default constructor // Default constructor
xml_node_iterator(); xml_node_iterator();
// Construct an iterator which points to the specified node // Construct an iterator which points to the specified node
xml_node_iterator(const xml_node& node); xml_node_iterator(const xml_node& node);
// Iterator operators // Iterator operators
bool operator==(const xml_node_iterator& rhs) const; bool operator==(const xml_node_iterator& rhs) const;
bool operator!=(const xml_node_iterator& rhs) const; bool operator!=(const xml_node_iterator& rhs) const;
xml_node& operator*(); xml_node& operator*() const;
xml_node* operator->(); xml_node* operator->() const;
const xml_node_iterator& operator++(); const xml_node_iterator& operator++();
xml_node_iterator operator++(int); xml_node_iterator operator++(int);
const xml_node_iterator& operator--(); const xml_node_iterator& operator--();
xml_node_iterator operator--(int); xml_node_iterator operator--(int);
}; };
// Attribute iterator (a bidirectional iterator over a collection of xml_attribute) // Attribute iterator (a bidirectional iterator over a collection of xml_attribute)
class PUGIXML_CLASS xml_attribute_iterator class PUGIXML_CLASS xml_attribute_iterator
{ {
friend class xml_node; friend class xml_node;
private: private:
xml_attribute _wrap; mutable xml_attribute _wrap;
xml_node _parent; xml_node _parent;
xml_attribute_iterator(xml_attribute_struct* ref, xml_node_s truct* parent); xml_attribute_iterator(xml_attribute_struct* ref, xml_node_s truct* parent);
public: public:
// Iterator traits // Iterator traits
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef xml_attribute value_type; typedef xml_attribute value_type;
typedef xml_attribute* pointer; typedef xml_attribute* pointer;
typedef xml_attribute& reference; typedef xml_attribute& reference;
#ifndef PUGIXML_NO_STL #ifndef PUGIXML_NO_STL
typedef std::bidirectional_iterator_tag iterator_category; typedef std::bidirectional_iterator_tag iterator_category;
#endif #endif
// Default constructor // Default constructor
xml_attribute_iterator(); xml_attribute_iterator();
// Construct an iterator which points to the specified attribute // Construct an iterator which points to the specified attri bute
xml_attribute_iterator(const xml_attribute& attr, const xml_ node& parent); xml_attribute_iterator(const xml_attribute& attr, const xml_ node& parent);
// Iterator operators // Iterator operators
bool operator==(const xml_attribute_iterator& rhs) const; bool operator==(const xml_attribute_iterator& rhs) const;
bool operator!=(const xml_attribute_iterator& rhs) const; bool operator!=(const xml_attribute_iterator& rhs) const;
xml_attribute& operator*(); xml_attribute& operator*() const;
xml_attribute* operator->(); xml_attribute* operator->() const;
const xml_attribute_iterator& operator++(); const xml_attribute_iterator& operator++();
xml_attribute_iterator operator++(int); xml_attribute_iterator operator++(int);
const xml_attribute_iterator& operator--(); const xml_attribute_iterator& operator--();
xml_attribute_iterator operator--(int); xml_attribute_iterator operator--(int);
}; };
// Named node range helper
class xml_named_node_iterator
{
public:
// Iterator traits
typedef ptrdiff_t difference_type;
typedef xml_node value_type;
typedef xml_node* pointer;
typedef xml_node& reference;
#ifndef PUGIXML_NO_STL
typedef std::forward_iterator_tag iterator_category;
#endif
// Default constructor
xml_named_node_iterator();
// Construct an iterator which points to the specified node
xml_named_node_iterator(const xml_node& node, const char_t*
name);
// Iterator operators
bool operator==(const xml_named_node_iterator& rhs) const;
bool operator!=(const xml_named_node_iterator& rhs) const;
xml_node& operator*() const;
xml_node* operator->() const;
const xml_named_node_iterator& operator++();
xml_named_node_iterator operator++(int);
private:
mutable xml_node _node;
const char_t* _name;
};
// Abstract tree walker class (see xml_node::traverse) // Abstract tree walker class (see xml_node::traverse)
class PUGIXML_CLASS xml_tree_walker class PUGIXML_CLASS xml_tree_walker
{ {
friend class xml_node; friend class xml_node;
private: private:
int _depth; int _depth;
protected: protected:
// Get current traversal depth // Get current traversal depth
skipping to change at line 674 skipping to change at line 806
// Callback that is called for each node traversed // Callback that is called for each node traversed
virtual bool for_each(xml_node& node) = 0; virtual bool for_each(xml_node& node) = 0;
// Callback that is called when traversal ends // Callback that is called when traversal ends
virtual bool end(xml_node& node); virtual bool end(xml_node& node);
}; };
// Parsing status, returned as part of xml_parse_result object // Parsing status, returned as part of xml_parse_result object
enum xml_parse_status enum xml_parse_status
{ {
status_ok = 0, // No error status_ok = 0, // No error
status_file_not_found, // File was not found during loa status_file_not_found, // File was not found during
d_file() load_file()
status_io_error, // Error reading from file/strea status_io_error, // Error reading fro
m m file/stream
status_out_of_memory, // Could not allocate memory status_out_of_memory, // Could not allocate memory
status_internal_error, // Internal error occurred status_internal_error, // Internal error occurred
status_unrecognized_tag, // Parser could not determine ta status_unrecognized_tag, // Parser could not determin
g type e tag type
status_bad_pi, // Parsing error occurred while status_bad_pi, // Parsing error occ
parsing document declaration/processing instruction urred while parsing document declaration/processing instruction
status_bad_comment, // Parsing error occurred while status_bad_comment, // Parsing error occ
parsing comment urred while parsing comment
status_bad_cdata, // Parsing error occurred while status_bad_cdata, // Parsing error occ
parsing CDATA section urred while parsing CDATA section
status_bad_doctype, // Parsing error occurred while status_bad_doctype, // Parsing error occ
parsing document type declaration urred while parsing document type declaration
status_bad_pcdata, // Parsing error occurred while status_bad_pcdata, // Parsing error occ
parsing PCDATA section urred while parsing PCDATA section
status_bad_start_element, // Parsing error occurred while status_bad_start_element, // Parsing error occurred wh
parsing start element tag ile parsing start element tag
status_bad_attribute, // Parsing error occurred while status_bad_attribute, // Parsing error occurred wh
parsing element attribute ile parsing element attribute
status_bad_end_element, // Parsing error occurred while status_bad_end_element, // Parsing error occurred wh
parsing end element tag ile parsing end element tag
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) 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)
}; };
// Parsing result // Parsing result
struct PUGIXML_CLASS xml_parse_result struct PUGIXML_CLASS xml_parse_result
{ {
// Parsing status (see xml_parse_status) // Parsing status (see xml_parse_status)
xml_parse_status status; xml_parse_status status;
// Last parsed offset (in char_t units from start of input d ata) // Last parsed offset (in char_t units from start of input d ata)
ptrdiff_t offset; ptrdiff_t offset;
// Source document encoding // Source document encoding
xml_encoding encoding; xml_encoding encoding;
// Default constructor, initializes object to failed state // Default constructor, initializes object to failed state
xml_parse_result(); xml_parse_result();
// Cast to bool operator // Cast to bool operator
operator bool() const; operator bool() const;
// Get error description // Get error description
const char* description() const; const char* description() const;
}; };
// Document class (DOM tree root) // Document class (DOM tree root)
skipping to change at line 740 skipping to change at line 872
xml_parse_result load_buffer_impl(void* contents, size_t siz e, unsigned int options, xml_encoding encoding, bool is_mutable, bool own); xml_parse_result load_buffer_impl(void* contents, size_t siz e, unsigned int options, xml_encoding encoding, bool is_mutable, bool own);
public: public:
// Default constructor, makes empty document // Default constructor, makes empty document
xml_document(); xml_document();
// Destructor, invalidates all node/attribute handles to thi s document // Destructor, invalidates all node/attribute handles to thi s document
~xml_document(); ~xml_document();
// Removes all nodes, leaving the empty document // Removes all nodes, leaving the empty document
void reset(); void reset();
// Removes all nodes, then copies the entire contents of the specif ied document // Removes all nodes, then copies the entire contents of the specified document
void reset(const xml_document& proto); void reset(const xml_document& proto);
#ifndef PUGIXML_NO_STL #ifndef PUGIXML_NO_STL
// Load document from stream. // Load document from stream.
xml_parse_result load(std::basic_istream<char, std::char_tra its<char> >& stream, unsigned int options = parse_default, xml_encoding enc oding = encoding_auto); xml_parse_result load(std::basic_istream<char, std::char_tra its<char> >& stream, unsigned int options = parse_default, xml_encoding enc oding = encoding_auto);
xml_parse_result load(std::basic_istream<wchar_t, std::char_ traits<wchar_t> >& stream, unsigned int options = parse_default); xml_parse_result load(std::basic_istream<wchar_t, std::char_ traits<wchar_t> >& stream, unsigned int options = parse_default);
#endif #endif
// Load document from zero-terminated string. No encoding co nversions are applied. // Load document from zero-terminated string. No encoding co nversions are applied.
xml_parse_result load(const char_t* contents, unsigned int o ptions = parse_default); xml_parse_result load(const char_t* contents, unsigned int o ptions = parse_default);
// Load document from file // Load document from file
xml_parse_result load_file(const char* path, unsigned int op tions = parse_default, xml_encoding encoding = encoding_auto); xml_parse_result load_file(const char* path, unsigned int op tions = parse_default, xml_encoding encoding = encoding_auto);
xml_parse_result load_file(const wchar_t* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); xml_parse_result load_file(const wchar_t* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
// Load document from buffer. Copies/converts the buffer, so it may be deleted or changed after the function returns. // Load document from buffer. Copies/converts the buffer, so it may be deleted or changed after the function returns.
xml_parse_result load_buffer(const void* contents, size_t si ze, unsigned int options = parse_default, xml_encoding encoding = encoding_ auto); xml_parse_result load_buffer(const void* contents, size_t si ze, unsigned int options = parse_default, xml_encoding encoding = encoding_ auto);
// Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data). // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data).
// You should ensure that buffer data will persist throughout the d ocument's lifetime, and free the buffer memory manually once document is de stroyed. // You should ensure that buffer data will persist throughou t the document's lifetime, and free the buffer memory manually once documen t is destroyed.
xml_parse_result load_buffer_inplace(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encodin g_auto); xml_parse_result load_buffer_inplace(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encodin g_auto);
// Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data). // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data).
// You should allocate the buffer with pugixml allocation function; document will free the buffer when it is no longer needed (you can't use i t anymore). // You should allocate the buffer with pugixml allocation fu nction; document will free the buffer when it is no longer needed (you can' t use it anymore).
xml_parse_result load_buffer_inplace_own(void* contents, siz e_t size, unsigned int options = parse_default, xml_encoding encoding = enc oding_auto); xml_parse_result load_buffer_inplace_own(void* contents, siz e_t size, unsigned int options = parse_default, xml_encoding encoding = enc oding_auto);
// Save XML document to writer (semantics is slightly differ ent from xml_node::print, see documentation for details). // Save XML document to writer (semantics is slightly differ ent from xml_node::print, see documentation for details).
void save(xml_writer& writer, const char_t* indent = PUGIXML _TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = e ncoding_auto) const; void save(xml_writer& writer, const char_t* indent = PUGIXML _TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = e ncoding_auto) const;
#ifndef PUGIXML_NO_STL #ifndef PUGIXML_NO_STL
// Save XML document to stream (semantics is slightly differ ent from xml_node::print, see documentation for details). // Save XML document to stream (semantics is slightly differ ent from xml_node::print, see documentation for details).
void save(std::basic_ostream<char, std::char_traits<char> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = fo rmat_default, xml_encoding encoding = encoding_auto) const; void save(std::basic_ostream<char, std::char_traits<char> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = fo rmat_default, xml_encoding encoding = encoding_auto) const;
void save(std::basic_ostream<wchar_t, std::char_traits<wchar _t> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flag s = format_default) const; void save(std::basic_ostream<wchar_t, std::char_traits<wchar _t> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flag s = format_default) const;
#endif #endif
// Save XML to file // Save XML to file
bool save_file(const char* path, const char_t* indent = PUGI XML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const; bool save_file(const char* path, const char_t* indent = PUGI XML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
bool save_file(const wchar_t* path, const char_t* indent = P UGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encodi ng = encoding_auto) const; bool save_file(const wchar_t* path, const char_t* indent = P UGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encodi ng = encoding_auto) const;
// Get document element // Get document element
xml_node document_element() const; xml_node document_element() const;
}; };
#ifndef PUGIXML_NO_XPATH #ifndef PUGIXML_NO_XPATH
// XPath query return type // XPath query return type
enum xpath_value_type enum xpath_value_type
{ {
xpath_type_none, // Unknown type (query failed to compi le) xpath_type_none, // Unknown type (query failed to c ompile)
xpath_type_node_set, // Node set (xpath_node_set) xpath_type_node_set, // Node set (xpath_node_set)
xpath_type_number, // Number xpath_type_number, // Number
xpath_type_string, // String xpath_type_string, // String
xpath_type_boolean // Boolean xpath_type_boolean // Boolean
}; };
// XPath parsing result // XPath parsing result
struct PUGIXML_CLASS xpath_parse_result struct PUGIXML_CLASS xpath_parse_result
{ {
// Error message (0 if no error) // Error message (0 if no error)
const char* error; const char* error;
// Last parsed offset (in char_t units from string start) // Last parsed offset (in char_t units from string start)
ptrdiff_t offset; ptrdiff_t offset;
// Default constructor, initializes object to failed state // Default constructor, initializes object to failed state
xpath_parse_result(); xpath_parse_result();
// Cast to bool operator // Cast to bool operator
operator bool() const; operator bool() const;
// Get error description // Get error description
const char* description() const; const char* description() const;
}; };
// A single XPath variable // A single XPath variable
skipping to change at line 833 skipping to change at line 965
xpath_value_type _type; xpath_value_type _type;
xpath_variable* _next; xpath_variable* _next;
xpath_variable(); xpath_variable();
// Non-copyable semantics // Non-copyable semantics
xpath_variable(const xpath_variable&); xpath_variable(const xpath_variable&);
xpath_variable& operator=(const xpath_variable&); xpath_variable& operator=(const xpath_variable&);
public: public:
// Get variable name // Get variable name
const char_t* name() const; const char_t* name() const;
// Get variable type // Get variable type
xpath_value_type type() const; xpath_value_type type() const;
// Get variable value; no type conversion is performed, default val ue (false, NaN, empty string, empty node set) is returned on type mismatch error // Get variable value; no type conversion is performed, defa ult value (false, NaN, empty string, empty node set) is returned on type mi smatch error
bool get_boolean() const; bool get_boolean() const;
double get_number() const; double get_number() const;
const char_t* get_string() const; const char_t* get_string() const;
const xpath_node_set& get_node_set() const; const xpath_node_set& get_node_set() const;
// Set variable value; no type conversion is performed, false is re turned on type mismatch error // Set variable value; no type conversion is performed, fals e is returned on type mismatch error
bool set(bool value); bool set(bool value);
bool set(double value); bool set(double value);
bool set(const char_t* value); bool set(const char_t* value);
bool set(const xpath_node_set& value); bool set(const xpath_node_set& value);
}; };
// A set of XPath variables // A set of XPath variables
class PUGIXML_CLASS xpath_variable_set class PUGIXML_CLASS xpath_variable_set
{ {
private: private:
xpath_variable* _data[64]; xpath_variable* _data[64];
// Non-copyable semantics // Non-copyable semantics
xpath_variable_set(const xpath_variable_set&); xpath_variable_set(const xpath_variable_set&);
xpath_variable_set& operator=(const xpath_variable_set&); xpath_variable_set& operator=(const xpath_variable_set&);
xpath_variable* find(const char_t* name) const; xpath_variable* find(const char_t* name) const;
public: public:
// Default constructor/destructor // Default constructor/destructor
xpath_variable_set(); xpath_variable_set();
~xpath_variable_set(); ~xpath_variable_set();
// Add a new variable or get the existing one, if the types match // Add a new variable or get the existing one, if the types match
xpath_variable* add(const char_t* name, xpath_value_type typ e); xpath_variable* add(const char_t* name, xpath_value_type typ e);
// Set value of an existing variable; no type conversion is perform ed, false is returned if there is no such variable or if types mismatch // Set value of an existing variable; no type conversion is performed, false is returned if there is no such variable or if types misma tch
bool set(const char_t* name, bool value); bool set(const char_t* name, bool value);
bool set(const char_t* name, double value); bool set(const char_t* name, double value);
bool set(const char_t* name, const char_t* value); bool set(const char_t* name, const char_t* value);
bool set(const char_t* name, const xpath_node_set& value); bool set(const char_t* name, const xpath_node_set& value);
// Get existing variable by name // Get existing variable by name
xpath_variable* get(const char_t* name); xpath_variable* get(const char_t* name);
const xpath_variable* get(const char_t* name) const; const xpath_variable* get(const char_t* name) const;
}; };
// A compiled XPath query object // A compiled XPath query object
class PUGIXML_CLASS xpath_query class PUGIXML_CLASS xpath_query
{ {
private: private:
void* _impl; void* _impl;
xpath_parse_result _result; xpath_parse_result _result;
typedef void* xpath_query::*unspecified_bool_type; typedef void (*unspecified_bool_type)(xpath_query***);
// Non-copyable semantics // Non-copyable semantics
xpath_query(const xpath_query&); xpath_query(const xpath_query&);
xpath_query& operator=(const xpath_query&); xpath_query& operator=(const xpath_query&);
public: public:
// Construct a compiled object from XPath expression. // Construct a compiled object from XPath expression.
// If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exc
on compilation errors. eption on compilation errors.
explicit xpath_query(const char_t* query, xpath_variable_set * variables = 0); explicit xpath_query(const char_t* query, xpath_variable_set * variables = 0);
// Destructor // Destructor
~xpath_query(); ~xpath_query();
// Get query expression return type // Get query expression return type
xpath_value_type return_type() const; xpath_value_type return_type() const;
// Evaluate expression as boolean value in the specified con text; performs type conversion if necessary. // Evaluate expression as boolean value in the specified con text; performs type conversion if necessary.
// If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc o n out of memory errors. // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_ alloc on out of memory errors.
bool evaluate_boolean(const xpath_node& n) const; bool evaluate_boolean(const xpath_node& n) const;
// Evaluate expression as double value in the specified cont ext; performs type conversion if necessary. // Evaluate expression as double value in the specified cont ext; performs type conversion if necessary.
// If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc o n out of memory errors. // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_ alloc on out of memory errors.
double evaluate_number(const xpath_node& n) const; double evaluate_number(const xpath_node& n) const;
#ifndef PUGIXML_NO_STL #ifndef PUGIXML_NO_STL
// Evaluate expression as string value in the specified cont ext; performs type conversion if necessary. // Evaluate expression as string value in the specified cont ext; performs type conversion if necessary.
// If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc o n out of memory errors. // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_ alloc on out of memory errors.
string_t evaluate_string(const xpath_node& n) const; string_t evaluate_string(const xpath_node& n) const;
#endif #endif
// Evaluate expression as string value in the specified cont ext; performs type conversion if necessary. // Evaluate expression as string value in the specified cont ext; performs type conversion if necessary.
// At most capacity characters are written to the destination buffe // At most capacity characters are written to the destinatio
r, full result size is returned (includes terminating zero). n buffer, full result size is returned (includes terminating zero).
// If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc o // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_
n out of memory errors. alloc on out of memory errors.
// If PUGIXML_NO_EXCEPTIONS is defined, returns empty set instead. // If PUGIXML_NO_EXCEPTIONS is defined, returns empty set i
nstead.
size_t evaluate_string(char_t* buffer, size_t capacity, cons t xpath_node& n) const; size_t evaluate_string(char_t* buffer, size_t capacity, cons t xpath_node& n) const;
// Evaluate expression as node set in the specified context. // Evaluate expression as node set in the specified context.
// If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exception // If PUGIXML_NO_EXCEPTIONS is not defined, throws xpath_exc
on type mismatch and std::bad_alloc on out of memory errors. eption on type mismatch and std::bad_alloc on out of memory errors.
// If PUGIXML_NO_EXCEPTIONS is defined, returns empty node set inst // If PUGIXML_NO_EXCEPTIONS is defined, returns empty node s
ead. et instead.
xpath_node_set evaluate_node_set(const xpath_node& n) const; xpath_node_set evaluate_node_set(const xpath_node& n) const;
// Get parsing result (used to get compilation errors in PUG IXML_NO_EXCEPTIONS mode) // Get parsing result (used to get compilation errors in PUG IXML_NO_EXCEPTIONS mode)
const xpath_parse_result& result() const; const xpath_parse_result& result() const;
// Safe bool conversion operator // Safe bool conversion operator
operator unspecified_bool_type() const; operator unspecified_bool_type() const;
// Borland C++ workaround // Borland C++ workaround
bool operator!() const; bool operator!() const;
}; };
#ifndef PUGIXML_NO_EXCEPTIONS #ifndef PUGIXML_NO_EXCEPTIONS
// XPath exception class // XPath exception class
class PUGIXML_CLASS xpath_exception: public std::exception class PUGIXML_CLASS xpath_exception: public std::exception
{ {
private: private:
xpath_parse_result _result; xpath_parse_result _result;
public: public:
// Construct exception from parse result // Construct exception from parse result
explicit xpath_exception(const xpath_parse_result& result); explicit xpath_exception(const xpath_parse_result& result);
// Get error message // Get error message
virtual const char* what() const throw(); virtual const char* what() const throw();
// Get parse result // Get parse result
const xpath_parse_result& result() const; const xpath_parse_result& result() const;
}; };
#endif #endif
// XPath node class (either xml_node or xml_attribute) // XPath node class (either xml_node or xml_attribute)
class PUGIXML_CLASS xpath_node class PUGIXML_CLASS xpath_node
{ {
private: private:
xml_node _node; xml_node _node;
xml_attribute _attribute; xml_attribute _attribute;
typedef xml_node xpath_node::*unspecified_bool_type; typedef void (*unspecified_bool_type)(xpath_node***);
public: public:
// Default constructor; constructs empty XPath node // Default constructor; constructs empty XPath node
xpath_node(); xpath_node();
// Construct XPath node from XML node/attribute // Construct XPath node from XML node/attribute
xpath_node(const xml_node& node); xpath_node(const xml_node& node);
xpath_node(const xml_attribute& attribute, const xml_node& p arent); xpath_node(const xml_attribute& attribute, const xml_node& p arent);
// Get node/attribute, if any // Get node/attribute, if any
xml_node node() const; xml_node node() const;
xml_attribute attribute() const; xml_attribute attribute() const;
// Get parent of contained node/attribute // Get parent of contained node/attribute
xml_node parent() const; xml_node parent() const;
// Safe bool conversion operator // Safe bool conversion operator
operator unspecified_bool_type() const; operator unspecified_bool_type() const;
// Borland C++ workaround // Borland C++ workaround
bool operator!() const; bool operator!() const;
// Comparison operators // Comparison operators
bool operator==(const xpath_node& n) const; bool operator==(const xpath_node& n) const;
bool operator!=(const xpath_node& n) const; bool operator!=(const xpath_node& n) const;
}; };
#ifdef __BORLANDC__ #ifdef __BORLANDC__
// Borland C++ workaround // Borland C++ workaround
bool PUGIXML_FUNCTION operator&&(const xpath_node& lhs, bool rhs); bool PUGIXML_FUNCTION operator&&(const xpath_node& lhs, bool rhs);
bool PUGIXML_FUNCTION operator||(const xpath_node& lhs, bool rhs); bool PUGIXML_FUNCTION operator||(const xpath_node& lhs, bool rhs);
skipping to change at line 1036 skipping to change at line 1168
// Copy constructor/assignment operator // Copy constructor/assignment operator
xpath_node_set(const xpath_node_set& ns); xpath_node_set(const xpath_node_set& ns);
xpath_node_set& operator=(const xpath_node_set& ns); xpath_node_set& operator=(const xpath_node_set& ns);
// Get collection type // Get collection type
type_t type() const; type_t type() const;
// Get collection size // Get collection size
size_t size() const; size_t size() const;
// Indexing operator // Indexing operator
const xpath_node& operator[](size_t index) const; const xpath_node& operator[](size_t index) const;
// Collection iterators // Collection iterators
const_iterator begin() const; const_iterator begin() const;
const_iterator end() const; const_iterator end() const;
// Sort the collection in ascending/descending order by docu ment order // Sort the collection in ascending/descending order by docu ment order
void sort(bool reverse = false); void sort(bool reverse = false);
// Get first node in the collection by document order // Get first node in the collection by document order
skipping to change at line 1078 skipping to change at line 1210
// Convert UTF8 to wide string // Convert UTF8 to wide string
std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator <wchar_t> > PUGIXML_FUNCTION as_wide(const char* str); std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator <wchar_t> > PUGIXML_FUNCTION as_wide(const char* str);
std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator <wchar_t> > PUGIXML_FUNCTION as_wide(const std::basic_string<char, std::cha r_traits<char>, std::allocator<char> >& str); std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator <wchar_t> > PUGIXML_FUNCTION as_wide(const std::basic_string<char, std::cha r_traits<char>, std::allocator<char> >& str);
#endif #endif
// Memory allocation function interface; returns pointer to allocate d memory or NULL on failure // Memory allocation function interface; returns pointer to allocate d memory or NULL on failure
typedef void* (*allocation_function)(size_t size); typedef void* (*allocation_function)(size_t size);
// Memory deallocation function interface // Memory deallocation function interface
typedef void (*deallocation_function)(void* ptr); typedef void (*deallocation_function)(void* ptr);
// Override default memory management functions. All subsequent allocat // Override default memory management functions. All subsequent allo
ions/deallocations will be performed via supplied functions. cations/deallocations will be performed via supplied functions.
void PUGIXML_FUNCTION set_memory_management_functions(allocation_functi void PUGIXML_FUNCTION set_memory_management_functions(allocation_fun
on allocate, deallocation_function deallocate); ction allocate, deallocation_function deallocate);
// Get current memory management functions // Get current memory management functions
allocation_function PUGIXML_FUNCTION get_memory_allocation_function(); allocation_function PUGIXML_FUNCTION get_memory_allocation_function(
deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function );
(); deallocation_function PUGIXML_FUNCTION get_memory_deallocation_funct
ion();
} }
#if !defined(PUGIXML_NO_STL) && (defined(_MSC_VER) || defined(__ICC)) #if !defined(PUGIXML_NO_STL) && (defined(_MSC_VER) || defined(__ICC))
namespace std namespace std
{ {
// Workarounds for (non-standard) iterator category detection for ol der versions (MSVC7/IC8 and earlier) // Workarounds for (non-standard) iterator category detection for ol der versions (MSVC7/IC8 and earlier)
std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pug i::xml_node_iterator&); std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pug i::xml_node_iterator&);
std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pug i::xml_attribute_iterator&); std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pug i::xml_attribute_iterator&);
std::forward_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml _named_node_iterator&);
} }
#endif #endif
#if !defined(PUGIXML_NO_STL) && defined(__SUNPRO_CC) #if !defined(PUGIXML_NO_STL) && defined(__SUNPRO_CC)
namespace std namespace std
{ {
// Workarounds for (non-standard) iterator category detection // Workarounds for (non-standard) iterator category detection
std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category (const pugi::xml_node_iterator&); std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category (const pugi::xml_node_iterator&);
std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category (const pugi::xml_attribute_iterator&); std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category (const pugi::xml_attribute_iterator&);
std::forward_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_named_node_iterator&);
} }
#endif #endif
#endif #endif
/** /**
* Copyright (c) 2006-2010 Arseny Kapoulkine * Copyright (c) 2006-2012 Arseny Kapoulkine
* *
* Permission is hereby granted, free of charge, to any person * Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation * obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without * files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, * restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell * copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the * copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following * Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
 End of changes. 106 change blocks. 
208 lines changed or deleted 354 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/