Main MRPT website > C++ reference
MRPT logo
List of all members | Public Member Functions | Protected Member Functions
mrpt::utils::CConfigFileBase Class Referenceabstract

Detailed Description

This class allows loading and storing values and vectors of different types from a configuration text, which can be implemented as a ".ini" file, a memory-stored string, etc...

This is a virtual class, use only as a pointer to an implementation of one of the derived classes.

Definition at line 28 of file CConfigFileBase.h.

#include <mrpt/utils/CConfigFileBase.h>

Inheritance diagram for mrpt::utils::CConfigFileBase:
Inheritance graph
[legend]

Public Member Functions

virtual ~CConfigFileBase ()
 Virtual destructor... More...
 
virtual void getAllSections (vector_string &sections) const =0
 Returns a list with all the section names. More...
 
virtual void getAllKeys (const std::string section, vector_string &keys) const =0
 Returs a list with all the keys into a section. More...
 
bool sectionExists (const std::string &section_name) const
 Checks if a given section exists (name is case insensitive) More...
 
double read_double (const std::string &section, const std::string &name, double defaultValue, bool failIfNotFound=false) const
 Reads a configuration parameter of type "double". More...
 
float read_float (const std::string &section, const std::string &name, float defaultValue, bool failIfNotFound=false) const
 Reads a configuration parameter of type "float". More...
 
