Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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
13namespace mrpt
14{
15namespace 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 * \sa CConfigFileBase
34 * \ingroup mrpt_base_grp
35 */
37 {
38 private:
39 CConfigFileBase *m_bound_object; //!< The object we are wrapping
40 std::string m_prefix_sections, m_prefix_keys;
41
42 protected:
43 void writeString(const std::string &section,const std::string &name, const std::string &str) MRPT_OVERRIDE;
44 std::string readString(const std::string &section,const std::string &name,const std::string &defaultStr,bool failIfNotFound = false) const MRPT_OVERRIDE;
45
46 public:
47 /** Unbound constructor: must bind this object to CConfigFileBase before usage with \a bind() and \a setPrefixes() */
49 /** Construct and bind to (wrap) a given object with given prefix texts */
50 CConfigFilePrefixer(const CConfigFileBase &o, const std::string &prefix_sections, const std::string &prefix_keys);
51
52 /** Make this object to wrap the given existing CConfigFileBase object. Can be changed at any moment after construction */
53 void bind(const CConfigFileBase &o);
54
55 /** Change the prefix for sections and keys. Can be called at any moment. */
56 void setPrefixes(const std::string &prefix_sections, const std::string &prefix_keys);
57
58 std::string getSectionPrefix() const;
59 std::string getKeyPrefix() const;
60 CConfigFileBase *getBoundConfigFileBase() const; //!< Returns the currently-bounded config source, or NULL if none.
61
63
64 void getAllSections( vector_string &sections ) const MRPT_OVERRIDE; // See base class docs
65 void getAllKeys( const std::string &section, vector_string &keys ) const MRPT_OVERRIDE; // See base class docs
66
67 }; // End of class def.
68} // End of namespace
69} // end of namespace
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...
CConfigFileBase * m_bound_object
The object we are wrapping.
void writeString(const std::string &section, const std::string &name, const std::string &str) MRPT_OVERRIDE
A virtual method to write a generic string.
std::string readString(const std::string &section, const std::string &name, const std::string &defaultStr, bool failIfNotFound=false) const MRPT_OVERRIDE
A virtual method to read a generic string.
std::vector< std::string > vector_string
A type for passing a vector of strings.
Definition: types_simple.h:30
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition: mrpt_macros.h:28
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
STL namespace.



Page generated by Doxygen 1.9.5 for MRPT 1.4.0 SVN: at Tue Dec 27 00:53:09 UTC 2022