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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019