Implements a mechanism for passing parameters from a configuration file. More...
#include <ConfigFile.h>
Public Member Functions | |
ConfigFile () | |
Default constructor. | |
ConfigFile (const string &f_name) | |
Constructor. Collects parameters and their values from a configuration file. | |
void | setVariable (const char *p_name, const Value &p_value) |
Set a value of a parameter. | |
const Value & | getValue (const char *p_name) |
Get a value of a parameter. | |
Private Member Functions | |
void | readFrom (istream &istr) |
void | printOn (ostream &ostr) const |
void | rtrim (char *ch) |
void | ltrim (char *ch) |
void | trim (char *ch) |
Private Attributes | |
ParameterType | parameters |
Friends | |
ostream & | operator<< (ostream &ostr, const ConfigFile &C) |
Output operator. |
Implements a mechanism for passing parameters from a configuration file.
This class generates a list of parameters and their values from a given configuration file. The format of the configuration file is follows:
ParameterName1 : ParameterValue1
ParameterName2 : ParameterValue2
. . .
ParameterNameN : ParameterValueN
Parameter names are identifiers containing letters and numbers. Parameter values can be an integer or float point numbers and strings.
It is possible to add comments. Everything after a symbol # and until the end of a line is considered to be a comment.
Definition at line 111 of file ConfigFile.h.
ConfigFile::ConfigFile | ( | ) |
Default constructor.
ConfigFile::ConfigFile | ( | const string & | f_name | ) |
Constructor. Collects parameters and their values from a configuration file.
Will scan the file whose name is given as a parameter and create a list of parameters together with the corresponding values.
f_name | - name of the configuration file. |
const Value& ConfigFile::getValue | ( | const char * | p_name | ) |
Get a value of a parameter.
Returns a value of the parameter with the name p_name.
Note, since class Value is equipped with the operators converting the parameter value into standard types, it is not necessary to create instances of the class Value. Typical use of this function:
int v = configFile.getValue("THENAME");
or with explicit conversion:
string v = string(configFile.getValue("THENAME"));
void ConfigFile::ltrim | ( | char * | ch | ) | [private] |
void ConfigFile::printOn | ( | ostream & | ostr | ) | const [private] |
void ConfigFile::readFrom | ( | istream & | istr | ) | [private] |
void ConfigFile::rtrim | ( | char * | ch | ) | [private] |
void ConfigFile::setVariable | ( | const char * | p_name, | |
const Value & | p_value | |||
) |
Set a value of a parameter.
Sets a value of a parameter with the given name. Will create the parameter if not in the list.
p_name | - the name of the parameter. | |
p_value | - the value of the parameter. |
void ConfigFile::trim | ( | char * | ch | ) | [private] |
ostream& operator<< | ( | ostream & | ostr, | |
const ConfigFile & | C | |||
) | [friend] |
Output operator.
Prints a list of parameters together with their values.
Definition at line 179 of file ConfigFile.h.
ParameterType ConfigFile::parameters [private] |
Definition at line 208 of file ConfigFile.h.