ConfigFile Class Reference

Implements a mechanism for passing parameters from a configuration file. More...

#include <ConfigFile.h>

List of all members.

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 ValuegetValue (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.

Detailed Description

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.

Bug:
On some platforms scanning may hang if an empty string is contained in the input file.

Definition at line 111 of file ConfigFile.h.


Constructor & Destructor Documentation

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.

Parameters:
f_name - name of the configuration file.

Member Function Documentation

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.

Parameters:
p_name - the name of the parameter.
p_value - the value of the parameter.
void ConfigFile::trim ( char *  ch  )  [private]

Friends And Related Function Documentation

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.


Member Data Documentation

Definition at line 208 of file ConfigFile.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Mon Sep 26 18:43:46 2011 for CRyptography And Groups (CRAG) by  doxygen 1.6.1