bool read_bool (const std::string &section, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
 Reads a configuration parameter of type "bool", codified as "1"/"0" or "true"/"false" or "yes"/"no" for true/false, repectively. More...
 
int read_int (const std::string &section, const std::string &name, int defaultValue, bool failIfNotFound=false) const
 Reads a configuration parameter of type "int". More...
 
uint64_t read_uint64_t (const std::string &section, const std::string &name, uint64_t defaultValue, bool failIfNotFound=false) const
 Reads a configuration parameter of type "uint64_t": As in all other methods, the numeric value can be in decimal or hexadecimal with the prefix "0x". More...
 
std::string read_string (const std::string &section, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
 Reads a configuration parameter of type "string". More...
 
std::string read_string_first_word (const std::string &section, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
 Reads a configuration parameter of type "string", and keeps only the first word (this can be used to eliminate possible comments at the end of the line) More...
 
template<class VECTOR_TYPE >
void read_vector (const std::string &section, const std::string &name, const VECTOR_TYPE &defaultValue, VECTOR_TYPE &outValues, bool failIfNotFound=false) const
 Reads a configuration parameter of type vector, stored in the file as a string: "[v1 v2 v3 ... ]", where spaces could also be commas. More...
 
template<class MATRIX_TYPE >
void read_matrix (const std::string &section, const std::string &name, MATRIX_TYPE &outMatrix, const MATRIX_TYPE &defaultMatrix=MATRIX_TYPE(), bool failIfNotFound=false) const
 Reads a configuration parameter as a matrix written in a matlab-like format - for example: "[2 3 4 ; 7 8 9]" This template method can be instantiated for matrices of the types: int, long, unsinged int, unsigned long, float, double, long double. More...
 
template<typename ENUMTYPE >
ENUMTYPE read_enum (const std::string &section, const std::string &name, const ENUMTYPE &defaultValue, bool failIfNotFound=false) const
 Reads an "enum" value, where the value in the config file can be either a numerical value or the symbolic name, for example: In the code: More...
 
Save a configuration parameter. Optionally pads with spaces up to the desired width in number of characters (-1: no fill), and add a final comment field at the end of the line (a "// " prefix is automatically inserted).
void write (const std::string &section, const std::string &name, double value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
 
void write (const std::string &section, const std::string &name, float value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
 
void write (const std::string &section, const std::string &name, int value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
 
void write (const std::string &section, const std::string &name, uint32_t value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
 
void write (const std::string &section, const std::string &name, uint64_t value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
 
void write (const std::string &section, const std::string &name, const std::string &value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
 
void write (const std::string &section, const std::string &name, const std::vector< int > &value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
 
void write (const std::string &section, const std::string &name, const std::vector< unsigned int > &value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
 
void write (const std::string &section, const std::string &name, const std::vector< float > &value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
 
void write (const std::string &section, const std::string &name, const std::vector< double > &value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
 
void write (const std::string &section, const std::string &name, const std::vector< bool > &value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
 

Protected Member Functions

virtual void writeString (const std::string &section, const std::string &name, const std::string &str)=0
 A virtual method to write a generic string. More...
 
void writeString (const std::string &section, const std::string &name, const std::string &str, const int name_padding_width, const int value_padding_width, const std::string &comment)
 Write a generic string with optional padding and a comment field ("// ...") at the end of the line. More...
 
virtual std::string readString (const std::string &section, const std::string &name, const std::string &defaultStr, bool failIfNotFound=false) const =0
 A virtual method to read a generic string. More...
 

Constructor & Destructor Documentation

◆ ~CConfigFileBase()

virtual mrpt::utils::CConfigFileBase::~CConfigFileBase ( )
inlinevirtual

Virtual destructor...

Definition at line 50 of file CConfigFileBase.h.

Member Function Documentation

◆ getAllKeys()

virtual void mrpt::utils::CConfigFileBase::getAllKeys ( const std::string  section,
vector_string keys 
) const
pure virtual

Returs a list with all the keys into a section.

Implemented in mrpt::utils::CConfigFile, and mrpt::utils::CConfigFileMemory.

◆ getAllSections()

virtual void mrpt::utils::CConfigFileBase::getAllSections ( vector_string sections) const
pure virtual

Returns a list with all the section names.

Implemented in mrpt::utils::CConfigFile, and mrpt::utils::CConfigFileMemory.

◆ read_bool()

bool mrpt::utils::CConfigFileBase::read_bool ( const std::string &  section,
const std::string &  name,
bool  defaultValue,
bool  failIfNotFound = false 
) const

Reads a configuration parameter of type "bool", codified as "1"/"0" or "true"/"false" or "yes"/"no" for true/false, repectively.

Exceptions
std::exceptionIf the key name is not found and "failIfNotFound" is true. Otherwise the "defaultValue" is returned.

Referenced by mrpt::pbmap::config_heuristics::load_params().

◆ read_double()

double mrpt::utils::CConfigFileBase::read_double ( const std::string &  section,
const std::string &  name,
double  defaultValue,
bool  failIfNotFound = false 
) const

Reads a configuration parameter of type "double".

Exceptions
std::exceptionIf the key name is not found and "failIfNotFound" is true. Otherwise the "defaultValue" is returned.

◆ read_enum()

template<typename ENUMTYPE >
ENUMTYPE mrpt::utils::CConfigFileBase::read_enum ( const std::string &  section,
const std::string &  name,
const ENUMTYPE &  defaultValue,
bool  failIfNotFound = false 
) const
inline

Reads an "enum" value, where the value in the config file can be either a numerical value or the symbolic name, for example: In the code:

enum my_type_t { type_foo=0, type_bar };

In the config file:

[section]
type = type_bar // Use the symbolic name, or
type = 1 // use the numerical value (both lines will be equivalent)

Which can be loaded with:

cfgfile.read_enum<my_type_t>("section","type", type_foo );
Note
For an enum type to work with this template it is required that it defines a specialization of mrpt::utils::TEnumType

Definition at line 191 of file CConfigFileBase.h.

References mrpt::format(), MRPT_END, MRPT_START, mrpt::utils::TEnumType< ENUMTYPE >::name2value(), and THROW_EXCEPTION.

Referenced by mrpt::bayes::TKF_options::loadFromConfigFile(), and mrpt::srba::RbaEngine< KF2KF_POSE_TYPE, LM_TYPE, OBS_TYPE, RBA_OPTIONS >::TSRBAParameters::loadFromConfigFile().

◆ read_float()

float mrpt::utils::CConfigFileBase::read_float ( const std::string &  section,
const std::string &  name,
float  defaultValue,
bool  failIfNotFound = false 
) const

Reads a configuration parameter of type "float".

Exceptions
std::exceptionIf the key name is not found and "failIfNotFound" is true. Otherwise the "defaultValue" is returned.

Referenced by mrpt::pbmap::config_heuristics::load_params().

◆ read_int()

int mrpt::utils::CConfigFileBase::read_int ( const std::string &  section,
const std::string &  name,
int  defaultValue,
bool  failIfNotFound = false 
) const

Reads a configuration parameter of type "int".

Exceptions
std::exceptionIf the key name is not found and "failIfNotFound" is true. Otherwise the "defaultValue" is returned.

Referenced by mrpt::pbmap::config_heuristics::load_params().

◆ read_matrix()

template<class MATRIX_TYPE >
void mrpt::utils::CConfigFileBase::read_matrix ( const std::string &  section,
const std::string &  name,
MATRIX_TYPE &  outMatrix,
const MATRIX_TYPE &  defaultMatrix = MATRIX_TYPE(),
bool  failIfNotFound = false 
) const
inline

Reads a configuration parameter as a matrix written in a matlab-like format - for example: "[2 3 4 ; 7 8 9]" This template method can be instantiated for matrices of the types: int, long, unsinged int, unsigned long, float, double, long double.

Exceptions
std::exceptionIf the key name is not found and "failIfNotFound" is true. Otherwise the "defaultValue" is returned.

Definition at line 154 of file CConfigFileBase.h.

References THROW_EXCEPTION_CUSTOM_MSG1.

◆ read_string()

std::string mrpt::utils::CConfigFileBase::read_string ( const std::string &  section,
const std::string &  name,
const std::string &  defaultValue,
bool  failIfNotFound = false 
) const

Reads a configuration parameter of type "string".

Exceptions
std::exceptionIf the key name is not found and "failIfNotFound" is true. Otherwise the "defaultValue" is returned.

Referenced by mrpt::pbmap::config_heuristics::load_params().

◆ read_string_first_word()

std::string mrpt::utils::CConfigFileBase::read_string_first_word ( const std::string &  section,
const std::string &  name,
const std::string &  defaultValue,
bool  failIfNotFound = false 
) const

Reads a configuration parameter of type "string", and keeps only the first word (this can be used to eliminate possible comments at the end of the line)

Exceptions
std::exceptionIf the key name is not found and "failIfNotFound" is true. Otherwise the "defaultValue" is returned.

◆ read_uint64_t()

uint64_t mrpt::utils::CConfigFileBase::read_uint64_t ( const std::string &  section,
const std::string &  name,
uint64_t  defaultValue,
bool  failIfNotFound = false 
) const

Reads a configuration parameter of type "uint64_t": As in all other methods, the numeric value can be in decimal or hexadecimal with the prefix "0x".

Exceptions
std::exceptionIf the key name is not found and "failIfNotFound" is true. Otherwise the "defaultValue" is returned.

◆ read_vector()

template<class VECTOR_TYPE >
void mrpt::utils::CConfigFileBase::read_vector ( const std::string &  section,
const std::string &  name,
const VECTOR_TYPE &  defaultValue,
VECTOR_TYPE &  outValues,
bool  failIfNotFound = false 
) const
inline

Reads a configuration parameter of type vector, stored in the file as a string: "[v1 v2 v3 ... ]", where spaces could also be commas.

Exceptions
std::exceptionIf the key name is not found and "failIfNotFound" is true. Otherwise the "defaultValue" is returned.

Definition at line 119 of file CConfigFileBase.h.

References mrpt::system::tokenize().

◆ readString()

virtual std::string mrpt::utils::CConfigFileBase::readString ( const std::string &  section,
const std::string &  name,
const std::string &  defaultStr,
bool  failIfNotFound = false 
) const
protectedpure virtual

A virtual method to read a generic string.

Exceptions
std::exceptionIf the key name is not found and "failIfNotFound" is true. Otherwise the "defaultValue" is returned.

Implemented in mrpt::utils::CConfigFile, and mrpt::utils::CConfigFileMemory.

◆ sectionExists()

bool mrpt::utils::CConfigFileBase::sectionExists ( const std::string &  section_name) const

Checks if a given section exists (name is case insensitive)

◆ write() [1/11]

void mrpt::utils::CConfigFileBase::write ( const std::string &  section,
const std::string &  name,
double  value,
const int  name_padding_width = -1,
const int  value_padding_width = -1,
const std::string &  comment = std::string() 
)

◆ write() [2/11]

void mrpt::utils::CConfigFileBase::write ( const std::string &  section,
const std::string &  name,
float  value,
const int  name_padding_width = -1,
const int  value_padding_width = -1,
const std::string &  comment = std::string() 
)

◆ write() [3/11]

void mrpt::utils::CConfigFileBase::write ( const std::string &  section,
const std::string &  name,
int  value,
const int  name_padding_width = -1,
const int  value_padding_width = -1,
const std::string &  comment = std::string() 
)

◆ write() [4/11]

void mrpt::utils::CConfigFileBase::write ( const std::string &  section,
const std::string &  name,
uint32_t  value,
const int  name_padding_width = -1,
const int  value_padding_width = -1,
const std::string &  comment = std::string() 
)

◆ write() [5/11]

void mrpt::utils::CConfigFileBase::write ( const std::string &  section,
const std::string &  name,
uint64_t  value,
const int  name_padding_width = -1,
const int  value_padding_width = -1,
const std::string &  comment = std::string() 
)

◆ write() [6/11]

void mrpt::utils::CConfigFileBase::write ( const std::string &  section,
const std::string &  name,
const std::string &  value,
const int  name_padding_width = -1,
const int  value_padding_width = -1,
const std::string &  comment = std::string() 
)

◆ write() [7/11]

void mrpt::utils::CConfigFileBase::write ( const std::string &  section,
const std::string &  name,
const std::vector< int > &  value,
const int  name_padding_width = -1,
const int  value_padding_width = -1,
const std::string &  comment = std::string() 
)

◆ write() [8/11]

void mrpt::utils::CConfigFileBase::write ( const std::string &  section,
const std::string &  name,
const std::vector< unsigned int > &  value,
const int  name_padding_width = -1,
const int  value_padding_width = -1,
const std::string &  comment = std::string() 
)

◆ write() [9/11]

void mrpt::utils::CConfigFileBase::write ( const std::string &  section,
const std::string &  name,
const std::vector< float > &  value,
const int  name_padding_width = -1,
const int  value_padding_width = -1,
const std::string &  comment = std::string() 
)

◆ write() [10/11]

void mrpt::utils::CConfigFileBase::write ( const std::string &  section,
const std::string &  name,
const std::vector< double > &  value,
const int  name_padding_width = -1,
const int  value_padding_width = -1,
const std::string &  comment = std::string() 
)

◆ write() [11/11]

void mrpt::utils::CConfigFileBase::write ( const std::string &  section,
const std::string &  name,
const std::vector< bool > &  value,
const int  name_padding_width = -1,
const int  value_padding_width = -1,
const std::string &  comment = std::string() 
)

◆ writeString() [1/2]

virtual void mrpt::utils::CConfigFileBase::writeString ( const std::string &  section,
const std::string &  name,
const std::string &  str 
)
protectedpure virtual

A virtual method to write a generic string.

Implemented in mrpt::utils::CConfigFile, and mrpt::utils::CConfigFileMemory.

◆ writeString() [2/2]

void mrpt::utils::CConfigFileBase::writeString ( const std::string &  section,
const std::string &  name,
const std::string &  str,
const int  name_padding_width,
const int  value_padding_width,
const std::string &  comment 
)
protected

Write a generic string with optional padding and a comment field ("// ...") at the end of the line.




Page generated by Doxygen 1.8.14 for MRPT 1.1.0 SVN: at lun oct 28 00:54:49 CET 2019 Hosted on:
SourceForge.net Logo