Main MRPT website > C++ reference for MRPT 1.9.9
CConfigFilePrefixer.cpp
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 
10 #include "base-precomp.h" // Precompiled headers
11 
13 
14 using namespace mrpt;
15 using namespace mrpt::utils;
16 using namespace std;
17 
18 CConfigFilePrefixer::CConfigFilePrefixer() : m_bound_object(nullptr) {}
20  const CConfigFileBase& o, const std::string& prefix_sections,
21  const std::string& prefix_keys)
22  : m_bound_object(const_cast<CConfigFileBase*>(&o)),
23  m_prefix_sections(prefix_sections),
24  m_prefix_keys(prefix_keys)
25 {
26 }
28 {
29  // Nothing to free manually
30 }
31 
33 {
34  m_bound_object = const_cast<CConfigFileBase*>(&o);
35 }
36 
38  const std::string& prefix_sections, const std::string& prefix_keys)
39 {
40  m_prefix_sections = prefix_sections;
41  m_prefix_keys = prefix_keys;
42 }
43 
45 {
46  return m_prefix_sections;
47 }
50 {
51  return m_bound_object;
52 }
53 
55 {
56  ASSERTMSG_(
58  "You must first bind CConfigFilePrefixer to an existing object!")
59  m_bound_object->getAllSections(sections);
60  for (size_t i = 0; i < sections.size(); i++)
61  sections[i] = m_prefix_sections + sections[i];
62 }
63 
65  const std::string& section, vector_string& keys) const
66 {
67  ASSERTMSG_(
69  "You must first bind CConfigFilePrefixer to an existing object!")
70  m_bound_object->getAllKeys(section, keys);
71  for (size_t i = 0; i < keys.size(); i++) keys[i] = m_prefix_keys + keys[i];
72 }
73 
75  const std::string& section, const std::string& name, const std::string& str)
76 {
77  ASSERTMSG_(
79  "You must first bind CConfigFilePrefixer to an existing object!")
81  m_prefix_sections + section, m_prefix_keys + name, str);
82 }
83 
85  const std::string& section, const std::string& name,
86  const std::string& defaultStr, bool failIfNotFound) const
87 {
88  ASSERTMSG_(
90  "You must first bind CConfigFilePrefixer to an existing object!")
91  return m_bound_object->readString(
92  m_prefix_sections + section, m_prefix_keys + name, defaultStr,
93  failIfNotFound);
94 }
virtual void getAllKeys(const std::string &section, vector_string &keys) const =0
Returs a list with all the keys into a section.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
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.
virtual std::string readString(const std::string &section, const std::string &name, const std::string &defaultStr, bool failIfNotFound=false) const =0
A virtual method to read a generic string.
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:33
virtual void getAllSections(vector_string &sections) const =0
Returns a list with all the section names.
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
#define ASSERTMSG_(f, __ERROR_MSG)
void bind(const CConfigFileBase &o)
Make this object to wrap the given existing CConfigFileBase object.
virtual void writeString(const std::string &section, const std::string &name, const std::string &str)=0
A virtual method to write a generic string.



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