MRPT  2.0.3
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-2020, 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  [[maybe_unused]] CConfigFileBase& target,
31  [[maybe_unused]] const std::string& section) const
32 {
33  throw std::logic_error("The child class does not implement this method.");
34 }
35 
37  const std::string& config_file, const std::string& section) const
38 {
39  CConfigFile f(config_file);
40  this->saveToConfigFile(f, section);
41 }
42 
45  std::ostream& out, const char* varName, int v)
46 {
47  out << mrpt::format("%-*s= %i\n", LOADABLEOPTS_COLUMN_WIDTH, varName, v);
48 }
49 
51  std::ostream& out, const char* varName, float v)
52 {
53  out << mrpt::format("%-*s= %f\n", LOADABLEOPTS_COLUMN_WIDTH, varName, v);
54 }
55 
57  std::ostream& out, const char* varName, double v)
58 {
59  out << mrpt::format("%-*s= %f\n", LOADABLEOPTS_COLUMN_WIDTH, varName, v);
60 }
61 
63  std::ostream& out, const char* varName, bool v)
64 {
65  out << mrpt::format(
66  "%-*s= %s\n", LOADABLEOPTS_COLUMN_WIDTH, varName, v ? "YES" : "NO");
67 }
68 
70  std::ostream& out, const char* varName, const std::string& v)
71 {
72  out << mrpt::format(
73  "%-*s= %s\n", LOADABLEOPTS_COLUMN_WIDTH, varName, v.c_str());
74 }
75 
76 void CLoadableOptions::dumpToTextStream(std::ostream& out) const
77 {
79  this->saveToConfigFile(cfg, "");
80  out << cfg.getContent();
81 }
mrpt::config
Definition: config/CConfigFile.h:14
mrpt::config::CLoadableOptions::dumpToConsole
void dumpToConsole() const
Just like dumpToTextStream() but sending the text to the console (std::cout)
Definition: CLoadableOptions.cpp:43
mrpt::config::CLoadableOptions::dumpVar_double
static void dumpVar_double(std::ostream &out, const char *varName, double v)
Definition: CLoadableOptions.cpp:56
CConfigFileMemory.h
format.h
CConfigFile.h
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
out
mrpt::vision::TStereoCalibResults out
Definition: chessboard_stereo_camera_calib_unittest.cpp:25
config-precomp.h
mrpt::config::CLoadableOptions::dumpVar_float
static void dumpVar_float(std::ostream &out, const char *varName, float v)
Definition: CLoadableOptions.cpp:50
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:62
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:44
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
LOADABLEOPTS_COLUMN_WIDTH
const int LOADABLEOPTS_COLUMN_WIDTH
Definition: CLoadableOptions.cpp:20
mrpt::config::CConfigFileMemory::getContent
void getContent(std::string &str) const
Return the current contents of the virtual "config file".
Definition: CConfigFileMemory.cpp:65
CLoadableOptions.h
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:36
mrpt::config::CConfigFile
This class allows loading and storing values and vectors of different types from "....
Definition: config/CConfigFile.h:31
mrpt::config::CLoadableOptions::dumpVar_string
static void dumpVar_string(std::ostream &out, const char *varName, const std::string &v)
Definition: CLoadableOptions.cpp:69
mrpt::config::CConfigFileMemory
This class implements a config file-like interface over a memory-stored string list.
Definition: config/CConfigFileMemory.h:36
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:76
mrpt::format
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26



Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Thu May 21 21:53:32 UTC 2020