Main MRPT website > C++ reference for MRPT 1.9.9
List of all members | Public Member Functions | Protected Member Functions | Friends
mrpt::config::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.

See: Configuration file format in MRPT

Definition at line 44 of file config/CConfigFileBase.h.

#include <mrpt/config/CConfigFileBase.h>

Inheritance diagram for mrpt::config::CConfigFileBase:
Inheritance graph

Public Member Functions

virtual ~CConfigFileBase ()
 dtor More...
 
virtual void getAllSections (std::vector< std::string > &sections) const =0
 Returns a list with all the section names. More...
 
virtual void getAllKeys (const std::string &section, std::vector< std::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...
 
template<typename enum_t , typename = std::enable_if_t<std::is_enum<enum_t>::value>>
void write (const std::string &section, const std::string &name, enum_t 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...
 

Friends

class CConfigFilePrefixer
 

Constructor & Destructor Documentation

◆ ~CConfigFileBase()

CConfigFileBase::~CConfigFileBase ( )
virtual

dtor

Definition at line 32 of file CConfigFileBase.cpp.

Member Function Documentation

◆ getAllKeys()

virtual void mrpt::config::CConfigFileBase::getAllKeys ( const std::string section,
std::vector< std::string > &  keys 
) const
pure virtual

◆ getAllSections()

virtual void mrpt::config::CConfigFileBase::getAllSections ( std::vector< std::string > &  sections) const
pure virtual

◆ read_bool()

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

◆ read_double()

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

◆ read_enum()

template<typename ENUMTYPE >
ENUMTYPE mrpt::config::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::typemeta::TEnumType

Definition at line 245 of file config/CConfigFileBase.h.

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

Referenced by mrpt::hwdrivers::CVelodyneScanner::loadConfig_sensorSpecific(), mrpt::hwdrivers::CGPSInterface::loadConfig_sensorSpecific(), and mrpt::hwdrivers::CKinect::loadConfig_sensorSpecific().

◆ read_float()

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

Definition at line 113 of file CConfigFileBase.cpp.

Referenced by mrpt::pbmap::config_heuristics::load_params(), mrpt::hwdrivers::CWirelessPower::loadConfig_sensorSpecific(), mrpt::hwdrivers::CGillAnemometer::loadConfig_sensorSpecific(), mrpt::hwdrivers::CRaePID::loadConfig_sensorSpecific(), mrpt::hwdrivers::CIMUXSens_MT4::loadConfig_sensorSpecific(), mrpt::hwdrivers::CIMUXSens::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSickLaserUSB::loadConfig_sensorSpecific(), mrpt::hwdrivers::CIMUIntersense::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSkeletonTracker::loadConfig_sensorSpecific(), mrpt::hwdrivers::CGyroKVHDSP3000::loadConfig_sensorSpecific(), mrpt::hwdrivers::CRoboPeakLidar::loadConfig_sensorSpecific(), mrpt::hwdrivers::CIbeoLuxETH::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSICKTim561Eth::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSickLaserSerial::loadConfig_sensorSpecific(), mrpt::hwdrivers::CBoardSonars::loadConfig_sensorSpecific(), mrpt::hwdrivers::CLMS100Eth::loadConfig_sensorSpecific(), mrpt::hwdrivers::CPhidgetInterfaceKitProximitySensors::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSwissRanger3DCamera::loadConfig_sensorSpecific(), mrpt::hwdrivers::CVelodyneScanner::loadConfig_sensorSpecific(), mrpt::hwdrivers::CGPSInterface::loadConfig_sensorSpecific(), mrpt::hwdrivers::COpenNI2_RGBD360::loadConfig_sensorSpecific(), mrpt::hwdrivers::CHokuyoURG::loadConfig_sensorSpecific(), mrpt::hwdrivers::COpenNI2Sensor::loadConfig_sensorSpecific(), mrpt::hwdrivers::CKinect::loadConfig_sensorSpecific(), mrpt::hwdrivers::CCameraSensor::loadConfig_sensorSpecific(), mrpt::hwdrivers::TCaptureOptions_DUO3D::loadOptionsFrom(), mrpt::hwdrivers::TCaptureOptions_FlyCapture2::loadOptionsFrom(), and readConfigFile().

◆ read_int()

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

Definition at line 125 of file CConfigFileBase.cpp.

Referenced by mrpt::detectors::CCascadeClassifierDetection::init(), mrpt::detectors::CFaceDetection::init(), mrpt::nav::PlannerTPS_VirtualBase::internal_loadConfig_PTG(), mrpt::pbmap::config_heuristics::load_params(), mrpt::hwdrivers::CGenericSensor::loadConfig(), mrpt::hwdrivers::CGillAnemometer::loadConfig_sensorSpecific(), mrpt::hwdrivers::CRaePID::loadConfig_sensorSpecific(), mrpt::hwdrivers::CRoboticHeadInterface::loadConfig_sensorSpecific(), mrpt::hwdrivers::CIMUXSens_MT4::loadConfig_sensorSpecific(), mrpt::hwdrivers::CIMUXSens::loadConfig_sensorSpecific(), mrpt::hwdrivers::CImpinjRFID::loadConfig_sensorSpecific(), mrpt::hwdrivers::CIMUIntersense::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSICKTim561Eth::loadConfig_sensorSpecific(), mrpt::hwdrivers::CCANBusReader::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSickLaserSerial::loadConfig_sensorSpecific(), mrpt::hwdrivers::CBoardSonars::loadConfig_sensorSpecific(), mrpt::hwdrivers::CLMS100Eth::loadConfig_sensorSpecific(), mrpt::hwdrivers::CPhidgetInterfaceKitProximitySensors::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSwissRanger3DCamera::loadConfig_sensorSpecific(), mrpt::hwdrivers::CGPSInterface::loadConfig_sensorSpecific(), mrpt::hwdrivers::COpenNI2_RGBD360::loadConfig_sensorSpecific(), mrpt::hwdrivers::CHokuyoURG::loadConfig_sensorSpecific(), mrpt::hwdrivers::COpenNI2Sensor::loadConfig_sensorSpecific(), mrpt::hwdrivers::CKinect::loadConfig_sensorSpecific(), mrpt::hwdrivers::CCameraSensor::loadConfig_sensorSpecific(), mrpt::vision::TMultiResDescOptions::loadFromConfigFile(), mrpt::hwdrivers::TCaptureOptions_DUO3D::loadOptionsFrom(), mrpt::hwdrivers::TCaptureOptions_FlyCapture2::loadOptionsFrom(), mrpt::graphslam::CGraphSlamEngine< mrpt::graphs::CNetworkOfPoses2DInf >::loadParams(), readConfigFile(), mrpt::gui::CPanelCameraSelection::readConfigIntoVideoSourcePanel(), and TEST().

◆ read_matrix()

template<class MATRIX_TYPE >
void mrpt::config::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 206 of file config/CConfigFileBase.h.

References readString(), and THROW_EXCEPTION_FMT.

Referenced by mrpt::topography::path_from_rtk_gps().

◆ read_string()

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

Definition at line 169 of file CConfigFileBase.cpp.

References mrpt::system::trim().

Referenced by mrpt::detectors::CCascadeClassifierDetection::init(), mrpt::nav::PlannerTPS_VirtualBase::internal_loadConfig_PTG(), mrpt::pbmap::config_heuristics::load_params(), mrpt::hwdrivers::CGenericSensor::loadConfig(), mrpt::hwdrivers::CWirelessPower::loadConfig_sensorSpecific(), mrpt::hwdrivers::CGillAnemometer::loadConfig_sensorSpecific(), mrpt::hwdrivers::CRaePID::loadConfig_sensorSpecific(), mrpt::hwdrivers::CRoboticHeadInterface::loadConfig_sensorSpecific(), mrpt::hwdrivers::CIMUXSens_MT4::loadConfig_sensorSpecific(), mrpt::hwdrivers::CIMUXSens::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSickLaserUSB::loadConfig_sensorSpecific(), mrpt::hwdrivers::CImpinjRFID::loadConfig_sensorSpecific(), mrpt::hwdrivers::CEnoseModular::loadConfig_sensorSpecific(), mrpt::hwdrivers::CBoardENoses::loadConfig_sensorSpecific(), mrpt::hwdrivers::CGyroKVHDSP3000::loadConfig_sensorSpecific(), mrpt::hwdrivers::CRoboPeakLidar::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSICKTim561Eth::loadConfig_sensorSpecific(), mrpt::hwdrivers::CCANBusReader::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSickLaserSerial::loadConfig_sensorSpecific(), mrpt::hwdrivers::CBoardSonars::loadConfig_sensorSpecific(), mrpt::hwdrivers::CLMS100Eth::loadConfig_sensorSpecific(), mrpt::hwdrivers::CPhidgetInterfaceKitProximitySensors::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSwissRanger3DCamera::loadConfig_sensorSpecific(), mrpt::hwdrivers::CGPSInterface::loadConfig_sensorSpecific(), mrpt::hwdrivers::CHokuyoURG::loadConfig_sensorSpecific(), mrpt::hwdrivers::COpenNI2Sensor::loadConfig_sensorSpecific(), mrpt::hwdrivers::CNationalInstrumentsDAQ::loadConfig_sensorSpecific(), mrpt::hwdrivers::CKinect::loadConfig_sensorSpecific(), mrpt::hwdrivers::CCameraSensor::loadConfig_sensorSpecific(), mrpt::img::TStereoCamera::loadFromConfigFile(), mrpt::hwdrivers::TCaptureOptions_DUO3D::loadOptionsFrom(), mrpt::hwdrivers::TCaptureOptions_FlyCapture2::loadOptionsFrom(), mrpt::graphslam::CGraphSlamEngine< mrpt::graphs::CNetworkOfPoses2DInf >::loadParams(), readConfigFile(), CGraphSlamHandler< GRAPH_T >::readConfigFname(), mrpt::gui::CPanelCameraSelection::readConfigIntoVideoSourcePanel(), TEST(), and mrpt::gui::CPanelCameraSelection::writeConfigFromVideoSourcePanel().

◆ read_string_first_word()

std::string 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)

Definition at line 180 of file CConfigFileBase.cpp.

References THROW_EXCEPTION, and mrpt::system::tokenize().

Referenced by mrpt::hwdrivers::CCameraSensor::loadConfig_sensorSpecific(), and read_enum().

◆ read_uint64_t()

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

◆ read_vector()

template<class VECTOR_TYPE >
void mrpt::config::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 171 of file config/CConfigFileBase.h.

References readString(), mrpt::system::tokenize(), and val.

Referenced by mrpt::hwdrivers::C2DRangeFinderAbstract::loadCommonParams(), mrpt::hwdrivers::CRoboticHeadInterface::loadConfig_sensorSpecific(), mrpt::hwdrivers::CBoardENoses::loadConfig_sensorSpecific(), mrpt::hwdrivers::CBoardSonars::loadConfig_sensorSpecific(), mrpt::img::TCamera::loadFromConfigFile(), and mrpt::vision::TMultiResDescOptions::loadFromConfigFile().

◆ readString()

virtual std::string mrpt::config::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::config::CConfigFileMemory, mrpt::config::CConfigFile, and mrpt::config::CConfigFilePrefixer.

Referenced by read_matrix(), read_vector(), and mrpt::config::CConfigFilePrefixer::readString().

◆ sectionExists()

bool CConfigFileBase::sectionExists ( const std::string section_name) const

◆ write() [1/5]

template<typename data_t , typename = std::enable_if_t<!std::is_enum<data_t>::value>>
void mrpt::config::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() 
)
inline

Definition at line 101 of file config/CConfigFileBase.h.

References mrpt::to_string(), and writeString().

◆ write() [2/5]

template<typename data_t >
void mrpt::config::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() 
)
inline

Definition at line 112 of file config/CConfigFileBase.h.

References mrpt::to_string(), and writeString().

◆ write() [3/5]

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

Definition at line 33 of file CConfigFileBase.cpp.

◆ write() [4/5]

template<typename enum_t , typename = std::enable_if_t<std::is_enum<enum_t>::value>>
void mrpt::config::CConfigFileBase::write ( const std::string section,
const std::string name,
enum_t  value,
const int  name_padding_width = -1,
const int  value_padding_width = -1,
const std::string comment = std::string() 
)
inline

◆ write() [5/5]

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

Definition at line 47 of file CConfigFileBase.cpp.

◆ writeString() [1/2]

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

◆ writeString() [2/2]

void 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.

Definition at line 65 of file CConfigFileBase.cpp.

References mrpt::format().

Friends And Related Function Documentation

◆ CConfigFilePrefixer

friend class CConfigFilePrefixer
friend

Definition at line 46 of file config/CConfigFileBase.h.

type
GLuint GLuint GLsizei GLenum type
Definition: glext.h:3528



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST