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



Page generated by Doxygen 1.8.9.1 for MRPT 1.3.2 SVN:Unversioned directory at Tue Dec 8 09:49:21 UTC 2015