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-2018, 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 "config-precomp.h" // Precompiled headers
11 
15 #include <iostream>
16 #include <mrpt/core/format.h>
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 }
mrpt::config
Definition: config/CConfigFile.h:16
mrpt::config::CLoadableOptions::dumpToConsole
void dumpToConsole() const
Just like dumpToTextStream() but sending the text to the console (std::cout)
Definition: CLoadableOptions.cpp:44
mrpt::config::CLoadableOptions::dumpVar_double
static void dumpVar_double(std::ostream &out, const char *varName, double v)
Definition: CLoadableOptions.cpp:57
CConfigFileMemory.h
format.h
CConfigFile.h
MRPT_UNUSED_PARAM
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186
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
config-precomp.h
mrpt::config::CLoadableOptions::dumpVar_float
static void dumpVar_float(std::ostream &out, const char *varName, float v)
Definition: CLoadableOptions.cpp:51
v
const GLdouble * v
Definition: glext.h:3678
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:63
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:45
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::format
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
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:66
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:37
mrpt::config::CConfigFile
This class allows loading and storing values and vectors of different types from "....
Definition: config/CConfigFile.h:33
mrpt::config::CLoadableOptions::dumpVar_string
static void dumpVar_string(std::ostream &out, const char *varName, const std::string &v)
Definition: CLoadableOptions.cpp:70
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::config::CConfigFileMemory
This class implements a config file-like interface over a memory-stored string list.
Definition: config/CConfigFileMemory.h:30
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:77



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST