Main MRPT website > C++ reference for MRPT 1.5.6
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 
12 
15 #include <mrpt/utils/CConfigFile.h>
17 
18 using namespace mrpt::utils;
19 
21 const int LOADABLEOPTS_COLUMN_WIDTH = 41; // Until the "=" in each row.
22 
24  const std::string &config_file,
25  const std::string &section)
26 {
27  CConfigFile f(config_file);
28  this->loadFromConfigFile(f,section);
29 }
30 
33  const std::string &section) const
34 {
35  MRPT_UNUSED_PARAM(target); MRPT_UNUSED_PARAM(section);
36  throw std::logic_error("The child class does not implement this method.");
37 }
38 
40  const std::string &config_file,
41  const std::string &section) const
42 {
43  CConfigFile f(config_file);
44  this->saveToConfigFile(f,section);
45 }
46 
48 {
50 }
51 
52 void CLoadableOptions::dumpVar_int( CStream &out, const char *varName, int v )
53 {
54  out.printf("%-*s= %i\n",LOADABLEOPTS_COLUMN_WIDTH, varName, v);
55 }
56 
57 void CLoadableOptions::dumpVar_float( CStream &out, const char *varName, float v )
58 {
59  out.printf("%-*s= %f\n",LOADABLEOPTS_COLUMN_WIDTH, varName, v);
60 }
61 
62 void CLoadableOptions::dumpVar_double( CStream &out, const char *varName, double v )
63 {
64  out.printf("%-*s= %f\n",LOADABLEOPTS_COLUMN_WIDTH, varName, v);
65 }
66 
67 void CLoadableOptions::dumpVar_bool( CStream &out, const char *varName, bool v )
68 {
69  out.printf("%-*s= %s\n",LOADABLEOPTS_COLUMN_WIDTH, varName, v ? "YES":"NO" );
70 }
71 
72 void CLoadableOptions::dumpVar_string( 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 textual form, sending it to a CStream.
78  * The default implementation in this base class relies on \a saveToConfigFile() to generate a plain text representation of all the parameters.
79  */
81 {
83  this->saveToConfigFile(cfg,"");
84  out.printf("%s", cfg.getContent().c_str() );
85 }
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
This class allows loading and storing values and vectors of different types from ".ini" files easily.
Definition: CConfigFile.h:30
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:38
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:3919
const GLdouble * v
Definition: glext.h:3603
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:507
static void dumpVar_double(CStream &out, const char *varName, double v)



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