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:

List of all members.

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.
const wxString & GetErrMessage () const
 Get last occured error state/message.
xsSerializableGetRootItem () const
 Get pointer to root serializable object.
xsSerializableGetItem (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.
xsSerializableAddItem (long parentId, xsSerializable *item)
 Add serializable object to the serializer.
xsSerializableAddItem (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.
wxXmlSerializeroperator<< (xsSerializable *obj)
 Add serializable object to the serializer's root node.
wxXmlSerializeroperator<< (SerializableList &src)
 Add serializable objects stored in source serializable list to the serializer's root node.
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).

Static Public Member Functions

static xsPropertyIOGetPropertyIOHandler (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.
wxString m_sErr
 Error message.
xsSerializablem_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

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::wxXmlSerializer ( const wxString &  owner,
const wxString &  root,
const wxString &  version 
)

User constructor.

Parameters:
ownerOwner name
rootName of root node
versionFile version

Copy constructor.

virtual wxXmlSerializer::~wxXmlSerializer ( ) [virtual]

Destructor.


Member Function Documentation

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

Auxiliary function.

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

Auxiliary function.

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

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

Clear all initialized property IO handlers.

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

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

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

Deserialize objects from given stream.

Parameters:
instreamInput stream
Returns:
TRUE on success, otherwise FALSE

Reimplemented in wxSFDiagramManager.

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.

void wxXmlSerializer::EnableCloning ( bool  enab) [inline]

Enable/disable object cloning.

Parameters:
enabTRUE if the object can be cloned, otherwise FALSE
const wxString& wxXmlSerializer::GetErrMessage ( ) const [inline]

Get last occured error state/message.

Returns:
Error message
int wxXmlSerializer::GetIDCount ( long  id)

Get number of occurences of given ID.

Parameters:
idObject ID
Returns:
Number of ID's occurences

Get serializable object with given ID.

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

Get items of given class type.

Parameters:
typeClass type
listList with matching serializable objects
modeSearch mode
See also:
xsSerializable::SEARCHMODE
const wxString& wxXmlSerializer::GetLibraryVersion ( ) const [inline]

Get the library version.

Get the lowest free object ID.

static xsPropertyIO* wxXmlSerializer::GetPropertyIOHandler ( const wxString &  datatype) [inline, static]

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

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.

Returns:
Reference to map where all used IDs are stored

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.

Parameters:
idObject ID
Returns:
TRUE if the object ID is used, otherwise FALSE
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
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
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

Remove and destroy all stored serializable objects.

void wxXmlSerializer::RemoveItem ( long  id)

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

Parameters:
idObject ID

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

Parameters:
itemPointer to removed object
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
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.

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.

Set root item.

Parameters:
rootPointer to root item
void wxXmlSerializer::SetSerializerOwner ( const wxString &  name) [inline]

Set owner name.

Parameters:
nameOwner name
void wxXmlSerializer::SetSerializerRootName ( const wxString &  name) [inline]

Set root name.

Parameters:
nameRoot name
void wxXmlSerializer::SetSerializerVersion ( const wxString &  name) [inline]

Set file version.

Parameters:
nameFile version

Member Data Documentation

bool wxXmlSerializer::m_fClone [protected]

Object cloning flag.

Map of property IO handlers.

IDMap wxXmlSerializer::m_mapUsedIDs [protected]

Map storing information which ID is already used.

int wxXmlSerializer::m_nRefCounter [static, private]

Pointer to root object.

wxString wxXmlSerializer::m_sErr [protected]

Error message.

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.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines