Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
UppHub
Status & Roadmap
FAQ
Authors & License
Forums
Funding U++
Search on this site











SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo

XmlIO and Xmlize framework

 

class XmlIO

XmlIO represents a single XmlNode in Jsonize framework. It is used as parameter for Xmlize and XmlAttrLoad/XmlAttrStore global functions. These functions have default templated definitions that in turn call similary named methods of object. However, when implementation using method is not possible (e.g. for supported primitive types), global templated specializations can be used.

 

 

Public Method List

 

bool IsLoading() const

True if actual operation is retrieving data from XML to C++ variables.

 


 

bool IsStoring() const

True if actual operation is storing data from C++ variables to XML.

 


 

XmlNode& Node()

const XmlNode& Node() const

XmlNode *operator->()

Returns current XmlNode represented by this XmlIO.

 


 

String GetAttr(const char *id)

Same as Node().GetAttr(id) - returns the value of attribute of current XmlNode (used when retrieving data from XML).

 


 

void SetAttr(const char *id, const String& val)

Same as Node().SetAttr(id, val) - sets the value of attribute of current XmlNode (used when storing data to XML).

 


 

template <class TXmlIO operator()(const char *tag, T& var)

template <class T, class DXmlIO operator()(const char *tag, T& var, const D& def)

Creates subtag of current XmlNode tag, forms a new XmlIO for it and calls global Xmlize function with this new XmlIO and var as parameters. Common global Xmlize is a template function that calls Xmlize method for var with new XmlIO as parameter - that way the Xmlize can be defined either as global template function specializastion for T or as method of T (usually easier, but not always possible). def parameter can be used to provide default value when there is no corresponding tag on loading. Variant without def leaves var unchanged in this case.

 


 

template <class T, class DXmlIO List(const char *tag, const char *itemtag, T& var, const D& def)

template <class TXmlIO List(const char *tag, const char *itemtag, T& var)

Creates subtag of current XmlNode tag, forms a new XmlIO for it and calls global Xmlize function with this new XmlIO, itemtag and var as parameters. Common global Xmlize is a template function that calls Xmlize method for var with new XmlIO as parameter (but not itemtag) - that way the Xmlize can be defined either as global template function specialization for T or as method of T (usually easier, but not always possible). itemtag is additional parameter that can be used as name of embeded tags when collections of items are Xmlized. def parameter can be used to provide default value when there is no corresponding tag on loading. Variant without def leaves var unchanged in this case.

 


 

template <class T, class XXmlIO Var(const char *tag, T& var, X var_xmlize)

Creates subtag of current XmlNode tag, forms a new XmlIO for it and calls global item_xmlize callable with this new XmlIO and var as parameters. This allows for in-place definition of XML structure used to represent var.

 


 

template <class T, class XXmlIO Array(const char *tag, T& var, X item_xmlize, const char *itemtag = "item")

Xmlizes array container (must have GetCount, Add and operator[] methods), using item_xmlize to define the structure of elements. itemtag provides the tags of individual elements.

 


 

template <class TXmlIO Attr(const char *id, T& var)

template <class T, class DXmlIO Attr(const char *id, T& var, const D& def)

When retrieving data, calls global function void XmlAttrLoad(T& var, const String& text) with text set to the value of attribute id of current XmlNode. Common global Xmlize is a template function that calls void XmlAttrLoad(const String& text) method for var. When storing data, sets the attribute id of current XmlNode to the result of global function call String XmlAttrStore(const T& var). Common global Xmlize is a template function that calls void XmlAttrLoad(const String& text) method for var. def parameter can be used to provide default value when retrieving data from XML fails. Returns *this.

 


 

XmlIO At(int i)

Creates a new subnode with index i of current XmlNode and returns a new XmlIO for it. Node type and properties are to be set through created XmlIO.

 


 

XmlIO Add()

Adds a new subnode to current XmlNode and returns a new XmlIO for it. Node type and properties are to be set through created XmlIO.

 


 

XmlIO Add(const char *id)

Adds a new subtag id to current XmlNode and returns XmlIO for it. Node properties are to be set through created XmlIO.

 


 

XmlIO GetAdd(const char *id)

If there already exists subtag id in current XmlNode, returns XmlIO for it, if not, it is created and XmlIO for this new tag is returned. Node properties are to be set through returned XmlIO.

 


 

void SetUserData(const Value& v)

Associates some client code value with current XmlIO. This value is propagated to any new XmlIO created by current XmlIO..

 


 

Value GetUserData() const

Returns value set by SetUserData.

 


 

XmlIO(XmlNode& xml, bool loading, const Value& userdata)

XmlIO(XmlNode& xml, bool loading)

