ConfigurationNode Class Reference

A node in the configuration tree. More...

Classes

struct  ObjectAndStatus
 The structure with the object for a node and its status. More...
 

Public Member Functions

 ConfigurationNode (ConfigurationNode *parent, QString name=QString(), bool caseSensitive=false)
 Constructor. This creates an empty node.
 
 ~ConfigurationNode ()
 Destructor. This also destroys child nodes.
 
ConfigurationNodeaddNode (QString name)
 Adds a child node with the given name and returns a pointer to it.
 
bool addParameter (QString name)
 Adds a new parameter.
 
void clearAll ()
 Deletes all children and parameters.
 
bool deleteNode (QString name)
 Removes the child node with the given name.
 
bool deleteParameter (QString name)
 Deletes a parameter.
 
QList< const ConfigurationNode * > getAncestors () const
 Returns a list of pointers to ancestor nodes.
 
QStringList getAncestorsNames () const
 Returns a list of names of ancestor nodes.
 
QStringList getChildrenList () const
 Returns the list of child nodes (the list of names)
 
QList< ConfigurationNode * > getChildrenNodesList ()
 Returns the list of child nodes.
 
QStringList getFilteredChildrenList (QRegExp filter) const
 Returns the list of child nodes whose name matches the given regular expression.
 
QStringList getFilteredObjectParametersList (QRegExp filter) const
 Returns the list of parameters referring to objects.
 
QStringList getFilteredParametersList (QRegExp filter) const
 Returns the list of parameters whose name matches the given regular expression.
 
QString getFullName () const
 Returns the full name of the node (i.e. the full path from root to this node)
 
QString getName () const
 Returns the name of the node.
 
ConfigurationNodegetNode (QString path)
 Returns a pointer to the node having the given path.
 
const ConfigurationNodegetNode (QString path) const
 Returns a pointer to the node having the given path (const version)
 
ObjectAndStatus getObject (QString path, bool alsoMatchParents=false) const
 Returns the object to which the parameter with the given path refer.
 
ObjectAndStatus getObjectForNode (QString path) const
 Returns the object corresponding to the given node.
 
QStringList getObjectParametersList () const
 Returns the list of parameters referring to objects.
 
QStringList getParametersList () const
 Returns the list of parameter names.
 
const ConfigurationNodegetParent () const
 Returns the parent node.
 
QString getValue (QString path, bool alsoMatchParents=false) const
 Returns the value of the parameter with the given path.
 
bool isCaseSensitive () const
 Returns true if we behave in a case sensitive way.
 
bool isNull () const
 Returns true if this is a NULL node.
 
bool renameNode (QString oldName, QString newName)
 Rename the child node with the new given name.
 
void resetObject ()
 Resets the object for this node.
 
bool setObjectForNode (QString path, ParameterSettable *object, ObjectCreationStatus status=ObjectCreatedAndConfigured)
 Sets the object corresponding to the given node to object.
 
bool setValue (QString path, QString value)
 Sets the value of the parameter with the given path.
 
bool setValue (QString path, ParameterSettable *object)
 Sets the value of the parameter with the given path to point to an object.
 

Detailed Description

A node in the configuration tree.

This can contain other nodes or parameters (name-value pairs). When specifying the node or parameter you can use a path from the current node through child nodes.

Note
A null node is a node with a null name (i.e. a node with a null name string). A null node cannot be modified (i.e. you cannod add/remove children or parameters)

Definition at line 64 of file configurationnode.h.

Constructor & Destructor Documentation

ConfigurationNode ( ConfigurationNode parent,
QString  name = QString(),
bool  caseSensitive = false 
)

Constructor. This creates an empty node.

Parameters
parentthe parent node (NULL if we have no parent)
namethe name of the node. If this is the empty string, or if it is equal to the group separator or the parent group, this group will be the null group
caseSensitiveif true parameters and nodes names are considered as being case sensitive, otherwise case insensitive

Definition at line 27 of file configurationnode.cpp.

Referenced by ConfigurationNode::addNode().

Destructor. This also destroys child nodes.

Definition at line 42 of file configurationnode.cpp.

References ConfigurationNode::clearAll().

Member Function Documentation

ConfigurationNode * addNode ( QString  name)

Adds a child node with the given name and returns a pointer to it.

If the node already exists, the already existing node is returned

Parameters
namethe name of the child node
Returns
a pointer to the new node

Definition at line 103 of file configurationnode.cpp.

References ConfigurationNode::ConfigurationNode(), ConfigurationParameters::GroupSeparator(), ConfigurationNode::isNull(), and ConfigurationParameters::ParentGroup().

Referenced by ConfigurationParameters::createGroup().

bool addParameter ( QString  name)

Adds a new parameter.

The value for the new parameter is the empty string (i.e. "")

Parameters
namethe name of the parameter
Returns
true if parameter was added, false if a parameter with the given name already existed

Definition at line 260 of file configurationnode.cpp.

References ConfigurationParameters::GroupSeparator(), ConfigurationNode::isNull(), and ConfigurationParameters::ParentGroup().

Referenced by ConfigurationParameters::createParameter().

void clearAll ( )

Deletes all children and parameters.

Definition at line 505 of file configurationnode.cpp.

References ConfigurationNode::isNull().

Referenced by ConfigurationNode::getNode(), and ConfigurationNode::~ConfigurationNode().

bool deleteNode ( QString  name)

Removes the child node with the given name.

Parameters
namethe name of the child node to remove
Returns
true if the node exists, false otherwise

Definition at line 163 of file configurationnode.cpp.

References ConfigurationNode::isNull().

bool deleteParameter ( QString  name)

Deletes a parameter.

Parameters
namethe name of the parameter to remove
Returns
true if parameter was removed, false if no parameter with that name exists

Definition at line 466 of file configurationnode.cpp.

References ConfigurationNode::isNull().

Referenced by ConfigurationParameters::deleteParameter().

QList< const ConfigurationNode * > getAncestors ( ) const

Returns a list of pointers to ancestor nodes.

The last element of the list is this node

Returns
a list of pointers to ancestor nodes, from root down to this node

Definition at line 51 of file configurationnode.cpp.

References ConfigurationNode::getAncestors(), and ConfigurationNode::isNull().

Referenced by ConfigurationNode::getAncestors().

QStringList getAncestorsNames ( ) const

Returns a list of names of ancestor nodes.

The last element of the list is this node

Returns
a list of names of ancestor nodes, from root down to this node

Definition at line 69 of file configurationnode.cpp.

References ConfigurationNode::getAncestorsNames(), and ConfigurationNode::isNull().

Referenced by ConfigurationNode::getAncestorsNames().

QStringList getChildrenList ( ) const

Returns the list of child nodes (the list of names)

Returns
the list of names of child nodes

Definition at line 214 of file configurationnode.cpp.

QList< ConfigurationNode * > getChildrenNodesList ( )

Returns the list of child nodes.

Returns
the list of child nodes

Definition at line 209 of file configurationnode.cpp.

Referenced by ConfigurationParameters::resetGroupObjectAssociations(), and ConfigurationParameters::updateObjectReferences().

QStringList getFilteredChildrenList ( QRegExp  filter) const

Returns the list of child nodes whose name matches the given regular expression.

Parameters
filterthe regular expression that must be matched by child names
Returns
the filtered list of names of child nodes

Definition at line 219 of file configurationnode.cpp.

QStringList getFilteredObjectParametersList ( QRegExp  filter) const

Returns the list of parameters referring to objects.

Parameters
filterthe regular expression that must be matched by parameters names
Returns
the list of names of parameters referring to objects

Definition at line 500 of file configurationnode.cpp.

QStringList getFilteredParametersList ( QRegExp  filter) const

Returns the list of parameters whose name matches the given regular expression.

The list includes also the parameters referring to objects

