wxShapeFramework  1.13.0 beta
wxXmlSerializer Class Reference

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>

Inheritance diagram for wxXmlSerializer:
Collaboration diagram for wxXmlSerializer:

Public Member Functions

 XS_DECLARE_CLONABLE_CLASS (wxXmlSerializer)
 
 wxXmlSerializer ()
 Constructor. More...
 
 wxXmlSerializer (const wxString &owner, const wxString &root, const wxString &version)
 User constructor. More...
 
 wxXmlSerializer (const wxXmlSerializer &obj)
 Copy constructor. More...
 
virtual ~wxXmlSerializer ()
 Destructor. More...
 
void SetSerializerOwner (const wxString &name)
 Set owner name. More...
 
void SetSerializerRootName (const wxString &name)
 Set root name. More...
 
void SetSerializerVersion (const wxString &name)
 Set file version. More...
 
const wxString & GetSerializerOwner () const
 Get owner name. More...
 
const wxString & GetSerializerRootName () const
 Get name of root node. More...
 
const wxString & GetSerializerVersion () const
 Get file version. More...
 
const wxString & GetLibraryVersion () const
 Get the library version. More...
 
const wxString & GetErrMessage () const
 Get last occured error state/message. More...
 
xsSerializableGetRootItem () const
 Get pointer to root serializable object. More...
 
xsSerializableGetItem (long id)
 Get serializable object with given ID. More...
 
void GetItems (wxClassInfo *type, SerializableList &list, xsSerializable::SEARCHMODE mode=xsSerializable::searchBFS)
 Get items of given class type. More...
 
bool Contains (xsSerializable *object) const
 Check whether given object is included in the serializer. More...
 
bool Contains (wxClassInfo *type)
 Check whether any object of given type is included in the serializer. More...
 
void SetRootItem (xsSerializable *root)
 Set root item. More...
 
void CopyItems (const wxXmlSerializer &src)
 Replace current stored data with a content stored in given source manager. More...
 
xsSerializableAddItem (long parentId, xsSerializable *item)
 Add serializable object to the serializer. More...
 
xsSerializableAddItem (xsSerializable *parent, xsSerializable *item)
 Add serializable object to the serializer. More...
 
void RemoveItem (long id)
 Remove serializable object from the serializer (object will be destroyed). More...
 
void RemoveItem (xsSerializable *item)
 Remove serializable object from the serializer (object will be destroyed). More...
 
void RemoveAll ()
 Remove and destroy all stored serializable objects. More...
 
void EnableCloning (bool enab)
 Enable/disable object cloning. More...
 
bool IsCloned () const
 Returns information whether the object can be cloned or not. More...
 
virtual bool SerializeToXml (const wxString &file, bool withroot=false)
 Serialize stored objects to given file. More...
 
virtual bool SerializeToXml (wxOutputStream &outstream, bool withroot=false)
 Serialize stored objects to given stream. More...
 
virtual bool DeserializeFromXml (const wxString &file)
 Deserialize objects from given file. More...
 
virtual bool DeserializeFromXml (wxInputStream &instream)
 Deserialize objects from given stream. More...
 
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. More...
 
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. More...
 
long GetNewId ()
 Get the lowest free object ID. More...
 
bool IsIdUsed (long id)
 Find out whether given object ID is already used. More...
 
int GetIDCount (long id)
 Get number of occurences of given ID. More...
 
IDMap & GetUsedIDs ()
 Get map of used IDs. More...
 
void InitializeAllIOHandlers ()
 Initialize all standard property IO handlers. More...
 
void ClearIOHandlers ()
 Clear all initialized property IO handlers. More...
 
wxXmlSerializeroperator<< (xsSerializable *obj)
 Add serializable object to the serializer's root node. More...
 
wxXmlSerializeroperator<< (SerializableList &src)
 Add serializable objects stored in source serializable list to the serializer's root node. More...
 
void operator>> (SerializableList &dest)
 Get all items managed by the serializer (note that the items will be stored in given target list in a row regardless their original hierarchy). More...
 

Static Public Member Functions

static xsPropertyIOGetPropertyIOHandler (const wxString &datatype)
 Get property I/O handler for given datatype. More...
 

Static Public Attributes

static PropertyIOMap m_mapPropertyIOHandlers
 Map of property IO handlers. More...
 

Protected Attributes

wxString m_sOwner
 Owner name. More...
 
wxString m_sRootName
 Root node name. More...
 
wxString m_sVersion
 File version. More...
 
wxString m_sErr
 Error message. More...
 
xsSerializablem_pRoot
 Pointer to root object. More...
 
bool m_fClone
 Object cloning flag. More...
 
IDMap m_mapUsedIDs
 Map storing information which ID is already used. More...
 

Private Member Functions

xsSerializable_GetItem (long id, xsSerializable *parent)
 Auxiliary function. More...
 
bool _Contains (xsSerializable *object, xsSerializable *parent) const
 Auxiliary function. More...
 

Static Private Attributes

static int m_nRefCounter
 
static wxString m_sLibraryVersion
 

Detailed Description

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).

