wxShapeFramework
1.13.0 beta
|
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>
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... | |
xsSerializable * | GetRootItem () const |
Get pointer to root serializable object. More... | |
xsSerializable * | GetItem (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... | |
xsSerializable * | AddItem (long parentId, xsSerializable *item) |
Add serializable object to the serializer. More... | |
xsSerializable * | AddItem (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... | |
wxXmlSerializer & | operator<< (xsSerializable *obj) |
Add serializable object to the serializer's root node. More... | |
wxXmlSerializer & | operator<< (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 xsPropertyIO * | GetPropertyIOHandler (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... | |
xsSerializable * | m_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 |
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).
wxXmlSerializer::wxXmlSerializer | ( | ) |
Constructor.
wxXmlSerializer::wxXmlSerializer | ( | const wxString & | owner, |
const wxString & | root, | ||
const wxString & | version | ||
) |
User constructor.
owner | Owner name |
root | Name of root node |
version | File version |
wxXmlSerializer::wxXmlSerializer | ( | const wxXmlSerializer & | obj | ) |
Copy constructor.
|
virtual |
Destructor.
|
private |
Auxiliary function.
|
private |
Auxiliary function.
xsSerializable* wxXmlSerializer::AddItem | ( | long | parentId, |
xsSerializable * | item | ||
) |
Add serializable object to the serializer.
parentId | ID of parent serializable object |
item | Added serializable object |
xsSerializable* wxXmlSerializer::AddItem | ( | xsSerializable * | parent, |
xsSerializable * | item | ||
) |
Add serializable object to the serializer.
parent | Pointer to parent serializable object (if NULL then the object is added directly to the root item) |
item | Added serializable object |
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.
type | Pointer to class info |
bool wxXmlSerializer::Contains | ( | xsSerializable * | object | ) | const |
Check whether given object is included in the serializer.
object | Pointer to checked object |
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.
src | Reference to the source data manager |
|
virtual |
Deserialize objects from given file.
file | Full path to input file |
Reimplemented in wxSFDiagramManager.
|
virtual |
Deserialize objects from given stream.
instream | Input stream |
Reimplemented in wxSFDiagramManager.
|
virtual |
Deserialize child objects of given parent object from given XML node. The function can be overriden if necessary.
parent | Pointer to parent serializable object |
node | Pointer to input XML node |
Reimplemented in wxSFDiagramManager.
|
inline |
Enable/disable object cloning.
enab | TRUE if the object can be cloned, otherwise FALSE |
|
inline |
Get last occured error state/message.
int wxXmlSerializer::GetIDCount | ( | long | id | ) |
Get number of occurences of given ID.
id | Object ID |
xsSerializable* wxXmlSerializer::GetItem | ( | long | id | ) |
Get serializable object with given ID.
id | Object ID |
void wxXmlSerializer::GetItems | ( | wxClassInfo * | type, |
SerializableList & | list, | ||
xsSerializable::SEARCHMODE | mode = xsSerializable::searchBFS |
||
) |
Get items of given class type.
type | Class type |
list | List with matching serializable objects |
mode | Search mode |
|
inline |
Get the library version.
long wxXmlSerializer::GetNewId | ( | ) |
Get the lowest free object ID.
|
inlinestatic |
Get property I/O handler for given datatype.
datatype | String ID of data type |
|
inline |
Get pointer to root serializable object.
|
inline |
Get owner name.
|
inline |
Get name of root node.
|
inline |
Get file version.
|
inline |
Get map of used IDs.
void wxXmlSerializer::InitializeAllIOHandlers | ( | ) |
Initialize all standard property IO handlers.
|
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.
id | Object ID |
|
inline |
Add serializable objects stored in source serializable list to the serializer's root node.
src | Reference to source serializable list |
|
inline |
Add serializable object to the serializer's root node.
obj | Pointer to serializable object |
|
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).
dest | Reference to target serializable list |
void wxXmlSerializer::RemoveAll | ( | ) |
Remove and destroy all stored serializable objects.
void wxXmlSerializer::RemoveItem | ( | long | id | ) |
Remove serializable object from the serializer (object will be destroyed).
id | Object ID |
void wxXmlSerializer::RemoveItem | ( | xsSerializable * | item | ) |
Remove serializable object from the serializer (object will be destroyed).
item | Pointer to removed object |
|
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.
parent | Pointer to parent serializable object |
node | Pointer to output XML node |
withparent | TRUE if the parent object should be serialized as well |
|
virtual |
Serialize stored objects to given file.
file | Full path to output file |
withroot | If TRUE then the root item's properties are serialized as well |
Reimplemented in wxSFDiagramManager.
|
virtual |
Serialize stored objects to given stream.
outstream | Output stream |
withroot | If TRUE then the root item's properties are serialized as well |
Reimplemented in wxSFDiagramManager.
void wxXmlSerializer::SetRootItem | ( | xsSerializable * | root | ) |
Set root item.
root | Pointer to root item |
|
inline |
Set owner name.
name | Owner name |
|
inline |
Set root name.
name | Root name |
|
inline |
Set file version.
name | File version |
wxXmlSerializer::XS_DECLARE_CLONABLE_CLASS | ( | wxXmlSerializer | ) |
|
protected |
Object cloning flag.
|
static |
Map of property IO handlers.
|
protected |
Map storing information which ID is already used.
|
staticprivate |
|
protected |
Pointer to root object.
|
protected |
Error message.
|
staticprivate |
|
protected |
Owner name.
|
protected |
Root node name.
|
protected |
File version.