dbp::app_config Class Reference

Configuration file parser class. More...

#include <app_config.h>

List of all members.

Public Types

typedef std::map< std::string,
std::string > 
strindex
typedef std::map< std::string,
strindex > 
sections

Public Member Functions

void clear ()
 Clear currently loaded options.
void load_from_file (const std::string &name)
 Load the configuration parameters from the given file.
template<class T >
value (const std::string &section, const std::string &name, T def_value) const
 Get the option value.
const strindex & section (const std::string &section_name) const
 Get the options section.
sections::const_iterator get_sections ()
 Get the sections iterator.
sections::const_iterator end ()
 Get the tail of the sections iterator.
template<>
const char * value (const std::string &section, const std::string &name, const char *def_value) const
template<>
int value (const std::string &section, const std::string &name, int def_value) const
template<>
double value (const std::string &section, const std::string &name, double def_value) const
template<>
bool value (const std::string &section, const std::string &name, bool def_value) const

Detailed Description

Configuration file parser class.

This class loads and parses configuration file in a common UNIX configuration file format, containing sections, parameters, its values and includes, like this:

[section]
option1 = value
option2 = yes
# comment
; comment
[another section]
option1 = 34
@include = other/file.conf
# and so on...

Member Function Documentation

sections::const_iterator dbp::app_config::end (  ) 

Get the tail of the sections iterator.

When iterating through sections, use the end() method for stopping the iteration, i.e.

for (app_config::sections::const_iterator i = cfg.get_sections();
  i != cfg.end(); ++i) {
        // (std::string) i->first contains the section name
        // (strindex) i->second contains the section options
}
sections::const_iterator dbp::app_config::get_sections (  ) 

Get the sections iterator.

Use get_sections() to iterate through all loaded sections to obtain all section names, for example.

void dbp::app_config::load_from_file ( const std::string &  name  ) 

Load the configuration parameters from the given file.

Clears currently loaded options and loads the new options from the configuration file.

Parameters:
name a name of the file to load.
const strindex& dbp::app_config::section ( const std::string &  section_name  )  const

Get the options section.

This function returns the section content as a whole.

Parameters:
section_name a name of the option section, without brackets.
Returns:
a list of all options of the given section.
template<class T >
T dbp::app_config::value ( const std::string &  section,
const std::string &  name,
def_value 
) const [inline]

Get the option value.

This function returns the option value, or, if the option is not defined, the default value provided.

Parameters:
section a name of the option section, without brackets.
name a name of the option.
def_value an option default value.
Returns:
option value or default value, if the option is not defined.

The documentation for this class was generated from the following file:

 
Support This Project
SourceForge.net Logo