Main MRPT website > C++ reference for MRPT 1.9.9
config/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-2018, 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 #pragma once
10 
11 #include <string>
12 #include <stdexcept>
13 #include <iosfwd>
14 
15 namespace mrpt
16 {
17 namespace config
18 {
19 // Frwd. decls:
20 class CConfigFileBase;
21 
22 /** This is a virtual base class for sets of options than can be loaded from
23  * and/or saved to configuration plain-text files.
24  * \todo Automatize this class thru a proxy auxiliary class where variables are
25  * registered from pointers, etc...
26  * \ingroup mrpt_base_grp
27  */
29 {
30  protected:
31  /** Used to print variable info from dumpToTextStream with the macro
32  * LOADABLEOPTS_DUMP_VAR */
33  static void dumpVar_int(std::ostream& out, const char* varName, int v);
34  static void dumpVar_float(std::ostream& out, const char* varName, float v);
35  static void dumpVar_double(
36  std::ostream& out, const char* varName, double v);
37  static void dumpVar_bool(std::ostream& out, const char* varName, bool v);
38  static void dumpVar_string(
39  std::ostream& out, const char* varName, const std::string& v);
40 
41  public:
42  /** This method load the options from a ".ini"-like file or memory-stored
43  * string list.
44  * Only those parameters found in the given "section" and having
45  * the same name that the variable are loaded. Those not found in
46  * the file will stay with their previous values (usually the default
47  * values loaded at initialization). An example of an ".ini" file:
48  * \code
49  * [section]
50  * resolution = 0.10 // blah blah...
51  * modeSelection = 1 // 0=blah, 1=blah,...
52  * \endcode
53  *
54  * \sa loadFromConfigFileName, saveToConfigFile
55  */
56  virtual void loadFromConfigFile(
58  const std::string& section) = 0;
59 
60  /** Behaves like loadFromConfigFile, but you can pass directly a file name
61  * and a temporary CConfigFile object will be created automatically to load
62  * the file.
63  * \sa loadFromConfigFile
64  */
66  const std::string& config_file, const std::string& section);
67 
68  /** This method saves the options to a ".ini"-like file or memory-stored
69  * string list.
70  * \sa loadFromConfigFile, saveToConfigFileName
71  */
72  virtual void saveToConfigFile(
74  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 std::ostream.
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(std::ostream& 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 NS config
118 } // end NS mrpt
mrpt::config::CLoadableOptions::dumpToConsole
void dumpToConsole() const
Just like dumpToTextStream() but sending the text to the console (std::cout)
Definition: CLoadableOptions.cpp:44
mrpt::config::CLoadableOptions::dumpVar_double
static void dumpVar_double(std::ostream &out, const char *varName, double v)
Definition: CLoadableOptions.cpp:57
mrpt::config::CLoadableOptions::loadFromConfigFileName
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...
Definition: CLoadableOptions.cpp:22
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
source
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
mrpt::config::CLoadableOptions::dumpVar_float
static void dumpVar_float(std::ostream &out, const char *varName, float v)
Definition: CLoadableOptions.cpp:51
v
const GLdouble * v
Definition: glext.h:3678
mrpt::config::CLoadableOptions::loadFromConfigFile
virtual void loadFromConfigFile(const mrpt::config::CConfigFileBase &source, const std::string &section)=0
This method load the options from a ".ini"-like file or memory-stored string list.
mrpt::config::CLoadableOptions::dumpVar_bool
static void dumpVar_bool(std::ostream &out, const char *varName, bool v)
Definition: CLoadableOptions.cpp:63
mrpt::config::CLoadableOptions::dumpVar_int
static void dumpVar_int(std::ostream &out, const char *varName, int v)
Used to print variable info from dumpToTextStream with the macro LOADABLEOPTS_DUMP_VAR.
Definition: CLoadableOptions.cpp:45
mrpt::config::CConfigFileBase
This class allows loading and storing values and vectors of different types from a configuration text...
Definition: config/CConfigFileBase.h:44
mrpt::config::CLoadableOptions::saveToConfigFile
virtual void saveToConfigFile(mrpt::config::CConfigFileBase &target, const std::string &section) const
This method saves the options to a ".ini"-like file or memory-stored string list.
Definition: CLoadableOptions.cpp:29
mrpt::config::CLoadableOptions
This is a virtual base class for sets of options than can be loaded from and/or saved to configuratio...
Definition: config/CLoadableOptions.h:28
mrpt::utils::CConfigFileBase
mrpt::config::CConfigFileBase CConfigFileBase
Definition: utils/CConfigFileBase.h:7
mrpt::config::CLoadableOptions::saveToConfigFileName
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...
Definition: CLoadableOptions.cpp:37
mrpt::config::CLoadableOptions::dumpVar_string
static void dumpVar_string(std::ostream &out, const char *varName, const std::string &v)
Definition: CLoadableOptions.cpp:70
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::config::CLoadableOptions::~CLoadableOptions
virtual ~CLoadableOptions()
Virtual destructor.
Definition: config/CLoadableOptions.h:97
mrpt::config::CLoadableOptions::dumpToTextStream
virtual void dumpToTextStream(std::ostream &out) const
This method should clearly display all the contents of the structure in textual form,...
Definition: CLoadableOptions.cpp:77



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST