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



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