Async 1.5.0
|
A class for reading INI-formatted configuration files. More...
#include <AsyncConfig.h>
Public Member Functions | |
Config (void) | |
Default constuctor. | |
~Config (void) | |
Destructor. | |
bool | open (const std::string &name) |
Open the given config file. | |
const std::string & | getValue (const std::string §ion, const std::string &tag) const |
Return the string value of the given configuration variable. | |
bool | getValue (const std::string §ion, const std::string &tag, std::string &value) const |
Get the string value of the given configuration variable. | |
template<typename Rsp > | |
bool | getValue (const std::string §ion, const std::string &tag, Rsp &rsp, bool missing_ok=false) const |
Get the value of the given configuration variable. | |
template<template< typename, typename > class Container, typename Value > | |
bool | getValue (const std::string §ion, const std::string &tag, Container< Value, std::allocator< Value > > &c, bool missing_ok=false) const |
Get the value of the given config variable into container. | |
template<typename Rsp > | |
bool | getValue (const std::string §ion, const std::string &tag, const Rsp &min, const Rsp &max, Rsp &rsp, bool missing_ok=false) const |
Get a range checked variable value. | |
std::list< std::string > | listSection (const std::string §ion) |
Return the name of all the tags in the given section. | |
void | setValue (const std::string §ion, const std::string &tag, const std::string &value) |
Set the value of a configuration variable. | |
A class for reading INI-formatted configuration files.
This class is used to read configuration files that is in the famous MS Windows INI file format. An example of a configuration file and how to use the class is shown below.
Definition at line 134 of file AsyncConfig.h.
|
inline |
Default constuctor.
Definition at line 140 of file AsyncConfig.h.
Async::Config::~Config | ( | void | ) |
Destructor.
const std::string & Async::Config::getValue | ( | const std::string & | section, |
const std::string & | tag | ||
) | const |
Return the string value of the given configuration variable.
section | The name of the section where the configuration variable is located |
tag | The name of the configuration variable to get |
This function will return the string value corresponding to the given configuration variable. If the configuration variable is unset, an empty sting is returned.
Referenced by getValue().
|
inline |
Get a range checked variable value.
section | The name of the section where the configuration variable is located |
tag | The name of the configuration variable to get. |
min | Smallest valid value. |
max | Largest valid value. |
rsp | The value is returned in this argument. Successful completion overwites prevoius contents. |
missing_ok | If set to true, return true if the configuration variable is missing |
This function is used to get the value of the given configuration variable, checking if it is within the given range (min <= value <= max). Requires operators >>, < and > to be defined in the value object. Normally a missing configuration variable is seen as an error and the function returns false. If the missing_ok parameter is set to true, this function returns true for a missing variable but till returns false if an illegal value is specified.
Definition at line 308 of file AsyncConfig.h.
References getValue().
|
inline |
Get the value of the given config variable into container.
section | The name of the section where the configuration variable is located |
tag | The name of the configuration variable to get |
c | The value is returned in this argument. Successful completion overwrites previous contents |
missing_ok | If set to true, return true if the configuration variable is missing |
This function is used to get the value of a configuraiton variable. The config variable is read into a container (e.g. vector, list etc). It's a template function meaning that it can take any value type that supports the operator>> function. Normally a missing configuration variable is seen as an error and the function returns false. If the missing_ok parameter is set to true, this function returns true for a missing variable but still returns false if an illegal value is specified.
Definition at line 254 of file AsyncConfig.h.
References getValue().
|
inline |
Get the value of the given configuration variable.
section | The name of the section where the configuration variable is located |
tag | The name of the configuration variable to get |
rsp | The value is returned in this argument. Successful completion overwrites previous contents |
missing_ok | If set to true, return true if the configuration variable is missing |
This function is used to get the value of a configuraiton variable. It's a template function meaning that it can take any value type that supports the operator>> function. Note that when the value is of type string, the overloaded getValue is used rather than this function. Normally a missing configuration variable is seen as an error and the function returns false. If the missing_ok parameter is set to true, this function returns true for a missing variable but still returns false if an illegal value is specified.
Definition at line 209 of file AsyncConfig.h.
References getValue().
bool Async::Config::getValue | ( | const std::string & | section, |
const std::string & | tag, | ||
std::string & | value | ||
) | const |
Get the string value of the given configuration variable.
section | The name of the section where the configuration variable is located |
tag | The name of the configuration variable to get |
value | The value is returned in this argument. Any previous contents is wiped |
This function is used to get the value for a configuration variable of type "string".
std::list< std::string > Async::Config::listSection | ( | const std::string & | section | ) |
Return the name of all the tags in the given section.
section | The name of the section where the configuration variables are located |
bool Async::Config::open | ( | const std::string & | name | ) |
Open the given config file.
name | The name of the configuration file to open |
This function will read the given configuration file into memory. If this function return false and errno != 0, the errno variable may give a hint what the problem was.
void Async::Config::setValue | ( | const std::string & | section, |
const std::string & | tag, | ||
const std::string & | value | ||
) |
Set the value of a configuration variable.
section | The name of the section where the configuration variable is located |
tag | The name of the configuration variable to set. |
value | The value to set |
This function is used to set the value of a configuration variable. If the given configuration section or variable does not exist, it is created. Note that this function will not write anything back to the associated configuration file. It will only set the value in memory.