00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef CONFIGURATION_NODE_H
00022 #define CONFIGURATION_NODE_H
00023
00024 #include "configurationconfig.h"
00025 #include <QMap>
00026 #include <QString>
00027 #include <QStringList>
00028
00029 namespace farsa {
00030
00031 class ParameterSettable;
00032
00037 enum ObjectCreationStatus {
00038 ObjectNotCreated,
00039 CreatingObject,
00040 ObjectCreatedNotConfigured,
00042 ConfiguringObject,
00044 CreatingAndConfiguringObject,
00048 ObjectCreatedAndConfigured
00050 };
00051
00064 class FARSA_CONF_API ConfigurationNode
00065 {
00066 public:
00070 struct ObjectAndStatus
00071 {
00075 ObjectAndStatus() :
00076 object(NULL),
00077 objectStatus(ObjectNotCreated)
00078 {
00079 }
00080
00084 ObjectAndStatus(const ObjectAndStatus& other) :
00085 object(other.object),
00086 objectStatus(other.objectStatus)
00087 {
00088 }
00089
00093 ObjectAndStatus& operator=(const ObjectAndStatus& other)
00094 {
00095 if (this == &other) {
00096 return *this;
00097 }
00098
00099 object = other.object;
00100 objectStatus = other.objectStatus;
00101
00102 return *this;
00103 }
00104
00108 ParameterSettable *object;
00109
00113 ObjectCreationStatus objectStatus;
00114 };
00115
00116 public:
00128 ConfigurationNode(ConfigurationNode *parent, QString name = QString(), bool caseSensitive = false);
00129
00133 ~ConfigurationNode();
00134
00140 const ConfigurationNode* getParent() const
00141 {
00142 return m_parent;
00143 }
00144
00152 QList<const ConfigurationNode*> getAncestors() const;
00153
00161 QStringList getAncestorsNames() const;
00162
00168 QString getName() const
00169 {
00170 return m_name;
00171 }
00172
00179 QString getFullName() const;
00180
00186 bool isNull() const
00187 {
00188 return m_name.isNull();
00189 }
00190
00196 bool isCaseSensitive() const
00197 {
00198 return m_caseSensitive;
00199 }
00200
00209 ConfigurationNode* addNode(QString name);
00210
00220 ConfigurationNode* getNode(QString path);
00221
00232 const ConfigurationNode* getNode(QString path) const;
00233
00240 bool deleteNode(QString name);
00241
00249 bool renameNode(QString oldName, QString newName);
00250
00256 QList<ConfigurationNode*> getChildrenNodesList();
00257
00263 QStringList getChildrenList() const;
00264
00273 QStringList getFilteredChildrenList(QRegExp filter) const;
00274
00288 bool setObjectForNode(QString path, ParameterSettable* object, ObjectCreationStatus status = ObjectCreatedAndConfigured);
00289
00296 void resetObject();
00297
00306 ObjectAndStatus getObjectForNode(QString path) const;
00307
00316 bool addParameter(QString name);
00317
00346 QString getValue(QString path, bool alsoMatchParents = false) const;
00347
00378 ObjectAndStatus getObject(QString path, bool alsoMatchParents = false) const;
00379
00388 bool setValue(QString path, QString value);
00389
00399 bool setValue(QString path, ParameterSettable* object);
00400
00408 bool deleteParameter(QString name);
00409
00416 QStringList getParametersList() const;
00417
00427 QStringList getFilteredParametersList(QRegExp filter) const;
00428
00434 QStringList getObjectParametersList() const;
00435
00443 QStringList getFilteredObjectParametersList(QRegExp filter) const;
00444
00448 void clearAll();
00449
00450 private:
00454 ConfigurationNode *const m_parent;
00455
00460 const bool m_caseSensitive;
00461
00465 const QString m_name;
00466
00472 mutable ConfigurationNode* m_nullNode;
00473
00477 mutable QString m_nullValue;
00478
00482 ObjectAndStatus m_object;
00483
00487 QMap<QString, ConfigurationNode*> m_children;
00488
00492 QStringList m_childrenkeys;
00493
00497 QMap<QString, QString> m_parameters;
00498
00502 QStringList m_parameterskeys;
00503
00507 QMap<QString, ObjectAndStatus> m_objectParameters;
00508
00512 ConfigurationNode(const ConfigurationNode &);
00513
00517 ConfigurationNode& operator=(const ConfigurationNode &);
00518 };
00519
00520 }
00521
00522 #endif