MRPT  1.9.9
CLoadableOptions.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "config-precomp.h" // Precompiled headers
11 
15 #include <mrpt/core/format.h>
16 #include <iostream>
17 
18 using namespace mrpt::config;
19 
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  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 
46  std::ostream& out, const char* varName, int v)
47 {
48  out << mrpt::format("%-*s= %i\n", LOADABLEOPTS_COLUMN_WIDTH, varName, v);
49 }
50 
52  std::ostream& out, const char* varName, float v)
53 {
54  out << mrpt::format("%-*s= %f\n", LOADABLEOPTS_COLUMN_WIDTH, varName, v);
55 }
56 
58  std::ostream& out, const char* varName, double v)
59 {
60  out << mrpt::format("%-*s= %f\n", LOADABLEOPTS_COLUMN_WIDTH, varName, v);
61 }
62 
64  std::ostream& out, const char* varName, bool v)
65 {
66  out << mrpt::format(
67  "%-*s= %s\n", LOADABLEOPTS_COLUMN_WIDTH, varName, v ? "YES" : "NO");
68 }
69 
71  std::ostream& out, const char* varName, const std::string& v)
72 {
73  out << mrpt::format(
74  "%-*s= %s\n", LOADABLEOPTS_COLUMN_WIDTH, varName, v.c_str());
75 }
76 
77 void CLoadableOptions::dumpToTextStream(std::ostream& out) const
78 {
80  this->saveToConfigFile(cfg, "");
81  out << cfg.getContent();
82 }
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.
This class implements a config file-like interface over a memory-stored string list.
static void dumpVar_double(std::ostream &out, const char *varName, double v)
This class allows loading and storing values and vectors of different types from ".ini" files easily.
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. ...
This class allows loading and storing values and vectors of different types from a configuration text...
static void dumpVar_bool(std::ostream &out, const char *varName, bool v)
static void dumpVar_string(std::ostream &out, const char *varName, const std::string &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...
virtual void dumpToTextStream(std::ostream &out) const
This method should clearly display all the contents of the structure in textual form, sending it to a std::ostream.
GLsizei const GLchar ** string
Definition: glext.h:4116
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...
const GLdouble * v
Definition: glext.h:3684
static void dumpVar_float(std::ostream &out, const char *varName, float v)
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.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
void getContent(std::string &str) const
Return the current contents of the virtual "config file".
void dumpToConsole() const
Just like dumpToTextStream() but sending the text to the console (std::cout)
const int LOADABLEOPTS_COLUMN_WIDTH
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019