5#include <utilities-def.h>
6#include <interface/sxml-i.h>
7#include <pugixml/pugixml.hpp>
9#include <helper/obj-ref-impl.hpp>
21 friend class SXmlNode;
24 pugi::xml_attribute _attr;
62 explicit SXmlAttr(LPVOID pData = NULL);
70 STDMETHOD_(LPVOID,
GetPrivPtr)(THIS) SCONST OVERRIDE;
77 STDMETHOD_(BOOL,
Empty)(THIS) SCONST OVERRIDE;
84 STDMETHOD_(
const wchar_t*,
Name)(THIS) SCONST OVERRIDE;
91 STDMETHOD_(
const wchar_t*,
Value)(THIS) SCONST OVERRIDE;
128 STDMETHOD_(
int,
AsInt)(THIS_
int def DEF_VAL(0)) OVERRIDE;
136 STDMETHOD_(
unsigned int,
AsUint)(THIS_
int def DEF_VAL(0)) OVERRIDE;
144 STDMETHOD_(
float,
AsFloat)(THIS_
float def DEF_VAL(0.0f)) OVERRIDE;
152 STDMETHOD_(
double,
AsDouble)(THIS_
double def DEF_VAL(0.0)) OVERRIDE;
160 STDMETHOD_(BOOL,
AsBool)(THIS_ BOOL def DEF_VAL(FALSE)) OVERRIDE;
168 operator bool()
const;
182 const wchar_t*
name()
const;
189 const wchar_t*
value()
const;
197 const wchar_t*
as_string(
const wchar_t* def = L
"")
const;
205 int as_int(
int def = 0)
const;
213 unsigned int as_uint(
unsigned int def = 0)
const;
229 float as_float(
float def = 0)
const;
237 bool as_bool(
bool def =
false)
const;
302 bool set_value(
double rhs,
int precision);
319 bool set_value(
float rhs,
int precision);
353 friend class SXmlDoc;
356 pugi::xml_node _node;
365 static IXmlNode * toIXmlNode(pugi::xml_node node);
394 explicit SXmlNode(LPVOID pData = NULL);
402 STDMETHOD_(
void,
ToString)(THIS_ IStringW *out) SCONST OVERRIDE;
409 STDMETHOD_(LPVOID,
GetPrivPtr)(THIS) SCONST OVERRIDE;
416 STDMETHOD_(BOOL,
Empty)(THIS) SCONST OVERRIDE;
423 STDMETHOD_(
const wchar_t*,
Name)(THIS) SCONST OVERRIDE;
430 STDMETHOD_(
const wchar_t*,
Value)(THIS) SCONST OVERRIDE;
437 STDMETHOD_(
const wchar_t*,
Text)(THIS) SCONST OVERRIDE;
445 STDMETHOD_(BOOL,
set_userdata)(THIS_
int data) OVERRIDE;
484 STDMETHOD_(
IXmlNode*,
Child)(THIS_
const wchar_t*
name, BOOL bCaseSensitive) SCONST OVERRIDE;
633 return _node==src._node;
640 return _node!=src._node;
645 operator bool()
const;
653 XmlNodeType type()
const;
657 const wchar_t* name()
const;
662 const wchar_t* value()
const;
700 SXmlNode child(
const wchar_t* name,
bool bCaseSensitive=
false)
const;
706 SXmlAttr attribute(
const wchar_t* name,
bool bCaseSensitive=
false)
const;
712 SXmlNode next_sibling(
const wchar_t* name,
bool bCaseSensitive=
false)
const;
718 SXmlNode previous_sibling(
const wchar_t* name,
bool bCaseSensitive=
false)
const;
725 SXmlAttr attribute(
const wchar_t* name,
SXmlAttr& hint,
bool bCaseSensitive=
false)
const;
729 const wchar_t* child_value()
const;
735 const wchar_t* child_value(
const wchar_t* name,
bool bCaseSensitive=
false)
const;
740 bool set_name(
const wchar_t* rhs);
745 bool set_value(
const wchar_t* rhs);
750 SXmlAttr append_attribute(
const wchar_t* name);
755 SXmlAttr prepend_attribute(
const wchar_t* name);
794 SXmlNode append_child(XmlNodeType type = node_element);
799 SXmlNode prepend_child(XmlNodeType type = node_element);
816 SXmlNode append_child(
const wchar_t* name);
821 SXmlNode prepend_child(
const wchar_t* name);
882 bool remove_attribute(
const SXmlAttr& a);
887 bool remove_attribute(
const wchar_t* name);
891 bool remove_attributes();
896 bool remove_child(
const SXmlNode& n);
901 bool remove_child(
const wchar_t* name);
905 bool remove_children();
913 friend class SXmlAttr;
914 friend class SXmlNode;
917 pugi::xml_document *_doc;
920 mutable pugi::xml_parse_result _result;
923 typedef SMap<pugi::xml_attribute_struct *, SXmlAttr*> AttrMap;
929 typedef SMap<pugi::xml_node_struct *, SXmlNode*> NodeMap;
937 IXmlAttr * toIXmlAttr(pugi::xml_attribute_struct *pAttr);
942 IXmlNode * toIXmlNode(pugi::xml_node_struct* pNode);
957 STDMETHOD_(LPVOID,
GetPrivPtr)(THIS) SCONST OVERRIDE;
960 STDMETHOD_(
void,
Reset)(THIS) OVERRIDE;
964 STDMETHOD_(
void,
Copy)(THIS_
const IXmlDoc* proto) OVERRIDE;
970 STDMETHOD_(BOOL,
LoadString)(THIS_
const wchar_t* contents,
unsigned int options) OVERRIDE;
977 STDMETHOD_(BOOL,
LoadFileA)(THIS_
const char* path,
unsigned int options, XmlEncoding encoding) OVERRIDE;
984 STDMETHOD_(BOOL,
LoadFileW)(THIS_
const wchar_t* path,
unsigned int options, XmlEncoding encoding) OVERRIDE;
992 STDMETHOD_(BOOL,
LoadBuffer)(THIS_
const void* contents,
size_t size,
unsigned int options, XmlEncoding encoding) OVERRIDE;
1001 STDMETHOD_(BOOL,
LoadBufferInplace)(THIS_
void* contents,
size_t size,
unsigned int options, XmlEncoding encoding) OVERRIDE;
1010 STDMETHOD_(BOOL,
LoadBufferInplaceOwn)(THIS_
void* contents,
size_t size,
unsigned int options, XmlEncoding encoding) OVERRIDE;
1014 STDMETHOD_(
void,
GetParseResult)(THIS_ XmlParseResult *pResult) SCONST OVERRIDE;
1019 STDMETHOD_(
void,
SaveBinary)(THIS_ FILE *f) SCONST OVERRIDE;
1027 STDMETHOD_(BOOL,
SaveFileA)(THIS_
const char* path,
const wchar_t* indent,
unsigned int flags, XmlEncoding encoding) SCONST OVERRIDE;
1035 STDMETHOD_(BOOL,
SaveFileW)(THIS_
const wchar_t* path,
const wchar_t* indent,
unsigned int flags, XmlEncoding encoding) SCONST OVERRIDE;
1046 bool load_string(
const wchar_t* contents,
unsigned int options = xml_parse_default);
1053 bool load_file(
const char* path,
unsigned int options = xml_parse_default, XmlEncoding encoding = enc_auto);
1060 bool load_file(
const wchar_t* path,
unsigned int options = xml_parse_default, XmlEncoding encoding = enc_auto);
1068 bool load_buffer(
const void* contents,
size_t size,
unsigned int options = xml_parse_default, XmlEncoding encoding = enc_auto);
1077 bool load_buffer_inplace(
void* contents,
size_t size,
unsigned int options = xml_parse_default, XmlEncoding encoding = enc_auto);
1086 bool load_buffer_inplace_own(
void* contents,
size_t size,
unsigned int options = xml_parse_default, XmlEncoding encoding = enc_auto);
1094 bool save_file(
const char* path,
const wchar_t* indent = L
"\t",
unsigned int flags = xml_parse_default, XmlEncoding encoding = enc_auto)
const;
1102 bool save_file(
const wchar_t* path,
const wchar_t* indent = L
"\t",
unsigned int flags = xml_parse_default, XmlEncoding encoding = enc_auto)
const;
1106 SXmlNode
root()
const;
1111 static const char *
GetErrDesc(XmlStatus status);
Class representing an XML attribute.
const wchar_t * Value() SCONST OVERRIDE
Gets the attribute value.
float as_float(float def=0) const
Converts the attribute value to a float.
SXmlAttr next_attribute() const
Gets the next attribute in the attribute list of the parent node.
SXmlAttr(pugi::xml_attribute attr)
Constructor for SXmlAttr.
float AsFloat(float def=0.0f) OVERRIDE
Converts the attribute value to a float.
IXmlAttr * Prev() OVERRIDE
Gets the previous attribute in the attribute list of the parent node.
BOOL set_userdata(int data) OVERRIDE
Sets user data for the attribute.
const wchar_t * Name() SCONST OVERRIDE
Gets the attribute name.
int AsInt(int def=0) OVERRIDE
Converts the attribute value to an integer.
int as_int(int def=0) const
Converts the attribute value to an integer.
int get_userdata() SCONST OVERRIDE
Gets user data for the attribute.
bool set_value(const wchar_t *rhs)
Sets the attribute value.
bool set_name(const wchar_t *rhs)
Sets the attribute name.
double AsDouble(double def=0.0) OVERRIDE
Converts the attribute value to a double.
const wchar_t * name() const
Gets the attribute name.
BOOL Empty() SCONST OVERRIDE
Checks if the attribute is empty.
const wchar_t * as_string(const wchar_t *def=L"") const
Gets the attribute value as a string.
unsigned int as_uint(unsigned int def=0) const
Converts the attribute value to an unsigned integer.
bool as_bool(bool def=false) const
Converts the attribute value to a boolean.
IXmlAttr * Next() OVERRIDE
Gets the next attribute in the attribute list of the parent node.
double as_double(double def=0) const
Converts the attribute value to a double.
SXmlAttr previous_attribute() const
Gets the previous attribute in the attribute list of the parent node.
unsigned int AsUint(int def=0) OVERRIDE
Converts the attribute value to an unsigned integer.
LPVOID GetPrivPtr() SCONST OVERRIDE
Gets the private data pointer.
bool empty() const
Checks if the attribute is empty.
const wchar_t * value() const
Gets the attribute value.
BOOL AsBool(BOOL def=FALSE) OVERRIDE
Converts the attribute value to a boolean.
IXmlNode * Root() SCONST OVERRIDE
Retrieves the root node of the document.
bool load_buffer_inplace(void *contents, size_t size, unsigned int options=xml_parse_default, XmlEncoding encoding=enc_auto)
Loads the document from a buffer using in-place parsing.
void Copy(const IXmlDoc *proto) OVERRIDE
Copies the contents of another document into this document.
BOOL LoadBufferInplaceOwn(void *contents, size_t size, unsigned int options, XmlEncoding encoding) OVERRIDE
Loads the document from a buffer using in-place parsing with automatic buffer management.
bool load_buffer_inplace_own(void *contents, size_t size, unsigned int options=xml_parse_default, XmlEncoding encoding=enc_auto)
Loads the document from a buffer using in-place parsing with automatic buffer management.
SXmlDoc()
Constructor for SXmlDoc.
BOOL LoadFileA(const char *path, unsigned int options, XmlEncoding encoding) OVERRIDE
Loads the document from a file (ANSI version).
bool save_file(const char *path, const wchar_t *indent=L"\t", unsigned int flags=xml_parse_default, XmlEncoding encoding=enc_auto) const
Saves the XML document to a file (ANSI version).
static const char * GetErrDesc(XmlStatus status)
Retrieves the error description for a given XML status.
void GetParseResult(XmlParseResult *pResult) SCONST OVERRIDE
Retrieves the result of the last parsing operation.
SXmlNode root() const
Retrieves the root node of the document.
BOOL SaveFileW(const wchar_t *path, const wchar_t *indent, unsigned int flags, XmlEncoding encoding) SCONST OVERRIDE
Saves the XML document to a file (Unicode version).
BOOL LoadString(const wchar_t *contents, unsigned int options) OVERRIDE
Loads the document from a zero-terminated string.
BOOL LoadFileW(const wchar_t *path, unsigned int options, XmlEncoding encoding) OVERRIDE
Loads the document from a file (Unicode version).
BOOL SaveFileA(const char *path, const wchar_t *indent, unsigned int flags, XmlEncoding encoding) SCONST OVERRIDE
Saves the XML document to a file (ANSI version).
BOOL LoadBufferInplace(void *contents, size_t size, unsigned int options, XmlEncoding encoding) OVERRIDE
Loads the document from a buffer using in-place parsing.
bool load_string(const wchar_t *contents, unsigned int options=xml_parse_default)
Loads the document from a zero-terminated string.
BOOL LoadBuffer(const void *contents, size_t size, unsigned int options, XmlEncoding encoding) OVERRIDE
Loads the document from a buffer.
void Reset() OVERRIDE
Resets the document, removing all nodes.
void SaveBinary(FILE *f) SCONST OVERRIDE
Saves the XML document to a writer.
bool load_buffer(const void *contents, size_t size, unsigned int options=xml_parse_default, XmlEncoding encoding=enc_auto)
Loads the document from a buffer.
LPVOID GetPrivPtr() SCONST OVERRIDE
Retrieves a private pointer associated with the document.
bool load_file(const char *path, unsigned int options=xml_parse_default, XmlEncoding encoding=enc_auto)
Loads the document from a file (ANSI version).
Class representing an XML node.
BOOL RemoveAttribute(const wchar_t *name) OVERRIDE
Removes an attribute by name.
IXmlNode * PrependCopyNode(const IXmlNode *proto) OVERRIDE
Prepends a copy of the specified node as a child.
IXmlNode * PrevSibling2(const wchar_t *name, BOOL bCaseSensitive) SCONST OVERRIDE
Gets the previous sibling node by name.
LPVOID GetPrivPtr() SCONST OVERRIDE
Gets the private data pointer.
IXmlAttr * LastAttribute() SCONST OVERRIDE
Gets the last attribute in the attribute list.
IXmlAttr * AppendCopyAttribute(const IXmlAttr *proto) OVERRIDE
Appends a copy of the specified attribute to the node.
BOOL RemoveChild(const wchar_t *name) OVERRIDE
Removes the child node with the specified name.
SXmlAttr append_copy(const SXmlAttr &proto)
Adds a copy of the specified attribute.
const wchar_t * Name() SCONST OVERRIDE
Gets the node name.
void ToString(IStringW *out) SCONST OVERRIDE
Converts the node to a string representation.
const wchar_t * Value() SCONST OVERRIDE
Gets the node value.
IXmlAttr * FirstAttribute() SCONST OVERRIDE
Gets the first attribute in the attribute list.
bool remove_attribute(const SXmlAttr &a)
Removes the specified attribute.
IXmlNode * NextSibling2(const wchar_t *name, BOOL bCaseSensitive) SCONST OVERRIDE
Gets the next sibling node by name.
IXmlNode * PrependChild(const wchar_t *name) OVERRIDE
Prepends a child node with the specified name.
const wchar_t * name() const
Gets the name of the node.
bool remove_children()
Removes all child nodes from the node.
IXmlAttr * PrependAttribute(const wchar_t *name) OVERRIDE
Prepends an attribute with the specified name.
BOOL RemoveAllChilden() OVERRIDE
Removes all child nodes from the node.
SXmlAttr append_attribute(const wchar_t *name)
Adds an attribute with the specified name.
SXmlNode prepend_child(XmlNodeType type=node_element)
Prepends a child node with the specified type.
int get_userdata() SCONST OVERRIDE
Gets user data for the node.
IXmlNode * NextSibling() SCONST OVERRIDE
Gets the next sibling node.
IXmlNode * PrevSibling() SCONST OVERRIDE
Gets the previous sibling node.
bool remove_child(const SXmlNode &n)
Removes the specified child node.
IXmlNode * AppendCopyNode(const IXmlNode *proto) OVERRIDE
Appends a copy of the specified node as a child.
IXmlNode * Child(const wchar_t *name, BOOL bCaseSensitive) SCONST OVERRIDE
Gets a child node by name.
IXmlAttr * Attribute(const wchar_t *name, BOOL bCaseSensitive) SCONST OVERRIDE
Gets an attribute by name.
SXmlAttr prepend_attribute(const wchar_t *name)
Prepends an attribute with the specified name.
IXmlNode * LastChild() SCONST OVERRIDE
Gets the last child node.
IXmlNode * FirstChild() SCONST OVERRIDE
Gets the first child node.
IXmlAttr * PrependCopyAttribute(const IXmlAttr *proto) OVERRIDE
Prepends a copy of the specified attribute to the node.
SXmlAttr prepend_copy(const SXmlAttr &proto)
Prepends a copy of the specified attribute.
IXmlAttr * AppendAttribute(const wchar_t *name) OVERRIDE
Appends an attribute with the specified name.
const wchar_t * Text() SCONST OVERRIDE
Gets the node text.
SXmlNode append_child(XmlNodeType type=node_element)
Adds a child node with the specified type.
BOOL Empty() SCONST OVERRIDE
Checks if the node is empty.
SXmlNode(pugi::xml_node node)
Constructor for SXmlNode.
BOOL set_userdata(int data) OVERRIDE
Sets user data for the node.
IXmlNode * AppendChild(const wchar_t *name) OVERRIDE
Appends a child node with the specified name.
Interface for XML attributes.
Interface for XML Document.
Bitfield structure for font style attributes.