Parameters
filterthe regular expression that must be matched by parameters names
Returns
the filtered list of names of parameters

Definition at line 489 of file configurationnode.cpp.

QString getFullName ( ) const

Returns the full name of the node (i.e. the full path from root to this node)

Returns
the full name of the node

Definition at line 89 of file configurationnode.cpp.

References ConfigurationNode::getFullName(), ConfigurationParameters::GroupSeparator(), and ConfigurationNode::isNull().

Referenced by ConfigurationNode::getFullName(), and ConfigurationParameters::updateObjectReferences().

QString getName ( ) const
inline

Returns the name of the node.

Returns
the name of the node

Definition at line 168 of file configurationnode.h.

ConfigurationNode * getNode ( QString  path)

Returns a pointer to the node having the given path.

The path is relative to this node

Parameters
paththe path of the node to return. The empty string is the current node
Returns
the node with the given path or a null node if no node with the given path exists

Definition at line 126 of file configurationnode.cpp.

Referenced by ConfigurationNode::getObjectForNode(), and ConfigurationNode::setObjectForNode().

const ConfigurationNode * getNode ( QString  path) const

Returns a pointer to the node having the given path (const version)

The path is relative to this node

Parameters
paththe path of the node to return. The empty string is the current node
Returns
the node with the given path or a null node if no node with the given path exists

Definition at line 132 of file configurationnode.cpp.

References ConfigurationNode::clearAll(), ConfigurationParameters::GroupSeparator(), ConfigurationNode::isNull(), and ConfigurationParameters::ParentGroup().

ConfigurationNode::ObjectAndStatus getObject ( QString  path,
bool  alsoMatchParents = false 
) const

Returns the object to which the parameter with the given path refer.

The path is relative to this node

Parameters
paththe path of the parameter (starting from this node)
alsoMatchParentsif true, the parameter is first searched in the given path then, if it is not found, it is searched back in parent groups until found or the main group is reached. If false the parameter is only searched in the given path
Returns
a structure containing a pointer to the object and the status for the object. The object in the structure is NULL in case of error
Note
if alsoMatchParents is true and the path contains "..", the object is searched in any of the traversed groups (also in subgroups). So, for example, if you have the following structure:
[GROUP_A]
param1 = obj1
[GROUP_A/GROUP_B]
param2 = obj2

and call getObject("GROUP_A/GROUP_B/../param2", true), you will get the value of param2 inside GROUP_A/GROUP_B

Definition at line 336 of file configurationnode.cpp.

References ConfigurationNode::getObject(), ConfigurationParameters::GroupSeparator(), ConfigurationNode::isNull(), and ConfigurationParameters::ParentGroup().

Referenced by ConfigurationNode::getObject(), and ConfigurationParameters::updateObjectReferences().

ConfigurationNode::ObjectAndStatus getObjectForNode ( QString  path) const

Returns the object corresponding to the given node.

Parameters
paththe path of the node whose corresponding object has to be set (relative to this node)
Returns
the object for the given node and its status. The object field of the returned structure is NULL in case of errors

Definition at line 248 of file configurationnode.cpp.

References ConfigurationNode::getNode(), and ConfigurationNode::isNull().

Referenced by ConfigurationParameters::getObjectFromGroup(), and ConfigurationParameters::updateObjectReferences().

QStringList getObjectParametersList ( ) const

Returns the list of parameters referring to objects.

Returns
the list of names of parameters referring to objects

Definition at line 494 of file configurationnode.cpp.

Referenced by ConfigurationParameters::updateObjectReferences().

QStringList getParametersList ( ) const

Returns the list of parameter names.

The list includes also the parameters referring to objects

Returns
the list of names of parameters

Definition at line 483 of file configurationnode.cpp.

const ConfigurationNode* getParent ( ) const
inline

Returns the parent node.

Returns
the parent node

Definition at line 140 of file configurationnode.h.

QString getValue ( QString  path,
bool  alsoMatchParents = false 
) const

