MRPT  2.0.4
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 }
mrpt::config
Definition: config/CConfigFile.h:14
mrpt::config::CConfigFilePrefixer::readString
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.
Definition: CConfigFilePrefixer.cpp:89
mrpt::config::CConfigFilePrefixer::getKeyPrefix
std::string getKeyPrefix() const
Definition: CConfigFilePrefixer.cpp:47
mrpt::config::CConfigFileBase::readString
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.
mrpt::config::CConfigFilePrefixer::setPrefixes
void setPrefixes(const std::string &prefix_sections, const std::string &prefix_keys)
Change the prefix for sections and keys.
Definition: CConfigFilePrefixer.cpp:36
mrpt::config::CConfigFilePrefixer::m_bound_object
CConfigFileBase * m_bound_object
The object we are wrapping.
Definition: CConfigFilePrefixer.h:41
config-precomp.h
mrpt::config::CConfigFilePrefixer::getBoundConfigFileBase
CConfigFileBase * getBoundConfigFileBase() const
Returns the currently-bounded config source, or nullptr if none.
Definition: CConfigFilePrefixer.cpp:48
mrpt::config::CConfigFilePrefixer::ensureIsBound
void ensureIsBound() const
Definition: CConfigFilePrefixer.cpp:53
mrpt::config::CConfigFilePrefixer::getSectionPrefix
std::string getSectionPrefix() const
Definition: CConfigFilePrefixer.cpp:43
mrpt::config::CConfigFilePrefixer::m_prefix_keys
std::string m_prefix_keys
Definition: CConfigFilePrefixer.h:42
mrpt::config::CConfigFilePrefixer::bind
void bind(const CConfigFileBase &o)
Make this object to wrap the given existing CConfigFileBase object.
Definition: CConfigFilePrefixer.cpp:31
mrpt::config::CConfigFilePrefixer::CConfigFilePrefixer
CConfigFilePrefixer()
Unbound constructor: must bind this object to CConfigFileBase before usage with bind() and setPrefixe...
mrpt::config::CConfigFileBase::writeString
virtual void writeString(const std::string &section, const std::string &name, const std::string &str)=0
A virtual method to write a generic string.
mrpt::config::CConfigFilePrefixer::clear
void clear() override
Empties the "config file".
Definition: CConfigFilePrefixer.cpp:75
CConfigFilePrefixer.h
mrpt::config::CConfigFileBase
This class allows loading and storing values and vectors of different types from a configuration text...
Definition: config/CConfigFileBase.h:44
mrpt::config::CConfigFileBase::clear
virtual void clear()=0
Empties the "config file".
mrpt::config::CConfigFilePrefixer::getAllSections
void getAllSections(std::vector< std::string > &sections) const override
Returns a list with all the section names.
Definition: CConfigFilePrefixer.cpp:60
mrpt::config::CConfigFileBase::getAllSections
virtual void getAllSections(std::vector< std::string > &sections) const =0
Returns a list with all the section names.
ASSERTMSG_
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
Definition: exceptions.h:108
mrpt::config::CConfigFilePrefixer::getAllKeys
void getAllKeys(const std::string &section, std::vector< std::string > &keys) const override
Returs a list with all the keys into a section.
Definition: CConfigFilePrefixer.cpp:68
mrpt::config::CConfigFileBase::getAllKeys
virtual void getAllKeys(const std::string &section, std::vector< std::string > &keys) const =0
Returs a list with all the keys into a section.
mrpt::config::CConfigFilePrefixer::~CConfigFilePrefixer
~CConfigFilePrefixer() override
Definition: CConfigFilePrefixer.cpp:26
mrpt::config::CConfigFilePrefixer::m_prefix_sections
std::string m_prefix_sections
Definition: CConfigFilePrefixer.h:42
mrpt::config::CConfigFilePrefixer::writeString
void writeString(const std::string &section, const std::string &name, const std::string &str) override
A virtual method to write a generic string.
Definition: CConfigFilePrefixer.cpp:81



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sun Jul 19 15:15:43 UTC 2020