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-2018, 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 "config-precomp.h" // Precompiled headers
11 
13 
14 using namespace mrpt::config;
15 using namespace std;
16 
17 CConfigFilePrefixer::CConfigFilePrefixer() : m_bound_object(nullptr) {}
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 }
49 {
50  return m_bound_object;
51 }
52 
54  std::vector<std::string>& sections) const
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, std::vector<std::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 }
mrpt::config
Definition: config/CConfigFile.h:16
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:84
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:43
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::getSectionPrefix
std::string getSectionPrefix() const
Definition: CConfigFilePrefixer.cpp:43
mrpt::config::CConfigFilePrefixer::m_prefix_keys
std::string m_prefix_keys
Definition: CConfigFilePrefixer.h:44
mrpt::config::CConfigFilePrefixer::bind
void bind(const CConfigFileBase &o)
Make this object to wrap the given existing CConfigFileBase object.
Definition: CConfigFilePrefixer.cpp:31
name
GLuint const GLchar * name
Definition: glext.h:4054
mrpt::config::CConfigFilePrefixer::CConfigFilePrefixer
CConfigFilePrefixer()
Unbound constructor: must bind this object to CConfigFileBase before usage with bind() and setPrefixe...
Definition: CConfigFilePrefixer.cpp:17
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.
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::CConfigFilePrefixer::getAllSections
void getAllSections(std::vector< std::string > &sections) const override
Returns a list with all the section names.
Definition: CConfigFilePrefixer.cpp:53
mrpt::config::CConfigFileBase::getAllSections
virtual void getAllSections(std::vector< std::string > &sections) const =0
Returns a list with all the section names.
mrpt::config::CConfigFilePrefixer::~CConfigFilePrefixer
virtual ~CConfigFilePrefixer()
Definition: CConfigFilePrefixer.cpp:26
ASSERTMSG_
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
Definition: exceptions.h:101
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:64
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.
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::config::CConfigFilePrefixer::m_prefix_sections
std::string m_prefix_sections
Definition: CConfigFilePrefixer.h:44
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:74



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST