Class encapsulates a serializable objects' manager which is responsible for handling stored serializable objects and their serialization/deserialization from/to XML files or streams. More...
#include <XmlSerializer.h>
Public Member Functions | |
XS_DECLARE_CLONABLE_CLASS (wxXmlSerializer) | |
wxXmlSerializer () | |
Constructor. | |
wxXmlSerializer (const wxString &owner, const wxString &root, const wxString &version) | |
User constructor. | |
wxXmlSerializer (const wxXmlSerializer &obj) | |
Copy constructor. | |
virtual | ~wxXmlSerializer () |
Destructor. | |
void | SetSerializerOwner (const wxString &name) |
Set owner name. | |
void | SetSerializerRootName (const wxString &name) |
Set root name. | |
void | SetSerializerVersion (const wxString &name) |
Set file version. | |
const wxString & | GetSerializerOwner () const |
Get owner name. | |
const wxString & | GetSerializerRootName () const |
Get name of root node. | |
const wxString & | GetSerializerVersion () const |
Get file version. | |
const wxString & | GetLibraryVersion () const |
Get the library version. | |
xsSerializable * | GetRootItem () const |
Get pointer to root serializable object. | |
xsSerializable * | GetItem (long id) |
Get serializable object with given ID. | |
void | GetItems (wxClassInfo *type, SerializableList &list, xsSerializable::SEARCHMODE mode=xsSerializable::searchBFS) |
Get items of given class type. | |
bool | Contains (xsSerializable *object) const |
Check whether given object is included in the serializer. | |
bool | Contains (wxClassInfo *type) |
Check whether any object of given type is included in the serializer. | |
void | SetRootItem (xsSerializable *root) |
Set root item. | |
void | CopyItems (const wxXmlSerializer &src) |
Replace current stored data with a content stored in given source manager. | |
xsSerializable * | AddItem (long parentId, xsSerializable *item) |
Add serializable object to the serializer. | |
xsSerializable * | AddItem (xsSerializable *parent, xsSerializable *item) |
Add serializable object to the serializer. | |
void | RemoveItem (long id) |
Remove serializable object from the serializer (object will be destroyed). | |
void | RemoveItem (xsSerializable *item) |
Remove serializable object from the serializer (object will be destroyed). | |
void | RemoveAll () |
Remove and destroy all stored serializable objects. | |
void | EnableCloning (bool enab) |
Enable/disable object cloning. | |
bool | IsCloned () const |
Returns information whether the object can be cloned or not. | |
virtual bool | SerializeToXml (const wxString &file, bool withroot=false) |
Serialize stored objects to given file. | |
virtual bool | SerializeToXml (wxOutputStream &outstream, bool withroot=false) |
Serialize stored objects to given stream. | |
virtual bool | DeserializeFromXml (const wxString &file) |
Deserialize objects from given file. | |
virtual bool | DeserializeFromXml (wxInputStream &instream) |
Deserialize objects from given stream. | |
virtual void | SerializeObjects (xsSerializable *parent, wxXmlNode *node, bool withparent) |
Serialize child objects of given parent object (parent object can be optionaly serialized as well) to given XML node. The function can be overriden if necessary. | |
virtual void | DeserializeObjects (xsSerializable *parent, wxXmlNode *node) |
Deserialize child objects of given parent object from given XML node. The function can be overriden if necessary. | |
long | GetNewId () |
Get the lowest free object ID. | |
bool | IsIdUsed (long id) |
Find out whether given object ID is already used. | |
int | GetIDCount (long id) |
Get number of occurences of given ID. | |
IDMap & | GetUsedIDs () |
Get map of used IDs. | |
void | InitializeAllIOHandlers () |
Initialize all standard property IO handlers. | |
void | ClearIOHandlers () |
Clear all initialized property IO handlers. | |
void | operator<< (xsSerializable *obj) |
Add serializable object to the serializer's root. | |
Static Public Member Functions | |
static xsPropertyIO * | GetPropertyIOHandler (const wxString &datatype) |
Get property I/O handler for given datatype. | |
Static Public Attributes | |
static PropertyIOMap | m_mapPropertyIOHandlers |
Map of property IO handlers. | |
Protected Attributes | |
wxString | m_sOwner |
Owner name. | |
wxString | m_sRootName |
Root node name. | |
wxString | m_sVersion |
File version. | |
xsSerializable * | m_pRoot |
Pointer to root object. | |
bool | m_fClone |
Object cloning flag. | |
IDMap | m_mapUsedIDs |
Map storing information which ID is already used. | |
Private Member Functions | |
xsSerializable * | _GetItem (long id, xsSerializable *parent) |
Auxiliary function. | |
bool | _Contains (xsSerializable *object, xsSerializable *parent) const |
Auxiliary function. | |
Static Private Attributes | |
static int | m_nRefCounter |
static wxString | m_sLibraryVersion |
Class encapsulates a serializable objects' manager which is responsible for handling stored serializable objects and their serialization/deserialization from/to XML files or streams.
Stored objects can be arranged into a list or d-ary tree structure so this class can be used as a container for various application data. Also created XML files (root node) can be marked with given version and owner name, so it is possible to control a version of saved document.
wxXmlSerializer class contains one instance of xsSerializable object created in the class constructor (can be set later via member functions as well). This serializable object called 'root object' holds all other inserted serializable objects (in case of tree structure it is a topmost tree node, in case of list structure all list items are its children). These child object can be handled via xsSerializable and wxXmlSerializer classes' member functions.
Another built-in (optional) functionality is class instaces' cloning. User can use XS_DECLARE_CLONABLE_CLASS and XS_IMPLEMENT_CLONABLE_CLASS macros instead of classic DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS macros which lead to definition of wxXmlSerializer::Clone() virtual function used for cloning of current class instance via its copy constructor (user must define it manually).
wxXmlSerializer::wxXmlSerializer | ( | ) |
Constructor.
wxXmlSerializer::wxXmlSerializer | ( | const wxString & | owner, | |
const wxString & | root, | |||
const wxString & | version | |||
) |
User constructor.
owner | Owner name | |
root | Name of root node | |
version | File version |
wxXmlSerializer::wxXmlSerializer | ( | const wxXmlSerializer & | obj | ) |
Copy constructor.
virtual wxXmlSerializer::~wxXmlSerializer | ( | ) | [virtual] |
Destructor.
bool wxXmlSerializer::_Contains | ( | xsSerializable * | object, | |
xsSerializable * | parent | |||
) | const [private] |
Auxiliary function.
xsSerializable* wxXmlSerializer::_GetItem | ( | long | id, | |
xsSerializable * | parent | |||
) | [private] |
Auxiliary function.
xsSerializable* wxXmlSerializer::AddItem | ( | xsSerializable * | parent, | |
xsSerializable * | item | |||
) |
Add serializable object to the serializer.
parent | Pointer to parent serializable object (if NULL then the object is added directly to the root item) | |
item | Added serializable object |
xsSerializable* wxXmlSerializer::AddItem | ( | long | parentId, | |
xsSerializable * | item | |||
) |
Add serializable object to the serializer.
parentId | ID of parent serializable object | |
item | Added serializable object |
void wxXmlSerializer::ClearIOHandlers | ( | ) |
Clear all initialized property IO handlers.
bool wxXmlSerializer::Contains | ( | wxClassInfo * | type | ) |
Check whether any object of given type is included in the serializer.
type | Pointer to class info |
bool wxXmlSerializer::Contains | ( | xsSerializable * | object | ) | const |
Check whether given object is included in the serializer.
object | Pointer to checked object |
void wxXmlSerializer::CopyItems | ( | const wxXmlSerializer & | src | ) |
Replace current stored data with a content stored in given source manager.
For proper functionality all stored data items derived from the xsSerializable class MUST implement virtual function xsSerializable::Clone() as well as the copy constructor. For more details see the xsSerializable::Clone() function documentation.
src | Reference to the source data manager |
virtual bool wxXmlSerializer::DeserializeFromXml | ( | wxInputStream & | instream | ) | [virtual] |
Deserialize objects from given stream.
instream | Input stream |
virtual bool wxXmlSerializer::DeserializeFromXml | ( | const wxString & | file | ) | [virtual] |
Deserialize objects from given file.
file | Full path to input file |
virtual void wxXmlSerializer::DeserializeObjects | ( | xsSerializable * | parent, | |
wxXmlNode * | node | |||
) | [virtual] |
Deserialize child objects of given parent object from given XML node. The function can be overriden if necessary.
parent | Pointer to parent serializable object | |
node | Pointer to input XML node |
void wxXmlSerializer::EnableCloning | ( | bool | enab | ) | [inline] |
Enable/disable object cloning.
enab | TRUE if the object can be cloned, otherwise FALSE |
int wxXmlSerializer::GetIDCount | ( | long | id | ) |
Get number of occurences of given ID.
id | Object ID |
xsSerializable* wxXmlSerializer::GetItem | ( | long | id | ) |
Get serializable object with given ID.
id | Object ID |
void wxXmlSerializer::GetItems | ( | wxClassInfo * | type, | |
SerializableList & | list, | |||
xsSerializable::SEARCHMODE | mode = xsSerializable::searchBFS | |||
) |
Get items of given class type.
type | Class type | |
list | List with matching serializable objects | |
mode | Search mode |
const wxString& wxXmlSerializer::GetLibraryVersion | ( | ) | const [inline] |
Get the library version.
long wxXmlSerializer::GetNewId | ( | ) |
Get the lowest free object ID.
static xsPropertyIO* wxXmlSerializer::GetPropertyIOHandler | ( | const wxString & | datatype | ) | [inline, static] |
Get property I/O handler for given datatype.
datatype | String ID of data type |
xsSerializable* wxXmlSerializer::GetRootItem | ( | ) | const [inline] |
Get pointer to root serializable object.
const wxString& wxXmlSerializer::GetSerializerOwner | ( | ) | const [inline] |
Get owner name.
const wxString& wxXmlSerializer::GetSerializerRootName | ( | ) | const [inline] |
Get name of root node.
const wxString& wxXmlSerializer::GetSerializerVersion | ( | ) | const [inline] |
Get file version.
IDMap& wxXmlSerializer::GetUsedIDs | ( | ) | [inline] |
Get map of used IDs.
void wxXmlSerializer::InitializeAllIOHandlers | ( | ) |
Initialize all standard property IO handlers.
bool wxXmlSerializer::IsCloned | ( | ) | const [inline] |
Returns information whether the object can be cloned or not.
bool wxXmlSerializer::IsIdUsed | ( | long | id | ) |
Find out whether given object ID is already used.
id | Object ID |
void wxXmlSerializer::operator<< | ( | xsSerializable * | obj | ) | [inline] |
Add serializable object to the serializer's root.
obj | Pointer to serializable object |
void wxXmlSerializer::RemoveAll | ( | ) |
Remove and destroy all stored serializable objects.
void wxXmlSerializer::RemoveItem | ( | xsSerializable * | item | ) |
Remove serializable object from the serializer (object will be destroyed).
item | Pointer to removed object |
void wxXmlSerializer::RemoveItem | ( | long | id | ) |
Remove serializable object from the serializer (object will be destroyed).
id | Object ID |
virtual void wxXmlSerializer::SerializeObjects | ( | xsSerializable * | parent, | |
wxXmlNode * | node, | |||
bool | withparent | |||
) | [virtual] |
Serialize child objects of given parent object (parent object can be optionaly serialized as well) to given XML node. The function can be overriden if necessary.
parent | Pointer to parent serializable object | |
node | Pointer to output XML node | |
withparent | TRUE if the parent object should be serialized as well |
virtual bool wxXmlSerializer::SerializeToXml | ( | wxOutputStream & | outstream, | |
bool | withroot = false | |||
) | [virtual] |
Serialize stored objects to given stream.
outstream | Output stream | |
withroot | If TRUE then the root item's properties are serialized as well |
virtual bool wxXmlSerializer::SerializeToXml | ( | const wxString & | file, | |
bool | withroot = false | |||
) | [virtual] |
Serialize stored objects to given file.
file | Full path to output file | |
withroot | If TRUE then the root item's properties are serialized as well |
void wxXmlSerializer::SetRootItem | ( | xsSerializable * | root | ) |
Set root item.
root | Pointer to root item |
void wxXmlSerializer::SetSerializerOwner | ( | const wxString & | name | ) | [inline] |
Set owner name.
name | Owner name |
void wxXmlSerializer::SetSerializerRootName | ( | const wxString & | name | ) | [inline] |
Set root name.
name | Root name |
void wxXmlSerializer::SetSerializerVersion | ( | const wxString & | name | ) | [inline] |
Set file version.
name | File version |
wxXmlSerializer::XS_DECLARE_CLONABLE_CLASS | ( | wxXmlSerializer | ) |
bool wxXmlSerializer::m_fClone [protected] |
Object cloning flag.
PropertyIOMap wxXmlSerializer::m_mapPropertyIOHandlers [static] |
Map of property IO handlers.
IDMap wxXmlSerializer::m_mapUsedIDs [protected] |
Map storing information which ID is already used.
int wxXmlSerializer::m_nRefCounter [static, private] |
xsSerializable* wxXmlSerializer::m_pRoot [protected] |
Pointer to root object.
wxString wxXmlSerializer::m_sLibraryVersion [static, private] |
wxString wxXmlSerializer::m_sOwner [protected] |
Owner name.
wxString wxXmlSerializer::m_sRootName [protected] |
Root node name.
wxString wxXmlSerializer::m_sVersion [protected] |
File version.