Main MRPT website > C++ reference for MRPT 1.5.3
List of all members | Public Member Functions | Protected Member Functions | Private Attributes
mrpt::utils::CConfigFileMemory Class Reference

Detailed Description

This class implements a config file-like interface over a memory-stored string list.

Use base class CConfigFileBase's methods read_{int,float,double,string,...}() and write() to actually read and write values.

See: Configuration file format in MRPT

Definition at line 28 of file CConfigFileMemory.h.

#include <mrpt/utils/CConfigFileMemory.h>

Inheritance diagram for mrpt::utils::CConfigFileMemory:
Inheritance graph

Public Member Functions

 CConfigFileMemory ()
 Empty constructor. Upon construction, call any of the "setContent" method. More...
 
 CConfigFileMemory (const utils::CStringList &stringList)
 Constructor and initialize from a list of strings. More...
 
 CConfigFileMemory (const std::string &str)
 Constructor and initialize from string with the whole "config file". More...
 
virtual ~CConfigFileMemory ()
 dtor More...
 
 CConfigFileMemory (const CConfigFileMemory &o)
 Copy constructor. More...
 
CConfigFileMemoryoperator= (const CConfigFileMemory &o)
 Copy operator. More...
 
void setContent (const utils::CStringList &stringList)
 Changes the contents of the virtual "config file". More...
 
void setContent (const std::string &str)
 Changes the contents of the virtual "config file". More...
 
void getContent (std::string &str) const
 Return the current contents of the virtual "config file". More...
 
std::string getContent () const
 
void getAllSections (vector_string &sections) const MRPT_OVERRIDE
 Returns a list with all the section names. More...
 
void getAllKeys (const std::string &section, vector_string &keys) const MRPT_OVERRIDE
 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...
 
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).
template<typename data_t >
void write (const std::string &section, const std::string &name, const data_t &value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
 
template<typename data_t >
void write (const std::string &section, const std::string &name, const std::vector< data_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, 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())
 
Read a configuration parameter, launching exception if key name is not found and `failIfNotFound`=true
double read_double (const std::string &section, const std::string &name, double defaultValue, bool failIfNotFound=false) const
 
float read_float (const std::string &section, const std::string &name, float defaultValue, bool failIfNotFound=false) const
 
bool read_bool (const std::string &section, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
 
int read_int (const std::string &section, const std::string &name, int defaultValue, bool failIfNotFound=false) const
 
uint64_t read_uint64_t (const std::string &section, const std::string &name, uint64_t defaultValue, bool failIfNotFound=false) const
 
std::string read_string (const std::string &section, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
 
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]". 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...
 

Protected Member Functions

void writeString (const std::string &section, const std::string &name, const std::string &str) MRPT_OVERRIDE
 A virtual method to write a generic string. More...
 
std::string readString (const std::string &section, const std::string &name, const std::string &defaultStr, bool failIfNotFound=false) const MRPT_OVERRIDE
 A virtual method to read 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...
 

Private Attributes

void_ptr_noncopy m_ini
 The IniFile object. More...
 

Constructor & Destructor Documentation

◆ CConfigFileMemory() [1/4]

mrpt::utils::CConfigFileMemory::CConfigFileMemory ( )

Empty constructor. Upon construction, call any of the "setContent" method.

◆ CConfigFileMemory() [2/4]

mrpt::utils::CConfigFileMemory::CConfigFileMemory ( const utils::CStringList stringList)

Constructor and initialize from a list of strings.

◆ CConfigFileMemory() [3/4]

mrpt::utils::CConfigFileMemory::CConfigFileMemory ( const std::string &  str)

Constructor and initialize from string with the whole "config file".

◆ ~CConfigFileMemory()

virtual mrpt::utils::CConfigFileMemory::~CConfigFileMemory ( )
virtual

dtor

◆ CConfigFileMemory() [4/4]

mrpt::utils::CConfigFileMemory::CConfigFileMemory ( const CConfigFileMemory o)

Copy constructor.

Member Function Documentation

◆ getAllKeys()

void mrpt::utils::CConfigFileMemory::getAllKeys ( const std::string &  section,
vector_string keys 
) const
virtual

Returs a list with all the keys into a section.

Implements mrpt::utils::CConfigFileBase.

◆ getAllSections()

void mrpt::utils::CConfigFileMemory::getAllSections ( vector_string sections) const
virtual

Returns a list with all the section names.

Implements mrpt::utils::CConfigFileBase.

◆ getContent() [1/2]

void mrpt::utils::CConfigFileMemory::getContent ( std::string &  str) const

Return the current contents of the virtual "config file".

◆ getContent() [2/2]

std::string mrpt::utils::CConfigFileMemory::getContent ( ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 43 of file CConfigFileMemory.h.

References getContent(), and MRPT_OVERRIDE.

Referenced by getContent().

◆ operator=()

CConfigFileMemory& mrpt::utils::CConfigFileMemory::operator= ( const CConfigFileMemory o)

Copy operator.

◆ read_bool()

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

◆ read_double()

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

◆ 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
inlineinherited

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 163 of file CConfigFileBase.h.

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

◆ read_float()

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

◆ read_int()

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

◆ 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
inlineinherited

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 126 of file CConfigFileBase.h.

References THROW_EXCEPTION_FMT.

◆ 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
inherited

◆ 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
inherited

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)

◆ 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
inherited

◆ 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
inlineinherited

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 92 of file CConfigFileBase.h.

References mrpt::system::tokenize().

◆ readString()

std::string mrpt::utils::CConfigFileMemory::readString ( const std::string &  section,
const std::string &  name,
const std::string &  defaultStr,
bool  failIfNotFound = false 
) const
protectedvirtual

A virtual method to read a generic string.

Implements mrpt::utils::CConfigFileBase.

◆ sectionExists()

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

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

◆ setContent() [1/2]

void mrpt::utils::CConfigFileMemory::setContent ( const utils::CStringList stringList)

Changes the contents of the virtual "config file".

◆ setContent() [2/2]

void mrpt::utils::CConfigFileMemory::setContent ( const std::string &  str)

Changes the contents of the virtual "config file".

◆ write() [1/4]

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

Definition at line 63 of file CConfigFileBase.h.

References exprtk::details::value().

◆ write() [2/4]

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

Definition at line 70 of file CConfigFileBase.h.

◆ write() [3/4]

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() 
)
inherited

◆ write() [4/4]

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() 
)
inherited

◆ writeString() [1/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 
)
protectedinherited

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

◆ writeString() [2/2]

void mrpt::utils::CConfigFileMemory::writeString ( const std::string &  section,
const std::string &  name,
const std::string &  str 
)
protectedvirtual

A virtual method to write a generic string.

Implements mrpt::utils::CConfigFileBase.

Member Data Documentation

◆ m_ini

void_ptr_noncopy mrpt::utils::CConfigFileMemory::m_ini
private

The IniFile object.

Definition at line 49 of file CConfigFileMemory.h.




Page generated by Doxygen 1.8.13 for MRPT 1.5.3 at Mon Oct 30 10:27:08 UTC 2017