![]() |
Workspace 7.0.2
|
Class to hold a serialized representation of an object. More...
#include <Workspace/DataExecution/Serialization/serializeditem.h>
Public Member Functions | |
SerializedItem (const SerializedItem &sData) | |
~SerializedItem () | |
SerializedItem | addChild (const QString &tag) |
SerializedItem | addChildCopy (const SerializedItem &item) |
SerializedItem | addComment (const QString &comment) |
void | clear () |
void | deepCopy (const SerializedItem &item) |
SerializedItem | firstChild (const QString &tag=QString()) const |
bool | getAttribute (const QString &key, bool &value) const |
bool | getAttribute (const QString &key, double &value) const |
bool | getAttribute (const QString &key, int &value) const |
bool | getAttribute (const QString &key, QString &value) const |
bool | getAttribute (const QString &key, QVariant &value) const |
bool | getAttribute (const QString &key, unsigned &value) const |
QStringList | getAttributeKeys () const |
QString | getSubtreeAsString () const |
QString | getSubtreeAsString (SerializedTreeIO &io) const |
QString | getTagName () const |
QString | getText () const |
void | getText (QVariant &value) const |
bool | hasAttribute (const QString &key) const |
bool | hasAttributes () const |
bool | hasChildren () const |
bool | isEmpty (const QStringList &ignoredAttributes=QStringList()) const |
bool | isNull () const |
bool | isSameItem (const SerializedItem &item) const |
bool | isSameTree (const SerializedItem &item) const |
SerializedItem | nextSibling (const QString &=QString()) const |
SerializedItem & | operator= (const SerializedItem &item) |
SerializedItem | previousSibling (const QString &=QString()) const |
void | removeAllChildren () |
void | removeAllChildren (const QString &tag) |
void | removeAttribute (const QString &key) |
void | removeChild (const SerializedItem &child) |
void | setAttribute (const QString &key, bool value) |
void | setAttribute (const QString &key, const char *value) |
void | setAttribute (const QString &key, const QString &value) |
void | setAttribute (const QString &key, double value) |
void | setAttribute (const QString &key, int value) |
void | setAttribute (const QString &key, unsigned value) |
void | setTagName (const QString &tag) |
void | setText (const QString &str) |
Static Public Member Functions | |
static QString | getTagName (const QString &str) |
This class holds a hierarchical representation of serialized objects. Each object can have child objects and/or its own block of text, although it would be rare for an object to have both.
The SerializedItem class is actually just a handle into the underlying tree. There can be multiple handles to the same point in the underlying tree. Indeed, copying a SerializedItem object simply creates another handle to the same point in the tree, and modifying the data through one handle also changes the data for the other handles to that item.
From the preceding paragraph, it can be seen that copying a SerializedItem is cheap, since it is only a shallow copy (ie just a data handle is copied and not the data itself).
SerializedItem | ( | const SerializedItem & | sData | ) |
sData | An existing serialized data handle. |
Constructs another handle to whatever data is a handle for.
~SerializedItem | ( | ) |
SerializedItem addChild | ( | const QString & | tag | ) |
tag | The name of the data item to create as a child of this one. Valid characters are upper and lowercase letters, numbers and underscores. The first character must be a letter. Spaces will be automatically converted to underscores. It should be explicitly noted that periods (.), colons (:) and slashes (/ and \) are not allowed. |
SerializedItem addChildCopy | ( | const SerializedItem & | item | ) |
item | The item to copy and append as a child to this item. |
The purpose of this function is to make a deep copy of item and append it as a child of this item. All of item's children will be included in the deep copy.
SerializedItem addComment | ( | const QString & | comment | ) |
void clear | ( | ) |
void deepCopy | ( | const SerializedItem & | item | ) |
item | The source item to copy. |
The purpose of this function is to make a deep copy of item and make the current item that deep copy. The current item is first cleared by removing all its attributes, children and text. The attributes and text of item are then copied across along with deep copies of each child of item. If either this item or the item to be copied is null, then this item will be null when the function returns.
SerializedItem firstChild | ( | const QString & | tag = QString() | ) | const |
tag | The tag name to search for among the immediate children only. |
bool getAttribute | ( | const QString & | key, |
bool & | value | ||
) | const |
key | The name of the attribute to retrieve. |
value | Where to store the value of the attribute. |
If this is a null item, then this function will always fail since null items cannot have attributes.
bool getAttribute | ( | const QString & | key, |
double & | value | ||
) | const |
key | The name of the attribute to retrieve. |
value | Where to store the value of the attribute. |
If this is a null item, then this function will always fail since null items cannot have attributes.
bool getAttribute | ( | const QString & | key, |
int & | value | ||
) | const |
key | The name of the attribute to retrieve. |
value | Where to store the value of the attribute. |
If this is a null item, then this function will always fail since null items cannot have attributes.
bool getAttribute | ( | const QString & | key, |
QString & | value | ||
) | const |
key | The name of the attribute to retrieve. |
value | Where to store the value of the attribute. |
If this is a null item, then this function will always fail since null items cannot have attributes.
bool getAttribute | ( | const QString & | key, |
QVariant & | value | ||
) | const |
key | The name of the attribute to retrieve. |
value | Where to store the value of the attribute. |
If this is a null item, then this function will always fail since null items cannot have attributes.
bool getAttribute | ( | const QString & | key, |
unsigned & | value | ||
) | const |
key | The name of the attribute to retrieve. |
value | Where to store the value of the attribute. |
If this is a null item, then this function will always fail since null items cannot have attributes.
QStringList getAttributeKeys | ( | ) | const |
QString getSubtreeAsString | ( | ) | const |
This function allows you to output part of a tree to a string as an XML fragment.
QString getSubtreeAsString | ( | SerializedTreeIO & | io | ) | const |
io | The input / output for the "to string" operation. Allows the calling code to request the string in different formats. |
This function allows you to output part of a tree to a string as a string following the format of io.
QString getTagName | ( | ) | const |
|
static |
str | The string for which the equivalent tag name is needed. |
All characters not in the allowable character set are converted to underscores. The allowable character set includes all letters (both upper and lower case), numbers and underscores. In addition, a tag must begin with a letter, so if str does not, the string "tag_" will be prepended. The one exception is that if str is empty, then the string "tag" will be returned.
QString getText | ( | ) | const |
The text data is usually only present for a SerializedItem object with no children. The leaf nodes of the underlying tree will store their data as text, which can be retrieved with this function.
void getText | ( | QVariant & | value | ) | const |
value | The text data of this SerializedItem. If the text is a bool or numerical value, the correct QVariant type will be set for this parameter. |
bool hasAttribute | ( | const QString & | key | ) | const |
bool hasAttributes | ( | ) | const |
bool hasChildren | ( | ) | const |
bool isEmpty | ( | const QStringList & | ignoredAttributes = QStringList() | ) | const |
bool isNull | ( | ) | const |
A null SerializedItem object should only ever be encountered through a returned value from previousSibling(), nextSibling() or firstChild().
bool isSameItem | ( | const SerializedItem & | item | ) | const |
item | The item to test. |
bool isSameTree | ( | const SerializedItem & | item | ) | const |
item | The item to test. |
SerializedItem nextSibling | ( | const QString & | tag = QString() | ) | const |
tag | The tag name for the next sibling to return. If this is empty, then the next sibling will be returned regardless of its tag. |
SerializedItem & operator= | ( | const SerializedItem & | item | ) |
item | SerializedItem object to copy to this one. |
The assignment operator makes a shallow copy of item, meaning that they point to the same thing in the serialized tree.
SerializedItem previousSibling | ( | const QString & | tag = QString() | ) | const |
tag | The tag name for the previous sibling to return. If this is empty, then the previous sibling will be returned regardless of its tag. |
void removeAllChildren | ( | ) |
void removeAllChildren | ( | const QString & | tag | ) |
void removeAttribute | ( | const QString & | key | ) |
key | The attribute to remove from the item. If no attribute with this name exists, this function has no effect. |
void removeChild | ( | const SerializedItem & | child | ) |
void setAttribute | ( | const QString & | key, |
bool | value | ||
) |
key | The name of the attribute to set. If it does not yet exist for this data object, it will be created. |
value | The value to assign to the named attribute. |
void setAttribute | ( | const QString & | key, |
const char * | value | ||
) |
key | The name of the attribute to set. If it does not yet exist for this data object, it will be created. |
value | The value to assign to the named attribute. |
This particular overload is needed because, according to the C++ standard, a pointer has an implicit conversion to bool. Therefore, if a const
string is used for value and the const
char*
overload did not exist, it would erroneously call the bool
overload instead of the String overload.
void setAttribute | ( | const QString & | key, |
const QString & | value | ||
) |
key | The name of the attribute to set. If it does not yet exist for this data object, it will be created. |
value | The value to assign to the named attribute. |
void setAttribute | ( | const QString & | key, |
double | value | ||
) |
key | The name of the attribute to set. If it does not yet exist for this data object, it will be created. |
value | The value to assign to the named attribute. |
void setAttribute | ( | const QString & | key, |
int | value | ||
) |
key | The name of the attribute to set. If it does not yet exist for this data object, it will be created. |
value | The value to assign to the named attribute. |
void setAttribute | ( | const QString & | key, |
unsigned | value | ||
) |
key | The name of the attribute to set. If it does not yet exist for this data object, it will be created. |
value | The value to assign to the named attribute. |
void setTagName | ( | const QString & | tag | ) |
tag | The tag name for this object. |
This function should be used with care. A number of classes using SerializedItem objects rely on siblings having unique tag names. This condition is usually only checked when a child is added, so changing the tag name may result in such assumptions being violated. Callers of setTagName must ensure that they do not break any such assumptions before making the call.
void setText | ( | const QString & | str | ) |
str | A string holding the text data to associate with this SerializedItem object. |
The text data is usually only present for a SerializedItem object with no children. The leaf nodes of the underlying tree will store their data as text using this function.
The string str should pretty much be able to contain anything in the normal character set. Internally, some characters will be encoded (such as the less-than (<) character), but these are re-converted back to their original form when getText is called.