MRPT  2.0.1
CConfigFilePrefixer.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "config-precomp.h" // Precompiled headers
11 
13 
14 using namespace mrpt::config;
15 using namespace std;
16 
19  const CConfigFileBase& o, const std::string& prefix_sections,
20  const std::string& prefix_keys)
21  : m_bound_object(const_cast<CConfigFileBase*>(&o)),
22  m_prefix_sections(prefix_sections),
23  m_prefix_keys(prefix_keys)
24 {
25 }
27 {
28  // Nothing to free manually
29 }
30 
32 {
33  m_bound_object = const_cast<CConfigFileBase*>(&o);
34 }
35 
37  const std::string& prefix_sections, const std::string& prefix_keys)
38 {
39  m_prefix_sections = prefix_sections;
40  m_prefix_keys = prefix_keys;
41 }
42 
44 {
45  return m_prefix_sections;
46 }
47 std::string CConfigFilePrefixer::getKeyPrefix() const { return m_prefix_keys; }
49 {
50  return m_bound_object;
51 }
52 
54 {
55  ASSERTMSG_(
57  "You must first bind CConfigFilePrefixer to an existing object!");
58 }
59 
61  std::vector<std::string>& sections) const
62 {
63  ensureIsBound();
64  m_bound_object->getAllSections(sections);
65  for (auto& section : sections) section = m_prefix_sections + section;
66 }
67 
69  const std::string& section, std::vector<std::string>& keys) const
70 {
71  ensureIsBound();
72  m_bound_object->getAllKeys(section, keys);
73  for (auto& key : keys) key = m_prefix_keys + key;
74 }
76 {
77  ensureIsBound();
79 }
80 
82  const std::string& section, const std::string& name, const std::string& str)
83 {
84  ensureIsBound();
86  m_prefix_sections + section, m_prefix_keys + name, str);
87 }
88 
90  const std::string& section, const std::string& name,
91  const std::string& defaultStr, bool failIfNotFound) const
92 {
93  ensureIsBound();
94  return m_bound_object->readString(
95  m_prefix_sections + section, m_prefix_keys + name, defaultStr,
96  failIfNotFound);
97 }
virtual void getAllKeys(const std::string &section, std::vector< std::string > &keys) const =0
Returs a list with all the keys into a section.
CConfigFileBase * getBoundConfigFileBase() const
Returns the currently-bounded config source, or nullptr if none.
STL namespace.
virtual void writeString(const std::string &section, const std::string &name, const std::string &str)=0
A virtual method to write a generic string.
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.
void clear() override
Empties the "config file".
This class allows loading and storing values and vectors of different types from a configuration text...
virtual void getAllSections(std::vector< std::string > &sections) const =0
Returns a list with all the section names.
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
Definition: exceptions.h:108
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.
virtual void clear()=0
Empties the "config file".
CConfigFileBase * m_bound_object
The object we are wrapping.
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.
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.



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020