wxShapeFramework
1.13.0 beta
|
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>
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... | |
xsSerializable * | GetParent () |
Get serializable parent object. More... | |
wxXmlSerializer * | GetParentManager () |
Get parent data manager (instance of wxXmlSerializer). More... | |
xsSerializable * | GetFirstChild () |
Get first serializable child object. More... | |
xsSerializable * | GetFirstChild (wxClassInfo *type) |
Get first serializable child object of given type. More... | |
xsSerializable * | GetLastChild () |
Get last serializable child object. More... | |
xsSerializable * | GetLastChild (wxClassInfo *type) |
Get last serializable child object of given type. More... | |
xsSerializable * | GetSibbling () |
Get next serializable sibbling object. More... | |
xsSerializable * | GetSibbling (wxClassInfo *type) |
Get next serializable sibbling object of given type. More... | |
xsSerializable * | GetChild (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... | |
SerializableList & | GetChildrenList () |
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... | |
xsSerializable * | AddChild (xsSerializable *child) |
Add serializable child object to this object. More... | |
xsSerializable * | InsertChild (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... | |
xsProperty * | GetProperty (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... | |
xsSerializable * | operator<< (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... | |
xsSerializable * | m_pParentItem |
Pointer to parent serializable object. More... | |
wxXmlSerializer * | m_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 |
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).
xsSerializable::xsSerializable | ( | ) |
Constructor.
xsSerializable::xsSerializable | ( | const xsSerializable & | obj | ) |
Copy constructor.
xsSerializable::~xsSerializable | ( | ) |
Destructor.
xsSerializable* xsSerializable::AddChild | ( | xsSerializable * | child | ) |
Add serializable child object to this object.
child | Pointer to added child object (must NOT be NULL) |
void xsSerializable::AddProperty | ( | xsProperty * | property | ) |
Add new property to the property list.
property | Pointer to added property object |
|
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.
node | Pointer to a source XML node containig the property nodes |
Example code:
Reimplemented in wxSFTextShape, wxSFShapeBase, wxSFPolygonShape, and wxSFBitmapShape.
void xsSerializable::DeserializeObject | ( | wxXmlNode * | node | ) |
Deserialize marked class data members (properties) from appropriate fields of given parent 'object' XML node.
node | Pointer to parent 'object' XML node |
|
inline |
Enable/disable object cloning.
enab | TRUE if the object can be cloned, otherwise FALSE |
void xsSerializable::EnablePropertySerialization | ( | const wxString & | field, |
bool | enab | ||
) |
Enable/disable serialization of given property.
field | Property name |
enab | TRUE if the property should be serialized, otherwise FALSE |
|
inline |
Enable/disable object serialization.
enab | TRUE if the object should be serialized, otherwise FALSE |
xsSerializable* xsSerializable::GetChild | ( | long | id, |
bool | recursive = xsNORECURSIVE |
||
) |
Get child item with given ID if exists.
id | ID of searched child item |
recursive | If TRUE then the child shape will be searched recursivelly |
void xsSerializable::GetChildren | ( | wxClassInfo * | type, |
SerializableList & | list | ||
) |
Get children of given type.
type | Child object type (if NULL then all children are returned) |
list | Reference to a list where all found child objects will be appended |
|
inline |
Get list of children (serializable objects) of this object.
void xsSerializable::GetChildrenRecursively | ( | wxClassInfo * | type, |
SerializableList & | list, | ||
SEARCHMODE | mode = searchBFS |
||
) |
Get all children of given type recursively (i.e. children of children of .... ).
type | Get only children of given type (if NULL then all children are returned) |
list | Reference to a list where all found child objects will be appended |
mode | Search mode. User can choose Depth-First-Search or Breadth-First-Search algorithm (BFS is default) |
xsSerializable* xsSerializable::GetFirstChild | ( | ) |
Get first serializable child object.
xsSerializable* xsSerializable::GetFirstChild | ( | wxClassInfo * | type | ) |
Get first serializable child object of given type.
type | Child object type (can be NULL for any type) |
|
inline |
Get pointer to list node containing first serializable child object.
|
inline |
Get object ID.
xsSerializable* xsSerializable::GetLastChild | ( | ) |
Get last serializable child object.
xsSerializable* xsSerializable::GetLastChild | ( | wxClassInfo * | type | ) |
Get last serializable child object of given type.
type | Child object type (can be NULL for any type) |
|
inline |
Get pointer to list node containing last serializable child object.
|
inline |
Get serializable parent object.
|
inline |
Get parent data manager (instance of wxXmlSerializer).
|
inline |
Get reference to properties list.
xsProperty* xsSerializable::GetProperty | ( | const wxString & | field | ) |
Get serialized property of given name.
xsSerializable* xsSerializable::GetSibbling | ( | ) |
Get next serializable sibbling object.
xsSerializable* xsSerializable::GetSibbling | ( | wxClassInfo * | type | ) |
Get next serializable sibbling object of given type.
type | Child object type (can be NULL for any type) |
|
inline |
Function finds out whether this serializable item has some children.
|
protected |
Initialize new child object.
child | Pointer to new child object |
xsSerializable* xsSerializable::InsertChild | ( | size_t | pos, |
xsSerializable * | child | ||
) |
Insert serializable child object to this object at given position.
pos | Zero-based position |
child | Pointer to added child object (must NOT be NULL) |
|
inline |
Returns information whether the object can be cloned or not.
bool xsSerializable::IsPropertySerialized | ( | const wxString & | field | ) |
Returns information whether the given property is serialized or not.
field | Name of examined property |
|
inline |
Returns information whether the object can be serialized or not.
xsSerializable* xsSerializable::operator<< | ( | xsSerializable * | child | ) |
Add serializable child object to this object.
child | Pointer to added child object (should NOT be NULL) |
void xsSerializable::RemoveChild | ( | xsSerializable * | child | ) |
Remove serializable child item from this object (the child item will be destroyed).
child | Pointer to child item which should be removed |
void xsSerializable::RemoveChildren | ( | ) |
Remove all child items (all items will be destroyed).
void xsSerializable::RemoveProperty | ( | xsProperty * | property | ) |
Remove given property from the property list.
property | Pointer to existing property. |
void xsSerializable::Reparent | ( | xsSerializable * | parent | ) |
Assign this object as a child to given parent object.
parent | Pointer to new parent object (must NOT be NULL) |
|
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.
node | Pointer to XML node where the property nodes will be appended to |
Example code:
Reimplemented in wxSFTextShape, wxSFShapeBase, wxSFPolygonShape, and wxSFBitmapShape.
wxXmlNode* xsSerializable::SerializeObject | ( | wxXmlNode * | node | ) |
Create new 'object' XML node and serialize all marked class data members (properties) into it.
node | Pointer to parent XML node |
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.
|
inline |
Set serializable parent object.
parent | Pointer to parent object |
|
inline |
Set parent data manager.
parent | Pointer to parent data manager |
xsSerializable::XS_DECLARE_CLONABLE_CLASS | ( | xsSerializable | ) |
|
friend |
|
protected |
Object cloning flag.
|
protected |
Object serialization flag.
|
protected |
List of child objects.
|
protected |
List of serialized properties.
|
private |
Object ID.
|
protected |
Pointer to parent serializable object.
|
protected |
Pointer to parent data manager.