Constructor & Destructor Documentation

◆ wxXmlSerializer() [1/3]

wxXmlSerializer::wxXmlSerializer ( )

Constructor.

◆ wxXmlSerializer() [2/3]

wxXmlSerializer::wxXmlSerializer ( const wxString &  owner,
const wxString &  root,
const wxString &  version 
)

User constructor.

Parameters
ownerOwner name
rootName of root node
versionFile version

◆ wxXmlSerializer() [3/3]

wxXmlSerializer::wxXmlSerializer ( const wxXmlSerializer obj)

Copy constructor.

◆ ~wxXmlSerializer()

virtual wxXmlSerializer::~wxXmlSerializer ( )
virtual

Destructor.

Member Function Documentation

◆ _Contains()

bool wxXmlSerializer::_Contains ( xsSerializable object,
xsSerializable parent 
) const
private

Auxiliary function.

◆ _GetItem()

xsSerializable* wxXmlSerializer::_GetItem ( long  id,
xsSerializable parent 
)
private

Auxiliary function.

◆ AddItem() [1/2]

xsSerializable* wxXmlSerializer::AddItem ( long  parentId,
xsSerializable item 
)

Add serializable object to the serializer.

Parameters
parentIdID of parent serializable object
itemAdded serializable object
Returns
Pointer to added item

◆ AddItem() [2/2]

xsSerializable* wxXmlSerializer::AddItem ( xsSerializable parent,
xsSerializable item 
)

Add serializable object to the serializer.

Parameters
parentPointer to parent serializable object (if NULL then the object is added directly to the root item)
itemAdded serializable object
Returns
Pointer to added item

◆ ClearIOHandlers()

void wxXmlSerializer::ClearIOHandlers ( )

Clear all initialized property IO handlers.

◆ Contains() [1/2]

bool wxXmlSerializer::Contains ( wxClassInfo *  type)

Check whether any object of given type is included in the serializer.

Parameters
typePointer to class info
Returns
True if at least one object of given type is included in the serializer, otherwise False

◆ Contains() [2/2]

bool wxXmlSerializer::Contains ( xsSerializable object) const

Check whether given object is included in the serializer.

Parameters
objectPointer to checked object
Returns
True if the object is included in the serializer, otherwise False

◆ CopyItems()

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.
Parameters
srcReference to the source data manager

◆ DeserializeFromXml() [1/2]

virtual bool wxXmlSerializer::DeserializeFromXml ( const wxString &  file)
virtual

Deserialize objects from given file.

Parameters
fileFull path to input file
Returns
TRUE on success, otherwise FALSE

Reimplemented in wxSFDiagramManager.

◆ DeserializeFromXml() [2/2]

virtual bool wxXmlSerializer::DeserializeFromXml ( wxInputStream &  instream)
virtual

Deserialize objects from given stream.

Parameters
instreamInput stream
Returns
TRUE on success, otherwise FALSE

Reimplemented in wxSFDiagramManager.

◆ DeserializeObjects()

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.

Parameters
parentPointer to parent serializable object
nodePointer to input XML node

Reimplemented in wxSFDiagramManager.

◆ EnableCloning()

void wxXmlSerializer::EnableCloning ( bool  enab)
inline

Enable/disable object cloning.

Parameters
enabTRUE if the object can be cloned, otherwise FALSE

◆ GetErrMessage()

const wxString& wxXmlSerializer::GetErrMessage ( ) const
inline

Get last occured error state/message.

Returns
Error message

◆ GetIDCount()

int wxXmlSerializer::GetIDCount ( long  id)

Get number of occurences of given ID.

Parameters
idObject ID
Returns
Number of ID's occurences

◆ GetItem()

xsSerializable* wxXmlSerializer::GetItem ( long  id)

Get serializable object with given ID.

Parameters
idObject ID
Returns
Pointer to serializable object if exists, otherwise NULL

◆ GetItems()

void wxXmlSerializer::GetItems ( wxClassInfo *  type,
SerializableList list,
xsSerializable::SEARCHMODE  mode = xsSerializable::searchBFS 
)

Get items of given class type.

Parameters
typeClass type
listList with matching serializable objects
modeSearch mode
See also
xsSerializable::SEARCHMODE

◆ GetLibraryVersion()

const wxString& wxXmlSerializer::GetLibraryVersion ( ) const
inline

Get the library version.

◆ GetNewId()

long wxXmlSerializer::GetNewId ( )

Get the lowest free object ID.

◆ GetPropertyIOHandler()

static xsPropertyIO* wxXmlSerializer::GetPropertyIOHandler ( const wxString &  datatype)
inlinestatic

Get property I/O handler for given datatype.

Parameters
datatypeString ID of data type
Returns
Pointer to I/O handler suitable for given data type if exists, otherwise NULL

◆ GetRootItem()

xsSerializable* wxXmlSerializer::GetRootItem ( ) const
inline

Get pointer to root serializable object.

◆ GetSerializerOwner()

const wxString& wxXmlSerializer::GetSerializerOwner ( ) const
inline

Get owner name.

◆ GetSerializerRootName()

