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-2017, 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 utils
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_base_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(
80  vector_string& sections) const override; // See base class docs
81  void getAllKeys(const std::string& section, vector_string& keys)
82  const override; // See base class docs
83 
84 }; // End of class def.
85 } // End of namespace
86 } // end of namespace
A wrapper for other CConfigFileBase-based objects that prefixes a given token to every key and/or sec...
CConfigFilePrefixer()
Unbound constructor: must bind this object to CConfigFileBase before usage with bind() and setPrefixe...
void setPrefixes(const std::string &prefix_sections, const std::string &prefix_keys)
Change the prefix for sections and keys.
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.
This class allows loading and storing values and vectors of different types from a configuration text...
std::vector< std::string > vector_string
A type for passing a vector of strings.
Definition: types_simple.h:33
GLsizei const GLchar ** string
Definition: glext.h:4101
void getAllKeys(const std::string &section, vector_string &keys) const override
Returs a list with all the keys into a section.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void writeString(const std::string &section, const std::string &name, const std::string &str) override
A virtual method to write a generic string.
CConfigFileBase * getBoundConfigFileBase() const
Returns the currently-bounded config source, or nullptr if none.
CConfigFileBase * m_bound_object
The object we are wrapping.
void getAllSections(vector_string &sections) const override
Returns a list with all the section names.
GLuint const GLchar * name
Definition: glext.h:4054
void bind(const CConfigFileBase &o)
Make this object to wrap the given existing CConfigFileBase object.



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