60 static const char header_config_rcsid[] =
"$Id: config.h,v 1.18 2006/05/16 19:24:26 gourdeau Exp $";
64 #ifdef _MSC_VER // Microsoft 65 #pragma warning (disable:4786) // Disable decorated name truncation warnings 66 #pragma warning (disable:4503) // Disable decorated name truncation warnings 73 #include <boost/lexical_cast.hpp> 80 #define CAN_NOT_OPEN_FILE -1 83 #define CAN_NOT_CREATE_FILE -2 100 Config(
const bool bPrintErrorMessages =
true);
101 short read_conf(std::ifstream & inconffile);
105 bool section_exists(
const std::string &
section)
const;
106 bool parameter_exists(
const std::string & section,
const std::string &
parameter)
const;
109 template<
typename T>
bool select(
const std::string & section,
const std::string & parameter,
116 for(Conf_data::const_iterator iter = conf.begin(); iter != conf.end(); ++iter)
118 if( (iter->section == section) && (iter->parameter ==
parameter) )
122 value = boost::lexical_cast<T>(iter->value);
124 catch (boost::bad_lexical_cast & e)
134 short write_conf(std::ofstream & outconffile,
const std::string & file_title,
135 const int space_between_column);
137 template <
typename T>
bool add(
const std::string & section,
const std::string & parameter,
150 dataSet.
value = boost::lexical_cast<std::string>(
value);
152 catch (boost::bad_lexical_cast & e)
157 for(Conf_data::iterator iterConf = conf.begin(); iterConf != conf.end(); ++iterConf)
159 if(section == iterConf->section)
161 if(parameter == iterConf->parameter)
165 iterConf->value = boost::lexical_cast<std::string>(
value);
167 catch (boost::bad_lexical_cast & e)
173 for(Conf_data::iterator iterConf2 = iterConf; iterConf2 != conf.end(); ++iterConf2)
175 if(section != iterConf2->section)
177 conf.insert(iterConf2, dataSet);
184 conf.push_back(dataSet);
Conf_data conf
Data store from/to configuration file.
std::vector< Data > Conf_data
Configuration data type.
Basic data element used in Config class.
static const char header_config_rcsid[]
RCS/CVS version.
bool select(const std::string §ion, const std::string ¶meter, T &value) const
Get a parameter data, of a certain section, into the string value.
Handle configuration files.
bool bPrintErrorMessages
Print error messages on stderr.
bool add(const std::string §ion, const std::string ¶meter, 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.
struct Data Data
Basic data element used in Config class.