const wxString& wxXmlSerializer::GetSerializerRootName ( ) const
inline

Get name of root node.

◆ GetSerializerVersion()

const wxString& wxXmlSerializer::GetSerializerVersion ( ) const
inline

Get file version.

◆ GetUsedIDs()

IDMap& wxXmlSerializer::GetUsedIDs ( )
inline

Get map of used IDs.

Returns
Reference to map where all used IDs are stored

◆ InitializeAllIOHandlers()

void wxXmlSerializer::InitializeAllIOHandlers ( )

Initialize all standard property IO handlers.

◆ IsCloned()

bool wxXmlSerializer::IsCloned ( ) const
inline

Returns information whether the object can be cloned or not.

◆ IsIdUsed()

bool wxXmlSerializer::IsIdUsed ( long  id)

Find out whether given object ID is already used.

Parameters
idObject ID
Returns
TRUE if the object ID is used, otherwise FALSE

◆ operator<<() [1/2]

wxXmlSerializer& wxXmlSerializer::operator<< ( SerializableList src)
inline

Add serializable objects stored in source serializable list to the serializer's root node.

Parameters
srcReference to source serializable list
Returns
Reference to the serializer

◆ operator<<() [2/2]

wxXmlSerializer& wxXmlSerializer::operator<< ( xsSerializable obj)
inline

Add serializable object to the serializer's root node.

Parameters
objPointer to serializable object
Returns
Reference to the serializer

◆ operator>>()

void wxXmlSerializer::operator>> ( SerializableList dest)
inline

Get all items managed by the serializer (note that the items will be stored in given target list in a row regardless their original hierarchy).

Parameters
destReference to target serializable list

◆ RemoveAll()

void wxXmlSerializer::RemoveAll ( )

Remove and destroy all stored serializable objects.

◆ RemoveItem() [1/2]

void wxXmlSerializer::RemoveItem ( long  id)

Remove serializable object from the serializer (object will be destroyed).

Parameters
idObject ID

◆ RemoveItem() [2/2]

void wxXmlSerializer::RemoveItem ( xsSerializable item)

Remove serializable object from the serializer (object will be destroyed).

Parameters
itemPointer to removed object

◆ SerializeObjects()

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.

Parameters
parentPointer to parent serializable object
nodePointer to output XML node
withparentTRUE if the parent object should be serialized as well

◆ SerializeToXml() [1/2]

virtual bool wxXmlSerializer::SerializeToXml ( const wxString &  file,
bool  withroot = false 
)
virtual

Serialize stored objects to given file.

Parameters
fileFull path to output file
withrootIf TRUE then the root item's properties are serialized as well
Returns
TRUE on success, otherwise FALSE

Reimplemented in wxSFDiagramManager.

◆ SerializeToXml() [2/2]

virtual bool wxXmlSerializer::SerializeToXml ( wxOutputStream &  outstream,
bool  withroot = false 
)
virtual

Serialize stored objects to given stream.

Parameters
outstreamOutput stream
withrootIf TRUE then the root item's properties are serialized as well
Returns
TRUE on success, otherwise FALSE

Reimplemented in wxSFDiagramManager.

◆ SetRootItem()

void wxXmlSerializer::SetRootItem ( xsSerializable root)

Set root item.

Parameters
rootPointer to root item

◆ SetSerializerOwner()

void wxXmlSerializer::SetSerializerOwner ( const wxString &  name)
inline

Set owner name.

Parameters
nameOwner name

◆ SetSerializerRootName()

void wxXmlSerializer::SetSerializerRootName ( const wxString &  name)
inline

Set root name.

Parameters
nameRoot name

◆ SetSerializerVersion()

void wxXmlSerializer::SetSerializerVersion ( const wxString &  name)
inline

Set file version.

Parameters
nameFile version

◆ XS_DECLARE_CLONABLE_CLASS()

wxXmlSerializer::XS_DECLARE_CLONABLE_CLASS ( wxXmlSerializer  )

Member Data Documentation

◆ m_fClone

bool wxXmlSerializer::m_fClone
protected

Object cloning flag.

◆ m_mapPropertyIOHandlers

PropertyIOMap wxXmlSerializer::m_mapPropertyIOHandlers
static

Map of property IO handlers.

◆ m_mapUsedIDs

IDMap wxXmlSerializer::m_mapUsedIDs
protected

Map storing information which ID is already used.

◆ m_nRefCounter

int wxXmlSerializer::m_nRefCounter
staticprivate

◆ m_pRoot

xsSerializable* wxXmlSerializer::m_pRoot
protected

Pointer to root object.

◆ m_sErr

wxString wxXmlSerializer::m_sErr
protected

Error message.

◆ m_sLibraryVersion

wxString wxXmlSerializer::m_sLibraryVersion
staticprivate

◆ m_sOwner

wxString wxXmlSerializer::m_sOwner
protected

Owner name.

◆ m_sRootName

wxString wxXmlSerializer::m_sRootName
protected

Root node name.

◆ m_sVersion

wxString wxXmlSerializer::m_sVersion
protected

File version.


The documentation for this class was generated from the following file: