Main MRPT website > C++ reference for MRPT 1.9.9
config/CConfigFile.h
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 #pragma once
10 
12 #include <mrpt/core/pimpl.h>
13 
14 namespace mrpt
15 {
16 namespace config
17 {
18 /** This class allows loading and storing values and vectors of different types
19  * from ".ini" files easily.
20  * The contents of the file will be modified by "write" operations in memory,
21  * and will be saved back
22  * to the file at the destructor, and only if at least one write operation
23  * has been applied.
24  *
25  * Use base class `CConfigFileBase`'s methods
26  * `read_{int,float,double,string,...}()` and `write()` to actually read and
27  * write values.
28  *
29  * See: \ref config_file_format
30  *
31  * \ingroup mrpt_base_grp
32  */
34 {
35  private:
36  /** The name of the file */
38  /** The interface to the file: */
39  struct Impl;
41  /** If modified since load. */
42  bool m_modified;
43 
44  protected:
45  /** A virtual method to write a generic string */
46  void writeString(
47  const std::string& section, const std::string& name,
48  const std::string& str) override;
49 
50  /** A virtual method to read a generic string.
51  * \exception std::exception If the key name is not found and
52  * "failIfNotFound" is true. Otherwise the "defaultValue" is returned. */
54  const std::string& section, const std::string& name,
55  const std::string& defaultStr,
56  bool failIfNotFound = false) const override;
57 
58  public:
59  /** Constructor that opens a configuration file. */
60  CConfigFile(const std::string& fileName);
61 
62  /** Constructor, does not open any file. You should call "setFileName"
63  * before reading or writting or otherwise nothing will be read and write
64  * operations will be eventually lost.
65  * However, it's perfectly right to use this object without an associated
66  * file, in which case it will behave as an "in-memory" file.
67  */
68  CConfigFile();
69 
70  /** Associate this object with the given file, so future read/write
71  * operations will be applied to that file (it's synchronized at
72  * destruction) */
73  void setFileName(const std::string& fil_path);
74 
75  /** Dumps the changes to the physical configuration file now, not waiting
76  * until destruction. */
77  void writeNow();
78 
79  /** Discard saving (current) changes to physical file upon destruction */
80  void discardSavingChanges();
81 
82  /** Returns the file currently open by this object. */
83  std::string getAssociatedFile() const { return m_file; }
84  /** Destructor */
85  virtual ~CConfigFile();
86 
87  /** Returns a list with all the section names. */
88  virtual void getAllSections(
89  std::vector<std::string>& sections) const override;
90 
91  /** Returs a list with all the keys into a section. */
92  virtual void getAllKeys(
93  const std::string& section,
94  std::vector<std::string>& keys) const override;
95 
96 }; // End of class def.
97 
98 } // End of namespace
99 } // end of namespace
mrpt::pimpl< Impl > m_impl
void writeString(const std::string &section, const std::string &name, const std::string &str) override
A virtual method to write a generic string.
Definition: CConfigFile.cpp:95
virtual void getAllSections(std::vector< std::string > &sections) const override
Returns a list with all the section names.
spimpl::impl_ptr< T > pimpl
Definition: pimpl.h:15
bool m_modified
If modified since load.
This class allows loading and storing values and vectors of different types from ".ini" files easily.
CConfigFile()
Constructor, does not open any file.
Definition: CConfigFile.cpp:44
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.
This class allows loading and storing values and vectors of different types from a configuration text...
GLsizei const GLchar ** string
Definition: glext.h:4101
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void writeNow()
Dumps the changes to the physical configuration file now, not waiting until destruction.
Definition: CConfigFile.cpp:72
GLuint const GLchar * name
Definition: glext.h:4054
std::string m_file
The name of the file.
std::string getAssociatedFile() const
Returns the file currently open by this object.
void setFileName(const std::string &fil_path)
Associate this object with the given file, so future read/write operations will be applied to that fi...
Definition: CConfigFile.cpp:58
void discardSavingChanges()
Discard saving (current) changes to physical file upon destruction.
Definition: CConfigFile.cpp:83
virtual void getAllKeys(const std::string &section, std::vector< std::string > &keys) const override
Returs a list with all the keys into a section.
virtual ~CConfigFile()
Destructor.
Definition: CConfigFile.cpp:87



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019