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::config
14 {
15 /** A wrapper for other CConfigFileBase-based objects that prefixes a given
16  * token to every key and/or section.
17  * If, for example, your code expect:
18  * \code
19  * [params1]
20  * foo = 34.0
21  * bar = /dev/ttyUSB0
22  * \endcode
23  *
24  * Using this class with key entries prefix "s1_" will enable the same
25  * existing code to transparently parse this file content:
26  *
27  * \code
28  * [params1]
29  * s1_foo = 34.0
30  * s1_bar = /dev/ttyUSB0
31  * \endcode
32  *
33  * See: \ref config_file_format
34  * \sa CConfigFileBase
35  * \ingroup mrpt_config_grp
36  */
38 {
39  private:
40  /** The object we are wrapping */
43 
44  protected:
45  void writeString(
46  const std::string& section, const std::string& name,
47  const std::string& str) override;
49  const std::string& section, const std::string& name,
50  const std::string& defaultStr,
51  bool failIfNotFound = false) const override;
52 
53  public:
54  /** Unbound constructor: must bind this object to CConfigFileBase before
55  * usage with \a bind() and \a setPrefixes() */
57  /** Construct and bind to (wrap) a given object with given prefix texts */
59  const CConfigFileBase& o, const std::string& prefix_sections,
60  const std::string& prefix_keys);
61 
62  /** Make this object to wrap the given existing CConfigFileBase object. Can
63  * be changed at any moment after construction */
64  void bind(const CConfigFileBase& o);
65 
66  /** Change the prefix for sections and keys. Can be called at any moment. */
67  void setPrefixes(
68  const std::string& prefix_sections, const std::string& prefix_keys);
69 
71  std::string getKeyPrefix() const;
72  /** Returns the currently-bounded config source, or nullptr if none. */
74 
75  virtual ~CConfigFilePrefixer();
76 
77  void getAllSections(std::vector<std::string>& sections)
78  const override; // See base class docs
79  void getAllKeys(const std::string& section, std::vector<std::string>& keys)
80  const override; // See base class docs
81 
82 }; // End of class def.
83 }
84 
CConfigFileBase * getBoundConfigFileBase() const
Returns the currently-bounded config source, or nullptr if none.
CConfigFilePrefixer()
Unbound constructor: must bind this object to CConfigFileBase before usage with bind() and setPrefixe...
void writeString(const std::string &section, const std::string &name, const std::string &str) override
A virtual method to write a generic string.
This class allows loading and storing values and vectors of different types from a configuration text...
A wrapper for other CConfigFileBase-based objects that prefixes a given token to every key and/or sec...
GLsizei const GLchar ** string
Definition: glext.h:4101
void getAllSections(std::vector< std::string > &sections) const override
Returns a list with all the section names.
void bind(const CConfigFileBase &o)
Make this object to wrap the given existing CConfigFileBase object.
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.
CConfigFileBase * m_bound_object
The object we are wrapping.
GLuint const GLchar * name
Definition: glext.h:4054
void getAllKeys(const std::string &section, std::vector< std::string > &keys) const override
Returs a list with all the keys into a section.
void setPrefixes(const std::string &prefix_sections, const std::string &prefix_keys)
Change the prefix for sections and keys.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020