Utilitary class for parsing the configuration file.
More...
#include <config.h>
|
template<typename T > |
T | GetParameter (const std::string ¶meter) const |
| Template method which returns the value of the specified configuration parameter. More...
|
|
template<typename T > |
T | GetParameter (const std::string ¶meter, const T &defaultValue) const |
| Template method which returns the value of the specified configuration parameter, or defaults to defaultValue. More...
|
|
|
boost::property_tree::ptree | propertyTree |
| The internal mapping of the XML configuration file.
|
|
Utilitary class for parsing the configuration file.
Works as a singleton: Config::GetInstance().DoStuff()
Definition at line 49 of file config.h.
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_error | the 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.
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
-
parameter | a 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
-
parameter | a string wich contains the keys required to locate the required value in the XML tree. |
defaultValue | the 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
-
configFile | the location and name of the configuration file |
Definition at line 56 of file config.cpp.
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: