Main MRPT website > C++ reference for MRPT 1.3.2
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-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 CLoadableOptions_H
10 #define CLoadableOptions_H
11 
12 #include <mrpt/utils/core_defs.h>
13 #include <string>
14 #include <stdexcept>
15 
16 /*---------------------------------------------------------------
17  Class
18  ---------------------------------------------------------------*/
19 namespace mrpt
20 {
21 namespace utils
22 {
23  // Frwd. decls:
24  class CConfigFileBase;
25  class CStream;
26 
27  /** This is a virtual base class for sets of options than can be loaded from and/or saved to configuration plain-text files.
28  * \todo Automatize this class thru a proxy auxiliary class where variables are registered from pointers, etc...
29  * \ingroup mrpt_base_grp
30  */
32  {
33  protected:
34 
35  /** Used to print variable info from dumpToTextStream with the macro LOADABLEOPTS_DUMP_VAR */
36  static void dumpVar_int( CStream &out, const char *varName, int v );
37  static void dumpVar_float( CStream &out, const char *varName, float v );
38  static void dumpVar_double( CStream &out, const char *varName, double v );
39  static void dumpVar_bool( CStream &out, const char *varName, bool v );
40  static void dumpVar_string( CStream &out, const char *varName, const std::string &v );
41 
42 
43  public:
44  /** This method load the options from a ".ini"-like file or memory-stored 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(
58  const mrpt::utils::CConfigFileBase & source,
59  const std::string & section) = 0;
60 
61  /** Behaves like loadFromConfigFile, but you can pass directly a file name and a temporary CConfigFile object will be created automatically to load the file.
62  * \sa loadFromConfigFile
63  */
64  void loadFromConfigFileName(
65  const std::string & config_file,
66  const std::string & section);
67 
68  /** This method saves the options to a ".ini"-like file or memory-stored string list.
69  * \sa loadFromConfigFile, saveToConfigFileName
70  */
71  virtual void saveToConfigFile(
73  const std::string &section) const;
74 
75  /** Behaves like saveToConfigFile, but you can pass directly a file name and a temporary CConfigFile object will be created automatically to save the file.
76  * \sa saveToConfigFile, loadFromConfigFileName
77  */
78  void saveToConfigFileName(
79  const std::string &config_file,
80  const std::string &section) const;
81 
82  /** Just like \a dumpToTextStream() but sending the text to the console (std::cout) */
83  void dumpToConsole() const;
84 
85  /** This method should clearly display all the contents of the structure in textual form, sending it to a CStream.
86  * The default implementation in this base class relies on \a saveToConfigFile() to generate a plain text representation of all the parameters.
87  */
88  virtual void dumpToTextStream(mrpt::utils::CStream &out) const;
89 
90  /** Virtual destructor
91  */
93  {
94  }
95 
96  }; // End of class def.
97 
98  /** Macro for dumping a variable to a stream, within the method "dumpToTextStream(out)" (Variable types are: int, double, float, bool, string */
99  #define LOADABLEOPTS_DUMP_VAR(variableName,variableType) { dumpVar_##variableType(out, #variableName,static_cast<variableType>(variableName)); }
100 
101  /** Macro for dumping a variable to a stream, transforming the argument from radians to degrees. */
102  #define LOADABLEOPTS_DUMP_VAR_DEG(variableName) { dumpVar_double(out, #variableName,RAD2DEG(static_cast<double>(variableName))); }
103 
104  } // End of namespace
105 } // end of namespace
106 #endif
class BASE_IMPEXP CStream
Definition: math_frwds.h:26
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
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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.11 for MRPT 1.3.2 SVN: at Mon May 9 06:50:38 UTC 2016