Class to hold a serialized representation of a tree of objects.
More...
#include <Workspace/DataExecution/Serialization/serializedtree.h>
This class really just provides a place to hold the top of a tree. The real work is done by the SerializedItem class.
◆ SerializedTree() [1/2]
- Parameters
-
treeName | The 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]
- Parameters
-
tree | An 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()
Cleans up the private implementation obect.
◆ 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()
- Parameters
-
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()
- 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]
- Parameters
-
io | The 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()
- 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()
- Parameters
-
item | Supplies 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
-
fileName | Name 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]
- Parameters
-
fileName | Name of the file containing the serialized content to load into this tree. |
io | The 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
-
contents | The 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]
- Parameters
-
contents | The serialized content to load into this tree. |
io | The 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()
◆ operator=()
- Parameters
-
- Returns
- This object.
The assignment operator makes a shallow copy of tree, meaning that they point to the same serialized tree.
◆ save()
- Parameters
-
item | Where 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
-
fileName | Name 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]
- Parameters
-
fileName | Name of the file to write the serialized content representing this tree. |
io | The 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.
◆ DOCUMENT_NAME
const QString DOCUMENT_NAME = "serializeddata" |
|
static |