Main MRPT website > C++ reference for MRPT 1.5.6
CLoadableOptions.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 CLoadableOptions_H
10 #define CLoadableOptions_H
11 
12 #include <mrpt/utils/core_defs.h>
13 #include <string>
14 #include <stdexcept>
15 
16 namespace mrpt
17 {
18 namespace utils
19 {
20  // Frwd. decls:
21  class CConfigFileBase;
22  class CStream;
23 
24  /** This is a virtual base class for sets of options than can be loaded from and/or saved to configuration plain-text files.
25  * \todo Automatize this class thru a proxy auxiliary class where variables are registered from pointers, etc...
26  * \ingroup mrpt_base_grp
27  */
29  {
30  protected:
31 
32  /** Used to print variable info from dumpToTextStream with the macro LOADABLEOPTS_DUMP_VAR */
33  static void dumpVar_int( CStream &out, const char *varName, int v );
34  static void dumpVar_float( CStream &out, const char *varName, float v );
35  static void dumpVar_double( CStream &out, const char *varName, double v );
36  static void dumpVar_bool( CStream &out, const char *varName, bool v );
37  static void dumpVar_string( CStream &out, const char *varName, const std::string &v );
38 
39 
40  public:
41  /** This method load the options from a ".ini"-like file or memory-stored string list.
42  * Only those parameters found in the given "section" and having
43  * the same name that the variable are loaded. Those not found in
44  * the file will stay with their previous values (usually the default
45  * values loaded at initialization). An example of an ".ini" file:
46  * \code
47  * [section]
48  * resolution = 0.10 // blah blah...
49  * modeSelection = 1 // 0=blah, 1=blah,...
50  * \endcode
51  *
52  * \sa loadFromConfigFileName, saveToConfigFile
53  */
54  virtual void loadFromConfigFile(
56  const std::string & section) = 0;
57 
58  /** Behaves like loadFromConfigFile, but you can pass directly a file name and a temporary CConfigFile object will be created automatically to load the file.
59  * \sa loadFromConfigFile
60  */
61  void loadFromConfigFileName(
62  const std::string & config_file,
63  const std::string & section);
64 
65  /** This method saves the options to a ".ini"-like file or memory-stored string list.
66  * \sa loadFromConfigFile, saveToConfigFileName
67  */
68  virtual void saveToConfigFile(
70  const std::string &section) const;
71 
72  /** Behaves like saveToConfigFile, but you can pass directly a file name and a temporary CConfigFile object will be created automatically to save the file.
73  * \sa saveToConfigFile, loadFromConfigFileName
74  */
75  void saveToConfigFileName(
76  const std::string &config_file,
77  const std::string &section) const;
78 
79  /** Just like \a dumpToTextStream() but sending the text to the console (std::cout) */
80  void dumpToConsole() const;
81 
82  /** This method should clearly display all the contents of the structure in textual form, sending it to a CStream.
83  * The default implementation in this base class relies on \a saveToConfigFile() to generate a plain text representation of all the parameters.
84  */
85  virtual void dumpToTextStream(mrpt::utils::CStream &out) const;
86 
87  /** Virtual destructor */
88  virtual ~CLoadableOptions() { }
89 
90  }; // End of class def.
91 
92  /** Macro for dumping a variable to a stream, within the method "dumpToTextStream(out)" (Variable types are: int, double, float, bool, string */
93  #define LOADABLEOPTS_DUMP_VAR(variableName,variableType) { dumpVar_##variableType(out, #variableName,static_cast<variableType>(variableName)); }
94 
95  /** Macro for dumping a variable to a stream, transforming the argument from radians to degrees. */
96  #define LOADABLEOPTS_DUMP_VAR_DEG(variableName) { dumpVar_double(out, #variableName,RAD2DEG(static_cast<double>(variableName))); }
97 
98  } // End of namespace
99 } // end of namespace
100 #endif
This class allows loading and storing values and vectors of different types from a configuration text...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
GLsizei const GLchar ** string
Definition: glext.h:3919
const GLdouble * v
Definition: glext.h:3603
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLsizei GLsizei GLchar * source
Definition: glext.h:3908
This is a virtual base class for sets of options than can be loaded from and/or saved to configuratio...
virtual ~CLoadableOptions()
Virtual destructor.



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019