wxShapeFramework  1.13.0 beta
xsSerializable Class Reference

Base class encapsulating object which can be serialized/deserialized to/from XML file (disk file or any stream). This class acts as a data container for properties (xsProperty class objects) encapsulating serialized class data members. More...

#include <XmlSerializer.h>

Inheritance diagram for xsSerializable:
Collaboration diagram for xsSerializable:

Public Types

enum  SEARCHMODE { searchDFS , searchBFS }
 

Public Member Functions

 XS_DECLARE_CLONABLE_CLASS (xsSerializable)
 
 xsSerializable ()
 Constructor. More...
 
 xsSerializable (const xsSerializable &obj)
 Copy constructor. More...
 
 ~xsSerializable ()
 Destructor. More...
 
xsSerializableGetParent ()
 Get serializable parent object. More...
 
wxXmlSerializerGetParentManager ()
 Get parent data manager (instance of wxXmlSerializer). More...
 
xsSerializableGetFirstChild ()
 Get first serializable child object. More...
 
xsSerializableGetFirstChild (wxClassInfo *type)
 Get first serializable child object of given type. More...
 
xsSerializableGetLastChild ()
 Get last serializable child object. More...
 
xsSerializableGetLastChild (wxClassInfo *type)
 Get last serializable child object of given type. More...
 
xsSerializableGetSibbling ()
 Get next serializable sibbling object. More...
 
xsSerializableGetSibbling (wxClassInfo *type)
 Get next serializable sibbling object of given type. More...
 
xsSerializableGetChild (long id, bool recursive=xsNORECURSIVE)
 Get child item with given ID if exists. More...
 
bool HasChildren () const
 Function finds out whether this serializable item has some children. More...
 
SerializableListGetChildrenList ()
 Get list of children (serializable objects) of this object. More...
 
void GetChildren (wxClassInfo *type, SerializableList &list)
 Get children of given type. More...
 
void GetChildrenRecursively (wxClassInfo *type, SerializableList &list, SEARCHMODE mode=searchBFS)
 Get all children of given type recursively (i.e. children of children of .... ). More...
 
SerializableList::compatibility_iterator GetFirstChildNode () const
 Get pointer to list node containing first serializable child object. More...
 
SerializableList::compatibility_iterator GetLastChildNode () const
 Get pointer to list node containing last serializable child object. More...
 
void SetParent (xsSerializable *parent)
 Set serializable parent object. More...
 
void SetParentManager (wxXmlSerializer *parent)
 Set parent data manager. More...
 
xsSerializableAddChild (xsSerializable *child)
 Add serializable child object to this object. More...
 
xsSerializableInsertChild (size_t pos, xsSerializable *child)
 Insert serializable child object to this object at given position. More...
 
void RemoveChild (xsSerializable *child)
 Remove serializable child item from this object (the child item will be destroyed). More...
 
void RemoveChildren ()
 Remove all child items (all items will be destroyed). More...
 
void Reparent (xsSerializable *parent)
 Assign this object as a child to given parent object. More...
 
void SetId (long id)
 Set ID of this object. Can be used for further objects' handling by wxXmlSerializer class (default ID value is -1). This functions should NOT be used directly; it is called by wxXmlSerializer object in the case that this serializable object is attached to another one (or directly to root node of wxXmlSerializer) by wxXmlSerializer::AddItem() member function. More...
 
long GetId () const
 Get object ID. More...
 
wxXmlNode * SerializeObject (wxXmlNode *node)
 Create new 'object' XML node and serialize all marked class data members (properties) into it. More...
 
void DeserializeObject (wxXmlNode *node)
 Deserialize marked class data members (properties) from appropriate fields of given parent 'object' XML node. More...
 
void AddProperty (xsProperty *property)
 Add new property to the property list. More...
 
void RemoveProperty (xsProperty *property)
 Remove given property from the property list. More...
 
xsPropertyGetProperty (const wxString &field)
 Get serialized property of given name. More...
 
PropertyList & GetProperties ()
 Get reference to properties list. More...
 
void EnablePropertySerialization (const wxString &field, bool enab)
 Enable/disable serialization of given property. More...
 
bool IsPropertySerialized (const wxString &field)
 Returns information whether the given property is serialized or not. More...
 
void EnableSerialization (bool enab)
 Enable/disable object serialization. More...
 
bool IsSerialized () const
 Returns information whether the object can be serialized or not. More...
 
void EnableCloning (bool enab)
 Enable/disable object cloning. More...
 
bool IsCloningEnabled () const
 Returns information whether the object can be cloned or not. More...
 
