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

Detailed Description

This class allows loading and storing values and vectors of different types from ".ini" files easily.

The contents of the file will be modified by "write" operations in memory, and will be saved back to the file at the destructor, and only if at least one write operation has been applied.

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 35 of file CConfigFile.h.

#include <mrpt/utils/CConfigFile.h>

Inheritance diagram for mrpt::utils::CConfigFile:
Inheritance graph

Public Member Functions

 CConfigFile (const std::string &fileName)
 Constructor that opens a configuration file. More...
 
 CConfigFile ()
 Constructor, does not open any file. More...
 
void setFileName (const std::string &fil_path)
 Associate this object with the given file, so future read/write operations will be applied to that file (it's synchronized at destruction) More...
 
void writeNow ()
 Dumps the changes to the physical configuration file now, not waiting until destruction. More...
 
void discardSavingChanges ()
 Discard saving (current) changes to physical file upon destruction. More...
 
std::string getAssociatedFile () const
 Returns the file currently open by this object. More...
 
virtual ~CConfigFile ()
 Destructor. More...
 
virtual void getAllSections (vector_string &sections) const override
 Returns a list with all the section names. More...
 
virtual void getAllKeys (const std::string &section, vector_string &keys) const 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...
 
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())
 
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 , typename = std::enable_if_t<!std::is_enum<data_t>::value>>
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) 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 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

std::string m_file
 The name of the file. More...
 
void_ptr_noncopy m_ini
 The interface to the file: More...
 
bool m_modified
 If modified since load. More...
 

Constructor & Destructor Documentation

◆ CConfigFile() [1/2]

CConfigFile::CConfigFile ( const std::string fileName)

Constructor that opens a configuration file.

Definition at line 24 of file CConfigFile.cpp.

References MRPT_END, and MRPT_START.

◆ CConfigFile() [2/2]

CConfigFile::CConfigFile ( )

Constructor, does not open any file.

You should call "setFileName" before reading or writting or otherwise nothing will be read and write operations will be eventually lost. However, it's perfectly right to use this object without an associated file, in which case it will behave as an "in-memory" file.

Definition at line 39 of file CConfigFile.cpp.

References MRPT_END, and MRPT_START.

◆ ~CConfigFile()

CConfigFile::~CConfigFile ( )
virtual

Destructor.

Definition at line 82 of file CConfigFile.cpp.

Member Function Documentation

◆ discardSavingChanges()

void CConfigFile::discardSavingChanges ( )

Discard saving (current) changes to physical file upon destruction.

Definition at line 78 of file CConfigFile.cpp.

Referenced by run_rnav_test().

Here is the caller graph for this function:

◆ getAllKeys()

void CConfigFile::getAllKeys ( const std::string section,
vector_string keys 
) const
overridevirtual

Returs a list with all the keys into a section.

Implements mrpt::utils::CConfigFileBase.

Definition at line 160 of file CConfigFile.cpp.

◆ getAllSections()

void CConfigFile::getAllSections ( vector_string sections) const
overridevirtual

Returns a list with all the section names.

Implements mrpt::utils::CConfigFileBase.

Definition at line 145 of file CConfigFile.cpp.

◆ getAssociatedFile()

std::string mrpt::utils::CConfigFile::getAssociatedFile ( ) const
inline

Returns the file currently open by this object.

Definition at line 84 of file CConfigFile.h.

References m_file.

◆ read_bool()

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

Definition at line 143 of file CConfigFileBase.cpp.

References mrpt::system::lowerCase(), and mrpt::system::trim().