Returns the value of the parameter with the given path.

The path is relative to this node

Parameters
paththe path of the parameter (starting from this node)
alsoMatchParentsif true, the parameter is first searched in the given path then, if it is not found, it is searched back in parent groups until found or the main group is reached. If false the parameter is only searched in the given path
Returns
the parameter value or an empty string if no such parameter exists
Note
if alsoMatchParents is true and the path contains "..", the parameter is searched in any of the traversed groups (also in subgroups). So, for example, if you have the following structure:
[GROUP_A]
param1 = value1
[GROUP_A/GROUP_B]
param2 = value2

and call getValue("GROUP_A/GROUP_B/../param2", true), you will get the value of param2 inside GROUP_A/GROUP_B

Definition at line 279 of file configurationnode.cpp.

References ConfigurationNode::getValue(), ConfigurationParameters::GroupSeparator(), ConfigurationNode::isNull(), and ConfigurationParameters::ParentGroup().

Referenced by ConfigurationNode::getValue().

bool isCaseSensitive ( ) const
inline

Returns true if we behave in a case sensitive way.

Returns
true if we behave in a case sensitive way

Definition at line 196 of file configurationnode.h.

bool renameNode ( QString  oldName,
QString  newName 
)

Rename the child node with the new given name.

Parameters
oldNameis the current name of the child node to rename
newNameis the new name to assign to the child node
Returns
true if the node has been renamed, false otherwise

Definition at line 182 of file configurationnode.cpp.

References ConfigurationParameters::GroupSeparator(), ConfigurationNode::isNull(), and ConfigurationParameters::ParentGroup().

void resetObject ( )

Resets the object for this node.

This sets the object to NULL and the object status to ObjectNotCreated

Definition at line 242 of file configurationnode.cpp.

References ConfigurationNode::ObjectAndStatus::object, and ConfigurationNode::ObjectAndStatus::objectStatus.

Referenced by ConfigurationParameters::resetGroupObjectAssociations().

bool setObjectForNode ( QString  path,
ParameterSettable object,
ObjectCreationStatus  status = ObjectCreatedAndConfigured 
)

Sets the object corresponding to the given node to object.

This is const because it can be called on const nodes

Parameters
paththe path of the node whose corresponding object has to be set (relative to this node)
objectthe object corresponding to the given node. If is is NULL and status is not CreatingObject, only the status of the current object is changed; otherwise the object for the node is set to the value of object.
statusthe status of the object
Returns
false in case of error (e.g. path is a property, not a node)

Definition at line 224 of file configurationnode.cpp.

References ConfigurationNode::getNode(), ConfigurationNode::isNull(), ConfigurationNode::ObjectAndStatus::object, and ConfigurationNode::ObjectAndStatus::objectStatus.

Referenced by ConfigurationParameters::getObjectFromGroup().

bool setValue ( QString  path,
QString  value 
)

Sets the value of the parameter with the given path.

The path is relative to this node

Parameters
paththe path of the parameter (starting from this node)
valuethe new value for the parameter
Returns
false if the parameter doesn't exists, true otherwise

Definition at line 393 of file configurationnode.cpp.

References ConfigurationParameters::GroupSeparator(), ConfigurationNode::isNull(), ConfigurationParameters::ParentGroup(), and ConfigurationNode::setValue().

Referenced by ConfigurationNode::setValue(), and ConfigurationParameters::updateObjectReferences().

bool setValue ( QString  path,
ParameterSettable object 
)

Sets the value of the parameter with the given path to point to an object.

The path is relative to this node

Parameters
paththe path of the parameter (starting from this node)
objectthe object to which the parameter refer
Returns
false if the parameter doesn't exists, true otherwise

Definition at line 428 of file configurationnode.cpp.

References ConfigurationParameters::GroupSeparator(), ConfigurationNode::isNull(), ConfigurationParameters::ParentGroup(), and ConfigurationNode::setValue().


The documentation for this class was generated from the following files: