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-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 }
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)
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26
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.
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...
static void dumpVar_float(std::ostream &out, const char *varName, float v)
mrpt::vision::TStereoCalibResults out
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.
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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: b2c5333a7 Sat Mar 28 09:52:26 2020 +0100 at sáb mar 28 10:00:10 CET 2020