Main MRPT website > C++ reference for MRPT 1.9.9
CLoadableOptions.cpp
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 
10 #include "base-precomp.h" // Precompiled headers
11 
14 #include <mrpt/utils/CConfigFile.h>
16 
17 using namespace mrpt::utils;
18 
20 const int LOADABLEOPTS_COLUMN_WIDTH = 41; // Until the "=" in each row.
21 
23  const std::string& config_file, const std::string& section)
24 {
25  CConfigFile f(config_file);
26  this->loadFromConfigFile(f, section);
27 }
28 
30  mrpt::utils::CConfigFileBase& target, const std::string& section) const
31 {
32  MRPT_UNUSED_PARAM(target);
33  MRPT_UNUSED_PARAM(section);
34  throw std::logic_error("The child class does not implement this method.");
35 }
36 
38  const std::string& config_file, const std::string& section) const
39 {
40  CConfigFile f(config_file);
41  this->saveToConfigFile(f, section);
42 }
43 
45 {
47 }
48 
49 void CLoadableOptions::dumpVar_int(CStream& out, const char* varName, int v)
50 {
51  out.printf("%-*s= %i\n", LOADABLEOPTS_COLUMN_WIDTH, varName, v);
52 }
53 
54 void CLoadableOptions::dumpVar_float(CStream& out, const char* varName, float v)
55 {
56  out.printf("%-*s= %f\n", LOADABLEOPTS_COLUMN_WIDTH, varName, v);
57 }
58 
60  CStream& out, const char* varName, double v)
61 {
62  out.printf("%-*s= %f\n", LOADABLEOPTS_COLUMN_WIDTH, varName, v);
63 }
64 
65 void CLoadableOptions::dumpVar_bool(CStream& out, const char* varName, bool v)
66 {
67  out.printf(
68  "%-*s= %s\n", LOADABLEOPTS_COLUMN_WIDTH, varName, v ? "YES" : "NO");
69 }
70 
72  CStream& out, const char* varName, const std::string& v)
73 {
74  out.printf("%-*s= %s\n", LOADABLEOPTS_COLUMN_WIDTH, varName, v.c_str());
75 }
76 
77 /** This method should clearly display all the contents of the structure in
78  * textual form, sending it to a CStream.
79  * The default implementation in this base class relies on \a
80  * saveToConfigFile() to generate a plain text representation of all the
81  * parameters.
82  */
84 {
86  this->saveToConfigFile(cfg, "");
87  out.printf("%s", cfg.getContent().c_str());
88 }
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
This class allows loading and storing values and vectors of different types from ".ini" files easily.
Definition: CConfigFile.h:35
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 CStdOutStream derived class allow printing to standard out, normally the console text output...
Definition: CStdOutStream.h:26
CStdOutStream loadable_opts_my_cout
This class allows loading and storing values and vectors of different types from a configuration text...
This class implements a config file-like interface over a memory-stored string list.
void getContent(std::string &str) const
Return the current contents of the virtual "config file".
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...
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
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
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.
void dumpToConsole() const
Just like dumpToTextStream() but sending the text to the console (std::cout)
const int LOADABLEOPTS_COLUMN_WIDTH
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.
Definition: CStream.cpp:597
static void dumpVar_double(CStream &out, const char *varName, double v)



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