Class for handling configuration files. More...
#include <ConfigManager.h>
Public Member Functions | |
void | addParameter (const ConfigParameter ¶meter) |
void | addParameter (const ConfigParameterList ¶meters) |
void | addParameter (const ConfigPositionalParameter ¶meter) |
void | addParameter (const ConfigPositionalParameterList ¶meters) |
void | dump () const |
bool | initialize () |
bool | isInitialized () const |
void | registerObserver (ConfigObserver *observer, const String &key="") |
template<class T > | |
bool | setValue (const icl_core::String &key, typename icl_core::ConvertToRef< T >::ToConstRef value) |
Add a key/value pair or change a value. In contrast to Insert, this method notifies observers. | |
void | unregisterObserver (ConfigObserver *observer) |
Static Public Member Functions | |
static ConfigManager & | instance () |
Private Types | |
typedef icl_core::Map < icl_core::String, icl_core::List< ConfigObserver * > > | ObserverMap |
Private Member Functions | |
ConfigManager () | |
Creates an empty configuration object. | |
bool | load (const icl_core::String &filename) |
Reads configuration from a file. | |
void | notify (const icl_core::String &key) const |
Notify all observers about a changed key/value pair. | |
void | readAttributeTree (const icl_core::String &prefix, AttributeTree *at, bool extend_prefix=true) |
void | readXml (const ::icl_core::String &prefix, TiXmlNode *node, FilePath fp, bool extend_prefix=true) |
Private Attributes | |
bool | m_initialized |
ObserverMap | m_observers |
ConfigParameterList | m_parameter_list |
ConfigPositionalParameterList | m_postional_parameter_list |
Class for handling configuration files.
ConfigManager is implemented as a singleton so that it can be used from anywhere without the need to pass a config object around.
Before the configuration class can be used it has to be initialized through a call to Initialize(). It will parse the command line and look for a "-c [filename]" or "--configfile=[filename]" option. ConfigManager will try to read the specified file and extract all configuration attributes from it.
Configuration files are XML files. The names of the XML tags are used as the names of the configuration attributes while the content text of the XML tags are used as the attributes' values. Leading and trailing whitespace is automatically removed from the values. Remark: The name of the root element in the configuration file can be chosen arbitrarily. It is not or interpreted from ConfigManager in any way.
Configuration attributes are retrieved using an XPath like syntax. Hierarchical attribute names are separated by "/".
Definition at line 79 of file ConfigManager.h.
typedef icl_core::Map<icl_core::String, icl_core::List<ConfigObserver*> > icl_core::config::ConfigManager::ObserverMap [private] |
Definition at line 239 of file ConfigManager.h.
icl_core::config::ConfigManager::ConfigManager | ( | ) | [private] |
Creates an empty configuration object.
Definition at line 178 of file ConfigManager.cpp.
void icl_core::config::ConfigManager::addParameter | ( | const ConfigParameter & | parameter | ) |
Adds a commandline parameter.
Definition at line 47 of file ConfigManager.cpp.
void icl_core::config::ConfigManager::addParameter | ( | const ConfigParameterList & | parameters | ) |
Adds a list of commandline parameters.
Definition at line 59 of file ConfigManager.cpp.
void icl_core::config::ConfigManager::addParameter | ( | const ConfigPositionalParameter & | parameter | ) |
Adds a positional commandline parameter.
Definition at line 67 of file ConfigManager.cpp.
void icl_core::config::ConfigManager::addParameter | ( | const ConfigPositionalParameterList & | parameters | ) |
Adds a list of positional commandline parameters.
Definition at line 79 of file ConfigManager.cpp.
void icl_core::config::ConfigManager::dump | ( | ) | const |
Dumps all configuration keys and the corresponding values to stdout.
Definition at line 167 of file ConfigManager.cpp.
Initializes ConfigManager. Reads the configuration file if --configfile or -c has been specified on the commandline. If no configuration file has been specified, the initialization is treated as successful!
Definition at line 87 of file ConfigManager.cpp.
ConfigManager & icl_core::config::ConfigManager::instance | ( | ) | [static] |
Get the singleton ConfigManager instance.
Definition at line 41 of file ConfigManager.cpp.
bool icl_core::config::ConfigManager::isInitialized | ( | ) | const [inline] |
Check if the configuration framework has already been initialized.
Definition at line 120 of file ConfigManager.h.
bool icl_core::config::ConfigManager::load | ( | const icl_core::String & | filename | ) | [private] |
Reads configuration from a file.
Definition at line 189 of file ConfigManager.cpp.
void icl_core::config::ConfigManager::notify | ( | const icl_core::String & | key | ) | const [private] |
Notify all observers about a changed key/value pair.
Definition at line 405 of file ConfigManager.cpp.
void icl_core::config::ConfigManager::readAttributeTree | ( | const icl_core::String & | prefix, |
AttributeTree * | at, | ||
bool | extend_prefix = true |
||
) | [private] |
Definition at line 271 of file ConfigManager.cpp.
void icl_core::config::ConfigManager::readXml | ( | const ::icl_core::String & | prefix, |
TiXmlNode * | node, | ||
FilePath | fp, | ||
bool | extend_prefix = true |
||
) | [private] |
Definition at line 232 of file ConfigManager.cpp.
void icl_core::config::ConfigManager::registerObserver | ( | ConfigObserver * | observer, |
const String & | key = "" |
||
) |
! Register an observer which gets notified of changed key/value pairs
observer | The observer to add to the list of registered observers |
key | The key to be notified of, or an empty string for all changes |
Definition at line 298 of file ConfigManager.cpp.
bool icl_core::config::ConfigManager::setValue | ( | const icl_core::String & | key, |
typename icl_core::ConvertToRef< T >::ToConstRef | value | ||
) | [inline] |
Add a key/value pair or change a value. In contrast to Insert, this method notifies observers.
Definition at line 133 of file ConfigManager.h.
void icl_core::config::ConfigManager::unregisterObserver | ( | ConfigObserver * | observer | ) |
Unregister an observer so it does not get notified of changes anymore. Normally you shouldn't need to call this as the destructor of config observers automatically calls it
Definition at line 318 of file ConfigManager.cpp.
bool icl_core::config::ConfigManager::m_initialized [private] |
Definition at line 234 of file ConfigManager.h.
Definition at line 240 of file ConfigManager.h.
Definition at line 236 of file ConfigManager.h.
Definition at line 237 of file ConfigManager.h.