Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
icl_core::config::ConfigManager Class Reference

Class for handling configuration files. More...

#include <ConfigManager.h>

Inheritance diagram for icl_core::config::ConfigManager:
Inheritance graph
[legend]

Public Member Functions

void addParameter (const ConfigParameter &parameter)
 
void addParameter (const ConfigParameterList &parameters)
 
void addParameter (const ConfigPositionalParameter &parameter)
 
void addParameter (const ConfigPositionalParameterList &parameters)
 
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. More...
 
void unregisterObserver (ConfigObserver *observer)
 
- Public Member Functions inherited from icl_core::KeyValueDirectory< icl_core::String >
KeyValueDirectoryIterator< icl_core::Stringfind (const String &query) const
 
bool get (const String &key, typename ConvertToRef< icl_core::String >::ToRef value) const
 
bool hasKey (const String &key) const
 
bool insert (const String &key, typename ConvertToRef< icl_core::String >::ToConstRef value)
 

Static Public Member Functions

static ConfigManagerinstance ()
 

Private Types

typedef icl_core::Map< icl_core::String, icl_core::List< ConfigObserver * > > ObserverMap
 

Private Member Functions

 ConfigManager ()
 Creates an empty configuration object. More...
 
bool load (const icl_core::String &filename)
 Reads configuration from a file. More...
 
void notify (const icl_core::String &key) const
 Notify all observers about a changed key/value pair. More...
 
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
 

Detailed Description

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.

Member Typedef Documentation

Definition at line 239 of file ConfigManager.h.

Constructor & Destructor Documentation

icl_core::config::ConfigManager::ConfigManager ( )
private

Creates an empty configuration object.

Definition at line 178 of file ConfigManager.cpp.

Member Function Documentation

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.

bool icl_core::config::ConfigManager::initialize ( )

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!

Returns
true if the initialization was successful, false otherwise. If the initialization fails, an error message will be printed to stderr.

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

Parameters
observerThe observer to add to the list of registered observers
keyThe key to be notified of, or an empty string for all changes

Definition at line 298 of file ConfigManager.cpp.

template<class T >
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.

Member Data Documentation

bool icl_core::config::ConfigManager::m_initialized
private

Definition at line 234 of file ConfigManager.h.

ObserverMap icl_core::config::ConfigManager::m_observers
private

Definition at line 240 of file ConfigManager.h.

ConfigParameterList icl_core::config::ConfigManager::m_parameter_list
private

Definition at line 236 of file ConfigManager.h.

ConfigPositionalParameterList icl_core::config::ConfigManager::m_postional_parameter_list
private

Definition at line 237 of file ConfigManager.h.


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


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:59