Referenced by mrpt::detectors::CFaceDetection::init(), mrpt::maps::CRandomFieldGridMap2D::TInsertionOptionsCommon::internal_loadFromConfigFile_common(), mrpt::pbmap::config_heuristics::load_params(), mrpt::hwdrivers::C2DRangeFinderAbstract::loadCommonParams(), mrpt::hwdrivers::CIMUIntersense::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSkeletonTracker::loadConfig_sensorSpecific(), mrpt::hwdrivers::CCANBusReader::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSickLaserSerial::loadConfig_sensorSpecific(), mrpt::hwdrivers::CPhidgetInterfaceKitProximitySensors::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSwissRanger3DCamera::loadConfig_sensorSpecific(), mrpt::hwdrivers::CHokuyoURG::loadConfig_sensorSpecific(), mrpt::hwdrivers::CGPSInterface::loadConfig_sensorSpecific(), mrpt::hwdrivers::COpenNI2_RGBD360::loadConfig_sensorSpecific(), mrpt::hwdrivers::COpenNI2Sensor::loadConfig_sensorSpecific(), mrpt::hwdrivers::CKinect::loadConfig_sensorSpecific(), mrpt::hwdrivers::CCameraSensor::loadConfig_sensorSpecific(), mrpt::maps::CGasConcentrationGridMap2D::TInsertionOptions::loadFromConfigFile(), mrpt::maps::CRandomFieldGridMap3D::TInsertionOptions::loadFromConfigFile(), mrpt::maps::CLandmarksMap::TInsertionOptions::loadFromConfigFile(), mrpt::maps::CLandmarksMap::TLikelihoodOptions::loadFromConfigFile(), mrpt::vision::TMatchingOptions::loadFromConfigFile(), mrpt::maps::COccupancyGridMap2D::TLikelihoodOptions::loadFromConfigFile(), mrpt::vision::TMultiResDescOptions::loadFromConfigFile(), mrpt::hwdrivers::TCaptureOptions_DUO3D::loadOptionsFrom(), mrpt::hwdrivers::TCaptureOptions_FlyCapture2::loadOptionsFrom(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::loadParams(), readConfigFile(), CGraphSlamHandler< GRAPH_T >::readConfigFname(), mrpt::gui::CPanelCameraSelection::readConfigIntoVideoSourcePanel(), and run_test_pf_localization().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_double()

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

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

Referenced by mrpt::hwdrivers::CVelodyneScanner::loadConfig_sensorSpecific(), mrpt::hwdrivers::CGPSInterface::loadConfig_sensorSpecific(), mrpt::hwdrivers::CKinect::loadConfig_sensorSpecific(), mrpt::bayes::TKF_options::loadFromConfigFile(), mrpt::slam::CICP::TConfigParams::loadFromConfigFile(), mrpt::slam::CGridMapAligner::TConfigParams::loadFromConfigFile(), mrpt::slam::CMetricMapBuilderRBPF::TConstructionOptions::loadFromConfigFile(), mrpt::vision::CFeatureExtraction::TOptions::loadFromConfigFile(), mrpt::bayes::CParticleFilter::TParticleFilterOptions::loadFromConfigFile(), and mrpt::maps::COccupancyGridMap2D::TLikelihoodOptions::loadFromConfigFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_float()

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

Definition at line 106 of file CConfigFileBase.cpp.

Referenced by mrpt::maps::CRandomFieldGridMap2D::TInsertionOptionsCommon::internal_loadFromConfigFile_common(), 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::CGyroKVHDSP3000::loadConfig_sensorSpecific(), mrpt::hwdrivers::CSkeletonTracker::loadConfig_sensorSpecific(), mrpt::hwdrivers::CRoboPeakLidar::loadConfig_sensorSpecific(), mrpt::hwdrivers::CIbeoLuxETH::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::CHokuyoURG::loadConfig_sensorSpecific(), mrpt::hwdrivers::CGPSInterface::loadConfig_sensorSpecific(), mrpt::hwdrivers::COpenNI2_RGBD360::loadConfig_sensorSpecific(), mrpt::hwdrivers::COpenNI2Sensor::loadConfig_sensorSpecific(), mrpt::hwdrivers::CKinect::loadConfig_sensorSpecific(), mrpt::hwdrivers::CCameraSensor::loadConfig_sensorSpecific(), mrpt::maps::CGasConcentrationGridMap2D::TInsertionOptions::loadFromConfigFile(), mrpt::slam::CICP::TConfigParams::loadFromConfigFile(), mrpt::maps::CBeaconMap::TLikelihoodOptions::loadFromConfigFile(), mrpt::maps::CLandmarksMap::TInsertionOptions::loadFromConfigFile(), mrpt::vision::TStereoSystemParams::loadFromConfigFile(), mrpt::maps::CLandmarksMap::TLikelihoodOptions::loadFromConfigFile(), mrpt::vision::TMatchingOptions::loadFromConfigFile(), mrpt::maps::COccupancyGridMap2D::TLikelihoodOptions::loadFromConfigFile(), mrpt::hwdrivers::TCaptureOptions_DUO3D::loadOptionsFrom(), mrpt::hwdrivers::TCaptureOptions_FlyCapture2::loadOptionsFrom(), readConfigFile(), and run_test_pf_localization().

Here is the caller graph for this function:

◆ read_int()

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

Definition at line 118 of file CConfigFileBase.cpp.

Referenced by mrpt::detectors::CCascadeClassifierDetection::init(), mrpt::detectors::CFaceDetection::init(), mrpt::nav::PlannerTPS_VirtualBase::internal_loadConfig_PTG(), mrpt::maps::CRandomFieldGridMap2D::TInsertionOptionsCommon::internal_loadFromConfigFile_common(), 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::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::CHokuyoURG::loadConfig_sensorSpecific(), mrpt::hwdrivers::CGPSInterface::loadConfig_sensorSpecific(), mrpt::hwdrivers::COpenNI2_RGBD360::loadConfig_sensorSpecific(), mrpt::hwdrivers::COpenNI2Sensor::loadConfig_sensorSpecific(), mrpt::hwdrivers::CKinect::loadConfig_sensorSpecific(), mrpt::hwdrivers::CCameraSensor::loadConfig_sensorSpecific(), mrpt::maps::CGasConcentrationGridMap2D::TInsertionOptions::loadFromConfigFile(), mrpt::maps::CMultiMetricMapPDF::TPredictionParams::loadFromConfigFile(), mrpt::maps::CLandmarksMap::TInsertionOptions::loadFromConfigFile(), mrpt::vision::TStereoSystemParams::loadFromConfigFile(), mrpt::maps::CLandmarksMap::TLikelihoodOptions::loadFromConfigFile(), mrpt::vision::TMatchingOptions::loadFromConfigFile(), mrpt::maps::COccupancyGridMap2D::TLikelihoodOptions::loadFromConfigFile(), mrpt::vision::TMultiResDescOptions::loadFromConfigFile(), mrpt::hwdrivers::TCaptureOptions_DUO3D::loadOptionsFrom(), mrpt::hwdrivers::TCaptureOptions_FlyCapture2::loadOptionsFrom(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::loadParams(), readConfigFile(), mrpt::gui::CPanelCameraSelection::readConfigIntoVideoSourcePanel(), run_test_pf_localization(), and TEST().

Here is the caller graph for this function:

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

References mrpt::utils::CConfigFileBase::readString(), and THROW_EXCEPTION_FMT.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_string()

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

Definition at line 162 of file CConfigFileBase.cpp.

References mrpt::system::trim().

Referenced by mrpt::detectors::CCascadeClassifierDetection::init(), mrpt::nav::PlannerTPS_VirtualBase::internal_loadConfig_PTG(), mrpt::maps::CRandomFieldGridMap2D::TInsertionOptionsCommon::internal_loadFromConfigFile_common(), 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::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::CHokuyoURG::loadConfig_sensorSpecific(), mrpt::hwdrivers::CGPSInterface::loadConfig_sensorSpecific(), mrpt::hwdrivers::COpenNI2Sensor::loadConfig_sensorSpecific(), mrpt::hwdrivers::CNationalInstrumentsDAQ::loadConfig_sensorSpecific(), mrpt::hwdrivers::CKinect::loadConfig_sensorSpecific(), mrpt::hwdrivers::CCameraSensor::loadConfig_sensorSpecific(), mrpt::maps::CGasConcentrationGridMap2D::TInsertionOptions::loadFromConfigFile(), mrpt::utils::TStereoCamera::loadFromConfigFile(), mrpt::maps::CHeightGridMap2D::TInsertionOptions::loadFromConfigFile(), mrpt::hwdrivers::TCaptureOptions_DUO3D::loadOptionsFrom(), mrpt::hwdrivers::TCaptureOptions_FlyCapture2::loadOptionsFrom(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::loadParams(), readConfigFile(), CGraphSlamHandler< GRAPH_T >::readConfigFname(), mrpt::gui::CPanelCameraSelection::readConfigIntoVideoSourcePanel(), run_test_pf_localization(), TEST(), and mrpt::gui::CPanelCameraSelection::writeConfigFromVideoSourcePanel().

Here is the call graph for this function:
Here is the caller graph for this function:

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

Definition at line 173 of file CConfigFileBase.cpp.

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_uint64_t()

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

References mrpt::utils::CConfigFileBase::readString(), and mrpt::system::tokenize().

Referenced by mrpt::hwdrivers::C2DRangeFinderAbstract::loadCommonParams(), mrpt::hwdrivers::CRoboticHeadInterface::loadConfig_sensorSpecific(), mrpt::hwdrivers::CBoardENoses::loadConfig_sensorSpecific(), mrpt::hwdrivers::CBoardSonars::loadConfig_sensorSpecific(), mrpt::utils::TCamera::loadFromConfigFile(), mrpt::vision::TStereoSystemParams::loadFromConfigFile(), mrpt::maps::COccupancyGridMap2D::TLikelihoodOptions::loadFromConfigFile(), mrpt::vision::TMultiResDescOptions::loadFromConfigFile(), and run_test_pf_localization().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readString()

std::string CConfigFile::readString ( const std::string section,
const std::string name,
const std::string defaultStr,
bool  failIfNotFound = false 
) const
overrideprotectedvirtual

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.

Implements mrpt::utils::CConfigFileBase.

Definition at line 108 of file CConfigFile.cpp.

References mrpt::format(), MRPT_END, MRPT_START, and THROW_EXCEPTION.

Here is the call graph for this function:

◆ sectionExists()

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

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

Definition at line 198 of file CConfigFileBase.cpp.

References mrpt::system::os::_strcmpi().

Referenced by mrpt::hwdrivers::CPhidgetInterfaceKitProximitySensors::loadConfig_sensorSpecific(), and mrpt::hwdrivers::COpenNI2Sensor::loadConfig_sensorSpecific().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFileName()

void CConfigFile::setFileName ( const std::string fil_path)

Associate this object with the given file, so future read/write operations will be applied to that file (it's synchronized at destruction)

Definition at line 53 of file CConfigFile.cpp.

References MRPT_END, and MRPT_START.

◆ write() [1/5]

template<typename enum_t , typename = std::enable_if_t<std::is_enum<enum_t>::value>>
void mrpt::utils::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() 
)
inlineinherited

◆ write() [2/5]

template<typename data_t , typename = std::enable_if_t<!std::is_enum<data_t>::value>>
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 96 of file CConfigFileBase.h.

References mrpt::utils::CConfigFileBase::writeString().

Here is the call graph for this function:

◆ write() [3/5]

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

References mrpt::utils::CConfigFileBase::writeString().

Here is the call graph for this function:

◆ write() [4/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() 
)
inherited

Definition at line 26 of file CConfigFileBase.cpp.

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

Definition at line 40 of file CConfigFileBase.cpp.

◆ writeNow()

void CConfigFile::writeNow ( )

Dumps the changes to the physical configuration file now, not waiting until destruction.

Definition at line 67 of file CConfigFile.cpp.

References MRPT_END, and MRPT_START.

◆ writeString() [1/2]

void CConfigFile::writeString ( const std::string section,
const std::string name,
const std::string str 
)
overrideprotectedvirtual

A virtual method to write a generic string.

Implements mrpt::utils::CConfigFileBase.

Definition at line 91 of file CConfigFile.cpp.

References MRPT_END, MRPT_START, and THROW_EXCEPTION.

◆ 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 
)
protectedinherited

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

Definition at line 58 of file CConfigFileBase.cpp.

References mrpt::format().

Here is the call graph for this function:

Member Data Documentation

◆ m_file

std::string mrpt::utils::CConfigFile::m_file
private

The name of the file.

Definition at line 39 of file CConfigFile.h.

Referenced by getAssociatedFile().

◆ m_ini

void_ptr_noncopy mrpt::utils::CConfigFile::m_ini
private

The interface to the file:

Definition at line 41 of file CConfigFile.h.

◆ m_modified

bool mrpt::utils::CConfigFile::m_modified
private

If modified since load.

Definition at line 43 of file CConfigFile.h.




Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019