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>

Collaboration diagram for wxXmlSerializer:
Collaboration graph
[legend]

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.
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.
void operator<< (xsSerializable *obj)
 Add serializable object to the serializer's root.

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

Constructor.

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

User constructor.

Parameters:
owner Owner name
root Name of root node
version File version
wxXmlSerializer::wxXmlSerializer ( const wxXmlSerializer obj  ) 

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 ( xsSerializable parent,
xsSerializable item 
)

Add serializable object to the serializer.

Parameters:
parent Pointer to parent serializable object (if NULL then the object is added directly to the root item)
item Added serializable object
Returns:
Pointer to added item
xsSerializable* wxXmlSerializer::AddItem ( long  parentId,
xsSerializable item 
)

Add serializable object to the serializer.

Parameters:
parentId ID of parent serializable object
item Added serializable object
Returns:
Pointer to added item
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.

Parameters:
type Pointer to class info
Returns:
True if at least one object of given type is included in the serializer, otherwise False
bool wxXmlSerializer::Contains ( xsSerializable object  )  const

Check whether given object is included in the serializer.

Parameters:
object Pointer to checked object
Returns:
True if the object is included in the serializer, otherwise False
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:
src Reference to the source data manager
virtual bool wxXmlSerializer::DeserializeFromXml ( wxInputStream &  instream  )  [virtual]

Deserialize objects from given stream.

Parameters:
instream Input stream
Returns:
TRUE on success, otherwise FALSE
virtual bool wxXmlSerializer::DeserializeFromXml ( const wxString &  file  )  [virtual]

Deserialize objects from given file.

Parameters:
file Full path to input file
Returns:
TRUE on success, otherwise FALSE
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:
parent Pointer to parent serializable object
node Pointer to input XML node
void wxXmlSerializer::EnableCloning ( bool  enab  )  [inline]

Enable/disable object cloning.

Parameters:
enab TRUE if the object can be cloned, otherwise FALSE
int wxXmlSerializer::GetIDCount ( long  id  ) 

Get number of occurences of given ID.

Parameters:
id Object ID
Returns:
Number of ID's occurences
xsSerializable* wxXmlSerializer::GetItem ( long  id  ) 

Get serializable object with given ID.

Parameters:
id Object ID
Returns:
Pointer to serializable object if exists, otherwise NULL
void wxXmlSerializer::GetItems ( wxClassInfo *  type,
SerializableList &  list,
xsSerializable::SEARCHMODE  mode = xsSerializable::searchBFS 
)

Get items of given class type.

Parameters:
type Class type
list List with matching serializable objects
mode Search mode
See also:
xsSerializable::SEARCHMODE
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.

Parameters:
datatype String ID of data type
Returns:
Pointer to I/O handler suitable for given data type if exists, otherwise NULL
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.

Returns:
Reference to map where all used IDs are stored
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.

Parameters:
id Object ID
Returns:
TRUE if the object ID is used, otherwise FALSE
void wxXmlSerializer::operator<< ( xsSerializable obj  )  [inline]

Add serializable object to the serializer's root.

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

Parameters:
item Pointer to removed object
void wxXmlSerializer::RemoveItem ( long  id  ) 

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

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

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

Parameters:
outstream Output stream
withroot If TRUE then the root item's properties are serialized as well
Returns:
TRUE on success, otherwise FALSE
virtual bool wxXmlSerializer::SerializeToXml ( const wxString &  file,
bool  withroot = false 
) [virtual]

Serialize stored objects to given file.

Parameters:
file Full path to output file
withroot If TRUE then the root item's properties are serialized as well
Returns:
TRUE on success, otherwise FALSE
void wxXmlSerializer::SetRootItem ( xsSerializable root  ) 

Set root item.

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

Set owner name.

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

Set root name.

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

Set file version.

Parameters:
name File version
wxXmlSerializer::XS_DECLARE_CLONABLE_CLASS ( wxXmlSerializer   ) 

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_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:
Generated by  doxygen 1.6.3