Creates XmlIO for given XmlNode and sets the direction mode based on loading. If userdata are present, calls SetUserData(userdata).

 


 

XmlIO(XmlIO xml, const char *id)

If there already exists subtag id in current XmlNode, constructs XmlIO for it, if not, tag is created and XmlIO for this new tag is constructed.

 

 

 

Xmlize Store/Load functions

 

template <class TString StoreAsXML(const T& data, const char *name = NULL)

Stores data into XML string. The top-level tag is defined by name, if NULL, it is set to "app".

 


 

template <class Tbool LoadFromXML(T& data, const String& xml)

Loads data from XML string xml. In case of error or empty xml returns false.

 


 

template <class Tbool TryLoadFromXML(T& data, const String& xml)

Loads data from XML string xml. If xml is empty returns false. In case of error, throws XmlError.

 


 

template <class Tbool StoreAsXMLFile(T& data, const char *name = NULL, const char *file = NULL)

Stores data to XML file, using name ("app" if NULL) as top-level tag and file as the path of file. If file is NULL, ConfigFile(GetExeTitle() + ".xml") is used as the file path.

 


 

template <class Tbool LoadFromXMLFile(T& data, const char *file = NULL)

Loads data from XML file, using file as the path of file. If file is NULL, ConfigFile(GetExeTitle() + ".xml") is used as the file path. In case of error or empty xml returns false.

 


 

template <class Tbool TryLoadFromXMLFile(T& data, const char *file = NULL)

Loads data from XML file, using file as the path of file. If file is NULL, ConfigFile(GetExeTitle() + ".xml") is used as the file path. If xml is empty returns false. In case of error, throws XmlError.

 

 

Standard Xmlize template specializations

 

template <> void XmlAttrLoad(String& var, const String& text)

template <> String XmlAttrStore(const String& var)

template <> void XmlAttrLoad(WString& var, const String& text)

template <> String XmlAttrStore(const WString& var)

template <> void XmlAttrLoad(int& var, const String& text)

template <> String XmlAttrStore(const int& var)

template <> void XmlAttrLoad(dword& var, const String& text)

template <> String XmlAttrStore(const dword& var)

template <> void XmlAttrLoad(double& var, const String& text)

template <> String XmlAttrStore(const double& var)

template <> void XmlAttrLoad(bool& var, const String& text)

template <> String XmlAttrStore(const bool& var)

template <> void XmlAttrLoad(int16& var, const String& text)

template <> String XmlAttrStore(const int16& var)

template <> void XmlAttrLoad(int64& var, const String& text)

template <> String XmlAttrStore(const int64& var)

template <> void XmlAttrLoad(byte& var, const String& text)

template <> String XmlAttrStore(const byte& var)

template <> void XmlAttrLoad(Date& var, const String& text)

template <> String XmlAttrStore(const Date& var)

template <> void XmlAttrLoad(Time& var, const String& text)

template <> String XmlAttrStore(const Time& var)

Provides template specialization to support var data types as XML attributes.

 


 

template <> void Xmlize(XmlIO& xml, String& var)

template <> void Xmlize(XmlIO& xml, WString& var)

template <> void Xmlize(XmlIO& xml, int& var)

template <> void Xmlize(XmlIO& xml, dword& var)

template <> void Xmlize(XmlIO& xml, double& var)

template <> void Xmlize(XmlIO& xml, bool& var)

template <> void Xmlize(XmlIO& xml, Date& var)

template <> void Xmlize(XmlIO& xml, Time& var)

template <> void Xmlize(XmlIO& xml, int16& var)

template <> void Xmlize(XmlIO& xml, int64& var)

template <> void Xmlize(XmlIO& xml, byte& var)

Provides template specialization to support Xmlization of var data types.

 

 

Special Xmlize variants

 

void XmlizeLangAttr(XmlIO& xml, int& lang, const char *id = "lang")

Xmlizes lang language identifier number (which encodes i18n strings like "CS-CZ", see Lang.h) as id attribute, using more readable format ("CS-CZ") than plain integer number.

 


 

void XmlizeLang(XmlIO& xml, const char *tag, int& lang, const char *id = "id")

Xmlizes lang language identifier number (which encodes i18n strings like "CS-CZ", see Lang.h) as XML tag, using more readable format ("CS-CZ") than plain integer number.

 


 

template <class Tvoid XmlizeBySerialize(XmlIO& xio, T& x)

This function encodes/retrieves XML by binary serializing the object and Jsonizing the hexadecimal data string.

 


 

template <class Tvoid XmlizeByJsonize(XmlIO& xio, T& x)

This function encodes/retrieves XML by JSON conversion and then interpreting JSON object fields  as XML tags.

 

Do you want to contribute?