Main MRPT website > C++ reference for MRPT 1.9.9
CConfigFilePrefixer.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
12 
13 namespace mrpt
14 {
15 namespace config
16 {
17 /** A wrapper for other CConfigFileBase-based objects that prefixes a given
18  * token to every key and/or section.
19  * If, for example, your code expect:
20  * \code
21  * [params1]
22  * foo = 34.0
23  * bar = /dev/ttyUSB0
24  * \endcode
25  *
26  * Using this class with key entries prefix "s1_" will enable the same
27  * existing code to transparently parse this file content:
28  *
29  * \code
30  * [params1]
31  * s1_foo = 34.0
32  * s1_bar = /dev/ttyUSB0
33  * \endcode
34  *
35  * See: \ref config_file_format
36  * \sa CConfigFileBase
37  * \ingroup mrpt_config_grp
38  */
40 {
41  private:
42  /** The object we are wrapping */
45 
46  protected:
47  void writeString(
48  const std::string& section, const std::string& name,
49  const std::string& str) override;
51  const std::string& section, const std::string& name,
52  const std::string& defaultStr,
53  bool failIfNotFound = false) const override;
54 
55  public:
56  /** Unbound constructor: must bind this object to CConfigFileBase before
57  * usage with \a bind() and \a setPrefixes() */
59  /** Construct and bind to (wrap) a given object with given prefix texts */
61  const CConfigFileBase& o, const std::string& prefix_sections,
62  const std::string& prefix_keys);
63 
64  /** Make this object to wrap the given existing CConfigFileBase object. Can
65  * be changed at any moment after construction */
66  void bind(const CConfigFileBase& o);
67 
68  /** Change the prefix for sections and keys. Can be called at any moment. */
69  void setPrefixes(
70  const std::string& prefix_sections, const std::string& prefix_keys);
71 
73  std::string getKeyPrefix() const;
74  /** Returns the currently-bounded config source, or nullptr if none. */
76 
77  virtual ~CConfigFilePrefixer();
78 
79  void getAllSections(std::vector<std::string>& sections)
80  const override; // See base class docs
81  void getAllKeys(const std::string& section, std::vector<std::string>& keys)
82  const override; // See base class docs
83 
84 }; // End of class def.
85 } // End of namespace
86 } // end of namespace
mrpt::config::CConfigFilePrefixer::readString
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.
Definition: CConfigFilePrefixer.cpp:84
mrpt::config::CConfigFilePrefixer::getKeyPrefix
std::string getKeyPrefix() const
Definition: CConfigFilePrefixer.cpp:47
mrpt::config::CConfigFilePrefixer::setPrefixes
void setPrefixes(const std::string &prefix_sections, const std::string &prefix_keys)
Change the prefix for sections and keys.
Definition: CConfigFilePrefixer.cpp:36
mrpt::config::CConfigFilePrefixer::m_bound_object
CConfigFileBase * m_bound_object
The object we are wrapping.
Definition: CConfigFilePrefixer.h:43
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::config::CConfigFilePrefixer::getBoundConfigFileBase
CConfigFileBase * getBoundConfigFileBase() const
Returns the currently-bounded config source, or nullptr if none.
Definition: CConfigFilePrefixer.cpp:48
mrpt::config::CConfigFilePrefixer::getSectionPrefix
std::string getSectionPrefix() const
Definition: CConfigFilePrefixer.cpp:43
mrpt::config::CConfigFilePrefixer::m_prefix_keys
std::string m_prefix_keys
Definition: CConfigFilePrefixer.h:44
mrpt::config::CConfigFilePrefixer::bind
void bind(const CConfigFileBase &o)
Make this object to wrap the given existing CConfigFileBase object.
Definition: CConfigFilePrefixer.cpp:31
name
GLuint const GLchar * name
Definition: glext.h:4054
mrpt::config::CConfigFilePrefixer::CConfigFilePrefixer
CConfigFilePrefixer()
Unbound constructor: must bind this object to CConfigFileBase before usage with bind() and setPrefixe...
Definition: CConfigFilePrefixer.cpp:17
CConfigFileBase.h
mrpt::config::CConfigFileBase
This class allows loading and storing values and vectors of different types from a configuration text...
Definition: config/CConfigFileBase.h:44
mrpt::config::CConfigFilePrefixer
A wrapper for other CConfigFileBase-based objects that prefixes a given token to every key and/or sec...
Definition: CConfigFilePrefixer.h:39
mrpt::config::CConfigFilePrefixer::getAllSections
void getAllSections(std::vector< std::string > &sections) const override
Returns a list with all the section names.
Definition: CConfigFilePrefixer.cpp:53
mrpt::config::CConfigFilePrefixer::~CConfigFilePrefixer
virtual ~CConfigFilePrefixer()
Definition: CConfigFilePrefixer.cpp:26
mrpt::config::CConfigFilePrefixer::getAllKeys
void getAllKeys(const std::string &section, std::vector< std::string > &keys) const override
Returs a list with all the keys into a section.
Definition: CConfigFilePrefixer.cpp:64
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::config::CConfigFilePrefixer::m_prefix_sections
std::string m_prefix_sections
Definition: CConfigFilePrefixer.h:44
mrpt::config::CConfigFilePrefixer::writeString
void writeString(const std::string &section, const std::string &name, const std::string &str) override
A virtual method to write a generic string.
Definition: CConfigFilePrefixer.cpp:74



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