class mrpt::config::CConfigFileMemory
Python API: mrpt.config.CConfigFileMemory
Overview
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.
It can also parse a YAML text block and expose its fields (up to the first level of hierarchy, as allowed by INI-like files). This can be used to port MRPT classes relying on INI files to using YAML files transparently. This feature required building MRPT with yaml-cpp, and is provided by CConfigFileMemory::setContentFromYAML().
See: Configuration file format in MRPT
YAML support was introduced in MRPT 1.9.9
#include <mrpt/config/CConfigFileMemory.h> class CConfigFileMemory: public mrpt::config::CConfigFileBase { public: // structs struct Impl; // construction CConfigFileMemory(); CConfigFileMemory(const CConfigFileMemory&); CConfigFileMemory(CConfigFileMemory&&); CConfigFileMemory(const std::vector<std::string>& stringList); CConfigFileMemory(const std::string& str); // methods CConfigFileMemory& operator = (const CConfigFileMemory&); CConfigFileMemory& operator = (CConfigFileMemory&&); void setContent(const std::vector<std::string>& stringList); void setContent(const std::string& str); std::string getContent() const; virtual void clear(); virtual void getAllSections(std::vector<std::string>& sections) const; virtual void getAllKeys(const std::string& section, std::vector<std::string>& keys) const; };
Inherited Members
public: // methods 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() ); 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; uint32_t read_uint32_t( const std::string& section, const std::string& name, uint32_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; 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; 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; template <typename ENUMTYPE> ENUMTYPE read_enum( const std::string& section, const std::string& name, const ENUMTYPE& defaultValue, bool failIfNotFound = false ) const; CConfigFileBase& operator = (const CConfigFileBase&); CConfigFileBase& operator = (CConfigFileBase&&); virtual void getAllSections(std::vector<std::string>& sections) const = 0; std::vector<std::string> sections() const; virtual void getAllKeys(const std::string& section, std::vector<std::string>& keys) const = 0; std::vector<std::string> keys(const std::string& section) const; bool sectionExists(const std::string& section_name) const; bool keyExists(const std::string& section, const std::string& key) const; void setContentFromYAML(const std::string& yaml_block); std::string getContentAsYAML() const; virtual void clear() = 0; 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() );
Construction
CConfigFileMemory()
Empty constructor.
Upon construction, call any of the “setContent” method
CConfigFileMemory(const std::vector<std::string>& stringList)
Constructor and initialize from a list of strings.
CConfigFileMemory(const std::string& str)
Constructor and initialize from string with the whole “config file”.
Methods
void setContent(const std::vector<std::string>& stringList)
Changes the contents of the virtual “config file”.
void setContent(const std::string& str)
Changes the contents of the virtual “config file”.
std::string getContent() const
Return the current contents of the virtual “config file”.
virtual void clear()
Empties the virtual “config file”.
virtual void getAllSections(std::vector<std::string>& sections) const
Returns a list with all the section names.
virtual void getAllKeys( const std::string& section, std::vector<std::string>& keys ) const
Returns a list with all the keys into a section.