VoiceMan
Public Member Functions | Protected Types | Protected Member Functions
ConfigFile Class Reference

The configuration file parser. More...

Inheritance diagram for ConfigFile:
VoicemanConfigFile

List of all members.

Public Member Functions

void checkParams () const
 Checks values type matching.
 ConfigFile ()
 The default constructor.
const ConfigFileSectionfindSection (const std::string &name) const
 Returns the reference to the section object by the section name.
const ConfigFileSectiongetSection (ConfigFileSectionVector::size_type index) const
 Returns the reference to the section object by the section index.
ConfigFileSectionVector::size_type getSectionCount () const
 Returns the number of read sections.
bool hasSection (const std::string &name) const
 Checks if the specified section is accessible.
void load (const std::string &fileName)
 Loads configuration file content.
virtual ~ConfigFile ()
 The destructor.

Protected Types

enum  {
  AnyValue = -1, InvalidValue = 0, BooleanValue = 1, StringValue = 2,
  IntValue = 3, UintValue = 4, DoubleValue = 5
}

Protected Member Functions

virtual int params (const std::string &section, const std::string &param) const =0

Detailed Description

This is the main class to parse configuration file. It reads all data from file, constructs the set of ConfigFileSection objects and fills them with read data. User can analyze prepared information and perform required handling. This class can also check data types by the data types table, defined in child class. None of the data semantics is processed by this class.

See also:
ConfigFileSection ConfigFileException ConfigFileValueTypeException

Member Function Documentation

void ConfigFile::checkParams ( ) const

This method looks through read values and checks its types. If error is found the ConfigFileValueTypeException is thrown. Checking is performed by the data provided by params() method. You should override this method in your child classe. There are predefined macroses to define data types table.

const ConfigFileSection & ConfigFile::findSection ( const std::string &  name) const

This method looks through stored sections vector and finds U corresponding by section name. You must be strongly sure the required section exists. This method does not have any way to notify about an error.

Parameters:
[in]nameThe name of a section to return
Returns:
The reference to desired section object
const ConfigFileSection & ConfigFile::getSection ( ConfigFileSectionVector::size_type  index) const

Use this method to get desired section object.

Parameters:
[in]indexThe index of a section to return
Returns:
The reference to desired section object
ConfigFileSectionVector::size_type ConfigFile::getSectionCount ( ) const

Use this method to get number of parsed sections.

Returns:
Number of parsed sections
bool ConfigFile::hasSection ( const std::string &  name) const

Use this method to be sure the desired section exists.

Parameters:
[in]nameThe name of a section to check
Returns:
Non-zero if specified section exists
void ConfigFile::load ( const std::string &  fileName)

This method reads configuration file and saves processed data in the internal structures inside of this class. Any data can be retrieved later. On any error it throws ConfigFileException. This method does not perform any value type checking. You should explicitly call checkParams() method to do it.

Parameters:
[in]fileNameThe name of a file to read data from