MRPT  1.9.9
config/CConfigFileMemory.h
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 #pragma once
10 
12 #include <mrpt/core/pimpl.h>
13 #include <string>
14 #include <vector>
15 
16 namespace mrpt::config
17 {
18 /** This class implements a config file-like interface over a memory-stored
19  * string list.
20  *
21  * Use base class `CConfigFileBase`'s methods
22  * `read_{int,float,double,string,...}()` and `write()` to actually read and
23  * write values.
24  *
25  * It can also parse a YAML text block and expose its fields (up to the first
26  * level of hierarchy, as allowed by INI-like files). This can be used to port
27  * MRPT classes relying on INI files to using YAML files transparently.
28  * This feature required building MRPT with yaml-cpp, and is provided by
29  * CConfigFileMemory::setContentFromYAML().
30  *
31  * See: \ref config_file_format
32  *
33  * \ingroup mrpt_base_grp
34  * \note YAML support was introduced in MRPT 1.9.9
35  */
37 {
38  public:
39  /** Empty constructor. Upon construction, call any of the "setContent"
40  * method */
42  /** Constructor and initialize from a list of strings */
43  CConfigFileMemory(const std::vector<std::string>& stringList);
44  /** Constructor and initialize from string with the whole "config file" */
45  CConfigFileMemory(const std::string& str);
46  /** dtor */
47  ~CConfigFileMemory() override;
48 
49  /** Changes the contents of the virtual "config file" */
50  void setContent(const std::vector<std::string>& stringList);
51  /** Changes the contents of the virtual "config file" */
52  void setContent(const std::string& str);
53  /** Return the current contents of the virtual "config file" */
54  void getContent(std::string& str) const;
55  /** \overload */
56  inline std::string getContent() const
57  {
58  std::string s;
59  getContent(s);
60  return s;
61  }
62 
63  /** Empties the virtual "config file" */
64  void clear() override;
65 
66  /** Returns a list with all the section names */
67  void getAllSections(std::vector<std::string>& sections) const override;
68  /** Returs a list with all the keys into a section */
69  void getAllKeys(const std::string& section, std::vector<std::string>& keys)
70  const override;
71 
72  private:
73  /** The IniFile object */
74  struct Impl;
76 
77  protected:
78  /** A virtual method to write a generic string */
79  void writeString(
80  const std::string& section, const std::string& name,
81  const std::string& str) override;
82  /** A virtual method to read a generic string */
83  std::string readString(
84  const std::string& section, const std::string& name,
85  const std::string& defaultStr,
86  bool failIfNotFound = false) const override;
87 
88 }; // End of class def.
89 
90 } // namespace mrpt::config
This class implements a config file-like interface over a memory-stored string list.
CConfigFileMemory()
Empty constructor.
~CConfigFileMemory() override
dtor
spimpl::impl_ptr< T > pimpl
Definition: pimpl.h:15
void getAllKeys(const std::string &section, std::vector< std::string > &keys) const override
Returs a list with all the keys into a section.
This class allows loading and storing values and vectors of different types from a configuration text...
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.
void getAllSections(std::vector< std::string > &sections) const override
Returns a list with all the section names.
void clear() override
Empties the virtual "config file".
void setContent(const std::vector< std::string > &stringList)
Changes the contents of the virtual "config file".
void writeString(const std::string &section, const std::string &name, const std::string &str) override
A virtual method to write a generic string.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020