ROBOOP, A Robotics Object Oriented Package in C++
Config Class Reference

Handle configuration files. More...

#include <config.h>

Public Member Functions

 Config (const bool bPrintErrorMessages=true)
 Constructor.
 
short read_conf (std::ifstream &inconffile)
 Read a configuration file. More...
 
void clear ()
 Clear the data buffer.
 
void print ()
 Print the configuration data.
 
bool section_exists (const std::string &section) const
 Test to see if a section exists. More...
 
bool parameter_exists (const std::string &section, const std::string &parameter) const
 Test to see if a parameter exists within a section. More...
 
template<typename T >
bool select (const std::string &section, const std::string &parameter, T &value) const
 Get a parameter data, of a certain section, into the string value. More...
 
short write_conf (std::ofstream &outconffile, const std::string &file_title, const int space_between_column)
 Write the configuration information, contained in conf, on disk. More...
 
template<typename T >
bool add (const std::string &section, const std::string &parameter, const T &value)
 Added the value(string) of the parameter in the section in the configuration data. The functions will added the parameter and the section if it does not already exist.
 

Private Attributes

Conf_data conf
 Data store from/to configuration file.
 
bool bPrintErrorMessages
 Print error messages on stderr.
 

Detailed Description

Handle configuration files.

Definition at line 93 of file config.h.

Member Function Documentation

bool Config::parameter_exists ( const std::string &  section,
const std::string &  parameter 
) const

Test to see if a parameter exists within a section.

Returns
true if parameter is found within section

Definition at line 210 of file config.cpp.

short Config::read_conf ( std::ifstream &  inconffile)

Read a configuration file.

This function reads the configuration file specified in the constructor parameter. The information is stored in the variable conf.

A configuration file contains section(s) (between [ ]), and the section(s) contains parameter(s) with there respective value(s). The section and the parameter are always access via a string. Below is an exemple: one section named PUMA560_mDH, and two parameters.

[PUMA560_mDH] DH: 0 dof: 6

Definition at line 68 of file config.cpp.

References CAN_NOT_OPEN_FILE.

Referenced by Control_Select::set_control().

bool Config::section_exists ( const std::string &  section) const

Test to see if a section exists.

Returns
true if section is found

Definition at line 198 of file config.cpp.

template<typename T >
bool Config::select ( const std::string &  section,
const std::string &  parameter,
T &  value 
) const
inline

Get a parameter data, of a certain section, into the string value.

Returns
false if the data can not be found and true otherwise.

Definition at line 105 of file config.h.

References conf.

Referenced by Control_Select::set_control().

short Config::write_conf ( std::ofstream &  outconffile,
const std::string &  file_title,
const int  space_between_column 
)

Write the configuration information, contained in conf, on disk.

Parameters
filename,:Configuration file name.
file_title,:Title in the configuration file header.
space_between_column,:Number of blanks between : (of a parameter) and it's value.

Definition at line 222 of file config.cpp.

References CAN_NOT_CREATE_FILE.