Main MRPT website > C++ reference for MRPT 1.5.6
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 
19  m_bound_object(NULL)
20 {
21 }
22 CConfigFilePrefixer::CConfigFilePrefixer(const CConfigFileBase &o, const std::string &prefix_sections, const std::string &prefix_keys) :
23  m_bound_object( const_cast<CConfigFileBase*>(&o) ),
24  m_prefix_sections(prefix_sections),
25  m_prefix_keys(prefix_keys)
26 {
27 }
29 {
30  // Nothing to free manually
31 }
32 
34 {
35  m_bound_object = const_cast<CConfigFileBase*>(&o);
36 }
37 
38 void CConfigFilePrefixer::setPrefixes(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  return m_prefix_sections;
46 }
48  return m_prefix_keys;
49 }
51  return m_bound_object;
52 }
53 
55 {
56  ASSERTMSG_(m_bound_object, "You must first bind CConfigFilePrefixer to an existing object!")
57  m_bound_object->getAllSections(sections);
58  for (size_t i=0;i<sections.size();i++)
59  sections[i] = m_prefix_sections + sections[i];
60 }
61 
62 void CConfigFilePrefixer::getAllKeys( const std::string &section, vector_string &keys ) const
63 {
64  ASSERTMSG_(m_bound_object, "You must first bind CConfigFilePrefixer to an existing object!")
65  m_bound_object->getAllKeys(section,keys);
66  for (size_t i=0;i<keys.size();i++)
67  keys[i] = m_prefix_keys + keys[i];
68 }
69 
71 {
72  ASSERTMSG_(m_bound_object, "You must first bind CConfigFilePrefixer to an existing object!")
74 }
75 
76 std::string CConfigFilePrefixer::readString(const std::string &section,const std::string &name,const std::string &defaultStr,bool failIfNotFound ) const
77 {
78  ASSERTMSG_(m_bound_object, "You must first bind CConfigFilePrefixer to an existing object!")
79  return m_bound_object->readString( m_prefix_sections + section, m_prefix_keys + name, defaultStr,failIfNotFound);
80 }
virtual void getAllKeys(const std::string &section, vector_string &keys) const =0
Returs a list with all the keys into a section.
void getAllKeys(const std::string &section, vector_string &keys) const MRPT_OVERRIDE
Returs a list with all the keys into a section.
void writeString(const std::string &section, const std::string &name, const std::string &str) MRPT_OVERRIDE
A virtual method to write a generic string.
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.
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.
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.
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:30
void getAllSections(vector_string &sections) const MRPT_OVERRIDE
Returns a list with all the section names.
virtual void getAllSections(vector_string &sections) const =0
Returns a list with all the section names.
GLuint const GLchar * name
Definition: glew.h:1721
GLsizei const GLcharARB ** string
Definition: glew.h:3293
CConfigFileBase * m_bound_object
The object we are wrapping.
CConfigFileBase * getBoundConfigFileBase() const
Returns the currently-bounded config source, or NULL if none.
#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.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018