xsSerializableoperator<< (xsSerializable *child)
 Add serializable child object to this object. More...
 

Protected Member Functions

void InitChild (xsSerializable *child)
 Initialize new child object. More...
 
virtual wxXmlNode * Serialize (wxXmlNode *node)
 Serialize stored properties to the given XML node. The serialization routine is automatically called by the framework and cares about serialization of all defined properties. More...
 
virtual void Deserialize (wxXmlNode *node)
 Deserialize object properties from the given XML node. The routine is automatically called by the framework and cares about deserialization of all defined properties. More...
 

Protected Attributes

PropertyList m_lstProperties
 List of serialized properties. More...
 
SerializableList m_lstChildItems
 List of child objects. More...
 
xsSerializablem_pParentItem
 Pointer to parent serializable object. More...
 
wxXmlSerializerm_pParentManager
 Pointer to parent data manager. More...
 
bool m_fSerialize
 Object serialization flag. More...
 
bool m_fClone
 Object cloning flag. More...
 

Private Attributes

long m_nId
 Object ID. More...
 

Friends

class wxXmlSerializer
 

Detailed Description

Base class encapsulating object which can be serialized/deserialized to/from XML file (disk file or any stream). This class acts as a data container for properties (xsProperty class objects) encapsulating serialized class data members.

Class data members which should be serialized must be marked by appropriate macro defined in wxXmlSerializer.h header file (it is recommended to mark desired data members in the class constructor).

Instances of this class can be arranged into a list/d-ary tree hierarchy so it can behave like powerfull data container. All chained serializable class objects can be handled by class member functions or by member functions of wxXmlSerializer class object which should be used as their manager (recommended way).

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 xsSerializable::Clone() virtual function used for cloning of current class instance via its copy constructor (user must define it manually). Virtual xsSerializble::Clone() function is also used by the wxXmlSerializer::CopyItems() function (used by the wxXmlSerializer copy constructor).

Member Enumeration Documentation

◆ SEARCHMODE

Enumerator
searchDFS 

Depth-First-Search algorithm.

searchBFS 

Breadth-First-Search algorithm.

Constructor & Destructor Documentation

◆ xsSerializable() [1/2]

xsSerializable::xsSerializable ( )

Constructor.

◆ xsSerializable() [2/2]

xsSerializable::xsSerializable ( const xsSerializable obj)

Copy constructor.

◆ ~xsSerializable()

xsSerializable::~xsSerializable ( )

Destructor.

Member Function Documentation

◆ AddChild()

xsSerializable* xsSerializable::AddChild ( xsSerializable child)

Add serializable child object to this object.

Parameters
childPointer to added child object (must NOT be NULL)
Returns
Pointer to to the added child object

◆ AddProperty()

void xsSerializable::AddProperty ( xsProperty property)

Add new property to the property list.

Parameters
propertyPointer to added property object
See also
xsProperty

◆ Deserialize()

virtual void xsSerializable::Deserialize ( wxXmlNode *  node)
protectedvirtual

Deserialize object properties from the given XML node. The routine is automatically called by the framework and cares about deserialization of all defined properties.

Note that default implementation automatically deserializes all class data members marked by appropriate macros. If some non-standard class member should be deserialized as well, the source code of derived function implementation can be as in following example.

Parameters
nodePointer to a source XML node containig the property nodes

Example code:

void DerivedFrom_xsSerializable::Deserialize(wxXmlNode* node)
{
// call base class's deserialization rountine (if necessary...)
// iterate through all custom property nodes
wxXmlNode *propNode = node->GetChildren();
while(propNode)
{
if(propNode->GetName() == wxT("some_property_field_name"))
{
// read the node content and convert it to a proper data type
}
propNode = propNode->GetNext();
}
}
virtual void Deserialize(wxXmlNode *node)
Deserialize object properties from the given XML node. The routine is automatically called by the fra...

Reimplemented in wxSFTextShape, wxSFShapeBase, wxSFPolygonShape, and wxSFBitmapShape.

◆ DeserializeObject()

void xsSerializable::DeserializeObject ( wxXmlNode *  node)

Deserialize marked class data members (properties) from appropriate fields of given parent 'object' XML node.

Parameters
nodePointer to parent 'object' XML node

◆ EnableCloning()

void xsSerializable::EnableCloning ( bool  enab)
inline

Enable/disable object cloning.

Parameters
enabTRUE if the object can be cloned, otherwise FALSE

◆ EnablePropertySerialization()

void xsSerializable::EnablePropertySerialization ( const wxString &  field,
bool  enab 
)

Enable/disable serialization of given property.

Parameters
fieldProperty name
enabTRUE if the property should be serialized, otherwise FALSE

◆ EnableSerialization()

void xsSerializable::EnableSerialization ( bool  enab)
inline

Enable/disable object serialization.

Parameters
enabTRUE if the object should be serialized, otherwise FALSE

◆ GetChild()

xsSerializable* xsSerializable::GetChild ( long  id,
bool  recursive = xsNORECURSIVE 
)

Get child item with given ID if exists.

Parameters
idID of searched child item
recursiveIf TRUE then the child shape will be searched recursivelly
Returns
Pointer to first child with given ID if pressent, otherwise NULL

◆ GetChildren()

void xsSerializable::GetChildren ( wxClassInfo *  type,
SerializableList list 
)

Get children of given type.

Parameters
typeChild object type (if NULL then all children are returned)
listReference to a list where all found child objects will be appended

◆ GetChildrenList()

SerializableList& xsSerializable::GetChildrenList ( )
inline

Get list of children (serializable objects) of this object.

Returns
Reference to a list with child serializable objects (can be empty)

◆ GetChildrenRecursively()

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

Get all children of given type recursively (i.e. children of children of .... ).

Parameters
typeGet only children of given type (if NULL then all children are returned)
listReference to a list where all found child objects will be appended
modeSearch mode. User can choose Depth-First-Search or Breadth-First-Search algorithm (BFS is default)
See also
SEARCHMODE

◆ GetFirstChild() [1/2]

xsSerializable* xsSerializable::GetFirstChild ( )

Get first serializable child object.

Returns
Pointer to child object if exists, otherwise NULL

◆ GetFirstChild() [2/2]

xsSerializable* xsSerializable::GetFirstChild ( wxClassInfo *  type)

Get first serializable child object of given type.

Parameters
typeChild object type (can be NULL for any type)
Returns
Pointer to child object if exists, otherwise NULL

◆ GetFirstChildNode()

SerializableList::compatibility_iterator xsSerializable::GetFirstChildNode ( ) const
inline

Get pointer to list node containing first serializable child object.

◆ GetId()

long xsSerializable::GetId ( ) const
inline

Get object ID.

Returns
ID value or -1 if the ID hasn't been set yet

◆ GetLastChild() [1/2]

xsSerializable* xsSerializable::GetLastChild ( )

Get last serializable child object.

Returns
Pointer to child object if exists, otherwise NULL

◆ GetLastChild() [2/2]

xsSerializable* xsSerializable::GetLastChild ( wxClassInfo *  type)

Get last serializable child object of given type.

Parameters
typeChild object type (can be NULL for any type)
Returns
Pointer to child object if exists, otherwise NULL

◆ GetLastChildNode()

SerializableList::compatibility_iterator xsSerializable::GetLastChildNode ( ) const
inline

Get pointer to list node containing last serializable child object.

◆ GetParent()

xsSerializable* xsSerializable::GetParent ( )
inline

Get serializable parent object.

Returns
Pointer to serializable parent object if exists, otherwise NULL

◆ GetParentManager()

wxXmlSerializer* xsSerializable::GetParentManager ( )
inline

Get parent data manager (instance of wxXmlSerializer).

Returns
Pointer to parent data manager if set, otherwise NULL

◆ GetProperties()

PropertyList& xsSerializable::GetProperties ( )
inline

Get reference to properties list.

See also
xsProperty

◆ GetProperty()

xsProperty* xsSerializable::GetProperty ( const wxString &  field)

Get serialized property of given name.

Returns
Pointer to the property object if exists, otherwise NULL
See also
xsProperty

◆ GetSibbling() [1/2]

xsSerializable* xsSerializable::GetSibbling ( )

Get next serializable sibbling object.

Returns
Pointer to sibbling object if exists, otherwise NULL

◆ GetSibbling() [2/2]

xsSerializable* xsSerializable::GetSibbling ( wxClassInfo *  type)

Get next serializable sibbling object of given type.

Parameters
typeChild object type (can be NULL for any type)
Returns
Pointer to sibbling object if exists, otherwise NULL

◆ HasChildren()

bool xsSerializable::HasChildren ( ) const
inline

Function finds out whether this serializable item has some children.

Returns
TRUE if the parent shape has children, otherwise FALSE

◆ InitChild()

void xsSerializable::InitChild ( xsSerializable child)
protected

Initialize new child object.

Parameters
childPointer to new child object

◆ InsertChild()

xsSerializable* xsSerializable::InsertChild ( size_t  pos,
xsSerializable child 
)

Insert serializable child object to this object at given position.

Parameters
posZero-based position
childPointer to added child object (must NOT be NULL)
Returns
Pointer to to the added child object

◆ IsCloningEnabled()

bool xsSerializable::IsCloningEnabled ( ) const
inline

Returns information whether the object can be cloned or not.

◆ IsPropertySerialized()

bool xsSerializable::IsPropertySerialized ( const wxString &  field)

Returns information whether the given property is serialized or not.

Parameters
fieldName of examined property

◆ IsSerialized()

bool xsSerializable::IsSerialized ( ) const
inline

Returns information whether the object can be serialized or not.

◆ operator<<()

xsSerializable* xsSerializable::operator<< ( xsSerializable child)

Add serializable child object to this object.

Parameters
childPointer to added child object (should NOT be NULL)
Returns
Pointer to added object

◆ RemoveChild()

void xsSerializable::RemoveChild ( xsSerializable child)

Remove serializable child item from this object (the child item will be destroyed).

Parameters
childPointer to child item which should be removed

◆ RemoveChildren()

void xsSerializable::RemoveChildren ( )

Remove all child items (all items will be destroyed).

◆ RemoveProperty()

void xsSerializable::RemoveProperty ( xsProperty property)

Remove given property from the property list.

Parameters
propertyPointer to existing property.
See also
xsProperty, GetProperty()

◆ Reparent()

void xsSerializable::Reparent ( xsSerializable parent)

Assign this object as a child to given parent object.

Parameters
parentPointer to new parent object (must NOT be NULL)

◆ Serialize()

virtual wxXmlNode* xsSerializable::Serialize ( wxXmlNode *  node)
protectedvirtual

Serialize stored properties to the given XML node. The serialization routine is automatically called by the framework and cares about serialization of all defined properties.

Note that default implementation automatically serializes all class data members marked by appropriate macros. If some non-standard class member should be serialized as well, the source code of derived function implementation can be as in following example.

Parameters
nodePointer to XML node where the property nodes will be appended to

Example code:

wxXmlNode* DerivedFrom_xsSerializable::Serialize(wxXmlNode* node)
{
if(node)
{
// call base class's serialization routine
node = xsSeralizable::Serialize(node);
// serialize custom property
xsPropertyIO::AddPropertyNode(node, wxT("some_property_field_name"), wxT("string_repr_of_its_value"));
}
// return updated node
return node;
}
static wxXmlNode * AddPropertyNode(wxXmlNode *parent, const wxString &name, const wxString &value, wxXmlNodeType type=wxXML_TEXT_NODE)
Create new XML node of given name and value and assign it to the given parent XML node.

Reimplemented in wxSFTextShape, wxSFShapeBase, wxSFPolygonShape, and wxSFBitmapShape.

◆ SerializeObject()

wxXmlNode* xsSerializable::SerializeObject ( wxXmlNode *  node)

Create new 'object' XML node and serialize all marked class data members (properties) into it.

Parameters
nodePointer to parent XML node
Returns
Pointer to modified parent XML node

◆ SetId()

void xsSerializable::SetId ( long  id)

Set ID of this object. Can be used for further objects' handling by wxXmlSerializer class (default ID value is -1). This functions should NOT be used directly; it is called by wxXmlSerializer object in the case that this serializable object is attached to another one (or directly to root node of wxXmlSerializer) by wxXmlSerializer::AddItem() member function.

◆ SetParent()

void xsSerializable::SetParent ( xsSerializable parent)
inline

Set serializable parent object.

Parameters
parentPointer to parent object

◆ SetParentManager()

void xsSerializable::SetParentManager ( wxXmlSerializer parent)
inline

Set parent data manager.

Parameters
parentPointer to parent data manager

◆ XS_DECLARE_CLONABLE_CLASS()

xsSerializable::XS_DECLARE_CLONABLE_CLASS ( xsSerializable  )

Friends And Related Function Documentation

◆ wxXmlSerializer

friend class wxXmlSerializer
friend

Member Data Documentation

◆ m_fClone

bool xsSerializable::m_fClone
protected

Object cloning flag.

◆ m_fSerialize

bool xsSerializable::m_fSerialize
protected

Object serialization flag.

◆ m_lstChildItems

SerializableList xsSerializable::m_lstChildItems
protected

List of child objects.

◆ m_lstProperties

PropertyList xsSerializable::m_lstProperties
protected

List of serialized properties.

◆ m_nId

long xsSerializable::m_nId
private

Object ID.

◆ m_pParentItem

xsSerializable* xsSerializable::m_pParentItem
protected

Pointer to parent serializable object.

◆ m_pParentManager

wxXmlSerializer* xsSerializable::m_pParentManager
protected

Pointer to parent data manager.


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