Workspace 6.21.5
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
SerializedTree Class Reference

Class to hold a serialized representation of a tree of objects. More...

#include <Workspace/DataExecution/Serialization/serializedtree.h>

Inheritance diagram for SerializedTree:
[legend]

Public Member Functions

 SerializedTree (const QString &treeName)
 
 SerializedTree (const SerializedTree &tree)
 
 ~SerializedTree () override
 
bool canSerialize () const override
 
void deepCopy (const SerializedTree &tree)
 
SerializedItem getTop () const
 
QString getTreeAsString () const
 
QString getTreeAsString (SerializedTreeIO &io) const
 
QString getTreeName () const
 
bool isNull () const
 
bool load (const SerializedItem &item) override
 
bool loadFile (const QString &fileName)
 
bool loadFile (const QString &fileName, SerializedTreeIO &io)
 
bool loadString (const QString &contents)
 
bool loadString (const QString &contents, SerializedTreeIO &io)
 
SerializedTreeoperator= (const SerializedTree &tree)
 
bool save (SerializedItem &item) const override
 
bool saveFile (const QString &fileName) const
 
bool saveFile (const QString &fileName, SerializedTreeIO &io) const
 
- Public Member Functions inherited from Serialize
virtual ~Serialize ()=default
 
virtual bool canSerialize () const =0
 
virtual bool load (const SerializedItem &item)=0
 
virtual bool save (SerializedItem &item) const =0
 

Static Public Member Functions

static SerializedTree loadXmlDocument (const QString &xml)
 

Static Public Attributes

static const QString DOCUMENT_NAME = "serializeddata"
 

Detailed Description

This class really just provides a place to hold the top of a tree. The real work is done by the SerializedItem class.

Constructor & Destructor Documentation

◆ SerializedTree() [1/2]

SerializedTree ( const QString &  treeName)
Parameters
treeNameThe name to use for the tree. This must consist only of letters, numbers and underscores. All spaces will be converted to underscores. Upper/lower case is preserved, but a good convention is to use exclusively lowercase letters only.

Constructs an empty tree to hold serialized objects. The bulk of the work is handled by the SerializedData class. Once the empty tree is constructed, the top level can be extracted with getTop() and from there, child nodes can be added to the tree as required.

You should choose a unique treeName for each type of tree you intend to use. The treeName is generally used to identify what type of data the tree holds, and this generally dictates the expected structure of the tree.

◆ SerializedTree() [2/2]

SerializedTree ( const SerializedTree tree)
Parameters
treeAn existing serialized tree handle.

Constructs another handle to whatever tree is a handle for. Note that this does not create a new tree, but rather a new handle to an existing tree. If you need a completely independent copy of tree, use the other constructor followed by a call to the deepCopy() member function.

◆ ~SerializedTree()

~SerializedTree ( )
override

Cleans up the private implementation obect.

Member Function Documentation

◆ canSerialize()

bool canSerialize ( ) const
overridevirtual
Returns
True if this object can be serialized.

For objects that can be serialized, the save and load functions will be used to do the serialization. If this function returns false, both load() and save() must also return false.

Implements Serialize.

◆ deepCopy()

void deepCopy ( const SerializedTree tree)
Parameters
treeSerializedTree object to copy to this one.

The deepCopy function is similar to the assignment operator, except it creates a copy of the whole tree rather than just copy the handle. The result of this function is that the SerializedTree object will hold an entirely new tree of its own, which is a complete copy of tree.

◆ getTop()

SerializedItem getTop ( ) const
Returns
The top of the serialized tree.

◆ getTreeAsString() [1/2]

QString getTreeAsString ( ) const
Returns
The default (XML) string representation of the SerializedTree. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getTreeAsString() [2/2]

QString getTreeAsString ( SerializedTreeIO io) const
Parameters
ioThe object responsible for handling the writing of the tree to a string.
Returns
A string representation of the SerializedTree created using the specified IO reader / writer. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getTreeName()

QString getTreeName ( ) const
Returns
The name of the serialized tree.

◆ isNull()

bool isNull ( ) const
Returns
True if this is a null tree (ie not associated with any data).

A null SerializedTree object should only ever be encountered through a failed call to loadXmlDocument.

◆ load()

bool load ( const SerializedItem item)
overridevirtual
Parameters
itemSupplies the state to be loaded into this object.

This function will load the state of this object from item. For many object types, this is most easily implemented in terms of the object's input operator (>>).

It would be reasonable for subclass implementations to assume that the data provided in item is in the same form as would have been saved from a call to save.

Returns
If the state of the object could not be loaded, the function returns false. A return value of true implies that the object state was successfully loaded. If canSerialize() returns false, this function must do nothing except return false as well.

Implements Serialize.

◆ loadFile() [1/2]

bool loadFile ( const QString &  fileName)
Parameters
fileNameName of the file containing the serialized content to load into this tree.
Returns
bool true if the serialized content in the string contents can be loaded. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Loads a SerializedTree from a file.

◆ loadFile() [2/2]

bool loadFile ( const QString &  fileName,
SerializedTreeIO io 
)
Parameters
fileNameName of the file containing the serialized content to load into this tree.
ioThe object responsible for reading the contents. It will expect the string's content to be in a specific format (e.g. XML / JSON).
Returns
bool true if the serialized content in the string contents can be loaded. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Loads a SerializedTree from a file.

◆ loadString() [1/2]

bool loadString ( const QString &  contents)
Parameters
contentsThe serialized content to load into this tree in the default (XML) format.
Returns
bool true if the serialized content in the string contents can be loaded. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Loads a SerializedTree from a string

◆ loadString() [2/2]

bool loadString ( const QString &  contents,
SerializedTreeIO io 
)
Parameters
contentsThe serialized content to load into this tree.
ioThe object responsible for reading the contents. It will expect the string's content to be in a specific format (e.g. XML / JSON).
Returns
bool true if the serialized content in the string contents can be loaded. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Loads a SerializedTree from a string

◆ loadXmlDocument()

SerializedTree loadXmlDocument ( const QString &  xml)
static

◆ operator=()

SerializedTree & operator= ( const SerializedTree tree)
Parameters
treeSerializedTree object to copy to this one.
Returns
This object.

The assignment operator makes a shallow copy of tree, meaning that they point to the same serialized tree.

◆ save()

bool save ( SerializedItem item) const
overridevirtual
Parameters
itemWhere to save the state of this object.

This function will serialise the object by saving it to item. For most object types, this is most easily implemented in terms of the object's output operator (<<).

It is allowable for an object to only serialize part of itself. This would be useful if the data it represents has a set of defaults and only those values different to the defaults need to be serialized. Such an implementation then needs to be careful how it handles the complimentary load member function.

Returns
If an object could not be serialised or if the underlying object type does not support serialisation, this function should return false. A return value of true implies that the object was successfully saved to item. If canSerialize() returns false, this function must do nothing except return false as well.

Implements Serialize.

◆ saveFile() [1/2]

bool saveFile ( const QString &  fileName) const
Parameters
fileNameName of the file to write the serialized content representing this tree.
Returns
bool true if the serialized content in the string contents can be saved. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Saves a SerializedTree to a file.

◆ saveFile() [2/2]

bool saveFile ( const QString &  fileName,
SerializedTreeIO io 
) const
Parameters
fileNameName of the file to write the serialized content representing this tree.
ioThe object responsible for writing the contents. It will export the data in a specific format (e.g. XML / JSON).
Returns
bool true if the serialized content in the string contents can be saved. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Saves a SerializedTree to a file.

Member Data Documentation

◆ DOCUMENT_NAME

const QString DOCUMENT_NAME = "serializeddata"
static