Main MRPT website > C++ reference for MRPT 1.5.7
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 token to every key and/or section.
18  * If, for example, your code expect:
19  * \code
20  * [params1]
21  * foo = 34.0
22  * bar = /dev/ttyUSB0
23  * \endcode
24  *
25  * Using this class with key entries prefix "s1_" will enable the same 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_base_grp
36  */
38  {
39  private:
40  CConfigFileBase *m_bound_object; //!< The object we are wrapping
42 
43  protected:
44  void writeString(const std::string &section,const std::string &name, const std::string &str) MRPT_OVERRIDE;
45  std::string readString(const std::string &section,const std::string &name,const std::string &defaultStr,bool failIfNotFound = false) const MRPT_OVERRIDE;
46 
47  public:
48  /** Unbound constructor: must bind this object to CConfigFileBase before usage with \a bind() and \a setPrefixes() */
50  /** Construct and bind to (wrap) a given object with given prefix texts */
51  CConfigFilePrefixer(const CConfigFileBase &o, const std::string &prefix_sections, const std::string &prefix_keys);
52 
53  /** Make this object to wrap the given existing CConfigFileBase object. Can be changed at any moment after construction */
54  void bind(const CConfigFileBase &o);
55 
56  /** Change the prefix for sections and keys. Can be called at any moment. */
57  void setPrefixes(const std::string &prefix_sections, const std::string &prefix_keys);
58 
59  std::string getSectionPrefix() const;
60  std::string getKeyPrefix() const;
61  CConfigFileBase *getBoundConfigFileBase() const; //!< Returns the currently-bounded config source, or NULL if none.
62 
63  virtual ~CConfigFilePrefixer();
64 
65  void getAllSections( vector_string &sections ) const MRPT_OVERRIDE; // See base class docs
66  void getAllKeys( const std::string &section, vector_string &keys ) const MRPT_OVERRIDE; // See base class docs
67 
68  }; // End of class def.
69 } // End of namespace
70 } // end of namespace
A wrapper for other CConfigFileBase-based objects that prefixes a given token to every key and/or sec...
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
STL namespace.
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:30
GLsizei const GLchar ** string
Definition: glext.h:3919
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CConfigFileBase * m_bound_object
The object we are wrapping.
GLuint const GLchar * name
Definition: glext.h:3891



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019