class mrpt::config::CConfigFilePrefixer
Overview
A wrapper for other CConfigFileBase-based objects that prefixes a given token to every key and/or section.
If, for example, your code expect:
[params1] foo = 34.0 bar = /dev/ttyUSB0
Using this class with key entries prefix s1_
will enable the same existing code to transparently parse this file content:
[params1] s1_foo = 34.0 s1_bar = /dev/ttyUSB0
See: Configuration file format in MRPT
See also:
#include <mrpt/config/CConfigFilePrefixer.h> class CConfigFilePrefixer: public mrpt::config::CConfigFileBase { public: // construction CConfigFilePrefixer(); CConfigFilePrefixer(const CConfigFileBase& o, const std::string& prefix_sections, const std::string& prefix_keys); // 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; std::string read_string( const std::string& section, const std::string& name, const std::string& defaultValue, bool failIfNotFound = false ) const; void bind(const CConfigFileBase& o); void setPrefixes(const std::string& prefix_sections, const std::string& prefix_keys); std::string getSectionPrefix() const; std::string getKeyPrefix() const; CConfigFileBase* getBoundConfigFileBase() const; virtual void getAllSections(std::vector<std::string>& sections) const; virtual void getAllKeys(const std::string& section, std::vector<std::string>& keys) const; virtual void clear(); 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() ); };
Inherited Members
public: // methods virtual void getAllSections(std::vector<std::string>& sections) const = 0; virtual void getAllKeys(const std::string& section, std::vector<std::string>& keys) const = 0; virtual void clear() = 0;
Construction
CConfigFilePrefixer()
Unbound constructor: must bind this object to CConfigFileBase before usage with bind() and setPrefixes()
CConfigFilePrefixer( const CConfigFileBase& o, const std::string& prefix_sections, const std::string& prefix_keys )
Construct and bind to (wrap) a given object with given prefix texts.
Methods
void bind(const CConfigFileBase& o)
Make this object to wrap the given existing CConfigFileBase object.
Can be changed at any moment after construction
void setPrefixes( const std::string& prefix_sections, const std::string& prefix_keys )
Change the prefix for sections and keys.
Can be called at any moment.
CConfigFileBase* getBoundConfigFileBase() const
Returns the currently-bounded config source, or nullptr if none.
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
Returs a list with all the keys into a section.
virtual void clear()
Empties the “config file”.