SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
SeComLib::Utils::Config Class Reference

Utilitary class for parsing the configuration file. More...

#include <config.h>

Public Member Functions

template<typename T >
GetParameter (const std::string &parameter) const
 Template method which returns the value of the specified configuration parameter. More...
 
template<typename T >
GetParameter (const std::string &parameter, const T &defaultValue) const
 Template method which returns the value of the specified configuration parameter, or defaults to defaultValue. More...
 

Static Public Member Functions

static ConfigGetInstance ()
 Returns a reference to the singleton. More...
 
static void SetConfigFile (const std::string &configFile)
 Sets the location and name of the configuration file. More...
 

Private Member Functions

 Config ()
 
 ~Config ()
 Destructor - void implementation.
 
 Config (Config const &)
 Copy constructor - not implemented.
 
Config operator= (Config const &)
 Copy assignment operator - not implemented.
 

Private Attributes

boost::property_tree::ptree propertyTree
 The internal mapping of the XML configuration file.
 

Static Private Attributes

static std::string configFile
 The location of the configuration file. More...
 
static const std::string xmlRootElementName
 The name of the root node in the configuration XML file. More...
 

Detailed Description

Utilitary class for parsing the configuration file.

Works as a singleton: Config::GetInstance().DoStuff()

Definition at line 49 of file config.h.

Constructor & Destructor Documentation

SeComLib::Utils::Config::Config ( )
private

Default constructor

Todo:
throw a custom error

Parses the configuration file into the boost::property_tree::ptree structure

If not otherwise specified, it will pick up the file called config.xml in the current directory

Exceptions
std::runtime_errorthe provided input file does not exist or can't be read
Todo:
throw a custom exception here

Definition at line 67 of file config.cpp.

Member Function Documentation

Config & SeComLib::Utils::Config::GetInstance ( )
static

Returns a reference to the singleton.

Creates a static instance of this class and returns it. The instance will be destroyed when the application terminates (singleton pattern).

Returns
The static instance of this class

Definition at line 48 of file config.cpp.

template<typename T >
T SeComLib::Utils::Config::GetParameter ( const std::string &  parameter) const

Template method which returns the value of the specified configuration parameter.

Example: GetParameter<int>("key1.key2.key3");

Parameters
parametera string wich contains the keys required to locate the required value in the XML tree.
Returns
the queried value

Definition at line 41 of file config.hpp.

template<typename T >
T SeComLib::Utils::Config::GetParameter ( const std::string &  parameter,
const T &  defaultValue 
) const

Template method which returns the value of the specified configuration parameter, or defaults to defaultValue.

Deduces the template type from the defaultValue parameter.

Example: GetParameter("key1.key2.key3", 0U);//the returned value will have type unsigned int

Parameters
parametera string wich contains the keys required to locate the required value in the XML tree.
defaultValuethe method will return this value if the configuration file does not contain the queried data
Returns
the queried value

Definition at line 55 of file config.hpp.

void SeComLib::Utils::Config::SetConfigFile ( const std::string &  configFile)
static

Sets the location and name of the configuration file.

Parameters
configFilethe location and name of the configuration file

Definition at line 56 of file config.cpp.

Member Data Documentation

std::string SeComLib::Utils::Config::configFile
staticprivate

The location of the configuration file.

The default configuration file is located in the same directory as the application (defaults to config.xml)

Definition at line 70 of file config.h.

const std::string SeComLib::Utils::Config::xmlRootElementName
staticprivate

The name of the root node in the configuration XML file.

Initialize the name of the XML configuration file root node

Definition at line 73 of file config.h.


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