Go to the documentation of this file.
13 #include <type_traits>
23 template <
typename ENUMTYPE>
29 class CConfigFilePrefixer;
59 const std::string& str,
const int name_padding_width,
60 const int value_padding_width,
const std::string& comment);
67 const std::string& defaultStr,
bool failIfNotFound =
false)
const = 0;
74 virtual void getAllSections(std::vector<std::string>& sections)
const = 0;
78 const std::string& section, std::vector<std::string>& keys)
const = 0;
83 template <
typename enum_t,
87 const int name_padding_width = -1,
const int value_padding_width = -1,
92 name_padding_width, value_padding_width, comment);
99 template <
typename data_t,
103 const data_t&
value,
const int name_padding_width = -1,
104 const int value_padding_width = -1,
109 value_padding_width, comment);
111 template <
typename data_t>
114 const std::vector<data_t>&
value,
const int name_padding_width = -1,
115 const int value_padding_width = -1,
120 it !=
value.end(); ++it)
126 section,
name,
s, name_padding_width, value_padding_width, comment);
130 const int name_padding_width = -1,
const int value_padding_width = -1,
134 const int name_padding_width = -1,
const int value_padding_width = -1,
144 double defaultValue,
bool failIfNotFound =
false)
const;
147 bool failIfNotFound =
false)
const;
150 bool failIfNotFound =
false)
const;
153 bool failIfNotFound =
false)
const;
156 uint64_t defaultValue,
bool failIfNotFound =
false)
const;
159 const std::string& defaultValue,
bool failIfNotFound =
false)
const;
165 const std::string& defaultValue,
bool failIfNotFound =
false)
const;
170 template <
class VECTOR_TYPE>
173 const VECTOR_TYPE& defaultValue, VECTOR_TYPE& outValues,
174 bool failIfNotFound =
false)
const
178 std::vector<std::string> tokens;
181 if (tokens.size() == 0)
183 outValues = defaultValue;
188 const size_t N = tokens.size();
190 for (
size_t i = 0; i < N; i++)
192 double val = std::stod(tokens[i]);
205 template <
class MATRIX_TYPE>
208 MATRIX_TYPE& outMatrix,
209 const MATRIX_TYPE& defaultMatrix = MATRIX_TYPE(),
210 bool failIfNotFound =
false)
const
214 outMatrix = defaultMatrix;
218 if (!outMatrix.fromMatlabStringFormat(aux))
244 template <
typename ENUMTYPE>
247 const ENUMTYPE& defaultValue,
bool failIfNotFound =
false)
const
252 if (sVal.empty())
return defaultValue;
254 if (::isdigit(sVal[0]))
256 return static_cast<ENUMTYPE
>(::atoi(&sVal[0]));
264 catch (std::exception&)
267 "Invalid value '%s' for enum type while reading key='%s'.",
268 sVal.c_str(),
name.c_str())
282 #define MRPT_LOAD_CONFIG_VAR( \
283 variableName, variableType, configFileObject, sectionNameStr) \
285 variableName = configFileObject.read_##variableType( \
286 sectionNameStr, #variableName, variableName); \
291 #define MRPT_LOAD_CONFIG_VAR_CS(variableName, variableType) \
292 MRPT_LOAD_CONFIG_VAR(variableName, variableType, c, s)
296 #define MRPT_LOAD_CONFIG_VAR_DEGREES( \
297 variableName, configFileObject, sectionNameStr) \
299 variableName = mrpt::DEG2RAD( \
300 configFileObject.read_double( \
301 sectionNameStr, #variableName, mrpt::RAD2DEG(variableName))); \
306 #define MRPT_LOAD_CONFIG_VAR_DEGREES_NO_DEFAULT( \
307 variableName, configFileObject, sectionNameStr) \
309 variableName = mrpt::DEG2RAD( \
310 configFileObject.read_double( \
311 sectionNameStr, #variableName, mrpt::RAD2DEG(variableName), \
315 #define MRPT_LOAD_CONFIG_VAR_CAST( \
316 variableName, variableType, variableTypeCast, configFileObject, \
319 variableName = static_cast<variableTypeCast>( \
320 configFileObject.read_##variableType( \
321 sectionNameStr, #variableName, variableName)); \
324 #define MRPT_LOAD_HERE_CONFIG_VAR( \
325 variableName, variableType, targetVariable, configFileObject, \
327 targetVariable = configFileObject.read_##variableType( \
328 sectionNameStr, #variableName, targetVariable, false);
330 #define MRPT_LOAD_HERE_CONFIG_VAR_NO_DEFAULT( \
331 variableName, variableType, targetVariable, configFileObject, \
336 targetVariable = configFileObject.read_##variableType( \
337 sectionNameStr, #variableName, targetVariable, true); \
339 catch (std::exception&) \
343 "Value for '%s' not found in config file in section '%s'", \
344 static_cast<const char*>(#variableName), \
345 std::string(sectionNameStr).c_str())); \
349 #define MRPT_LOAD_HERE_CONFIG_VAR_DEGREES( \
350 variableName, variableType, targetVariable, configFileObject, \
352 targetVariable = mrpt::DEG2RAD( \
353 configFileObject.read_##variableType( \
354 sectionNameStr, #variableName, mrpt::RAD2DEG(targetVariable), \
357 #define MRPT_LOAD_HERE_CONFIG_VAR_DEGREES_NO_DEFAULT( \
358 variableName, variableType, targetVariable, configFileObject, \
363 targetVariable = mrpt::DEG2RAD( \
364 configFileObject.read_##variableType( \
365 sectionNameStr, #variableName, targetVariable, true)); \
367 catch (std::exception&) \
371 "Value for '%s' not found in config file in section '%s'", \
372 static_cast<const char*>(#variableName), \
373 std::string(sectionNameStr).c_str())); \
377 #define MRPT_LOAD_CONFIG_VAR_NO_DEFAULT( \
378 variableName, variableType, configFileObject, sectionNameStr) \
382 variableName = configFileObject.read_##variableType( \
383 sectionNameStr, #variableName, variableName, true); \
385 catch (std::exception&) \
389 "Value for '%s' not found in config file in section '%s'", \
390 static_cast<const char*>(#variableName), \
391 std::string(sectionNameStr).c_str())); \
397 #define MRPT_LOAD_CONFIG_VAR_REQUIRED_CS(variableName, variableType) \
398 MRPT_LOAD_CONFIG_VAR_NO_DEFAULT(variableName, variableType, c, s)
400 #define MRPT_LOAD_CONFIG_VAR_CAST_NO_DEFAULT( \
401 variableName, variableType, variableTypeCast, configFileObject, \
406 variableName = static_cast<variableTypeCast>( \
407 configFileObject.read_##variableType( \
408 sectionNameStr, #variableName, variableName, true)); \
410 catch (std::exception&) \
414 "Value for '%s' not found in config file in section '%s'", \
415 static_cast<const char*>(#variableName), \
416 std::string(sectionNameStr).c_str())); \
420 #define MRPT_LOAD_HERE_CONFIG_VAR_CAST( \
421 variableName, variableType, variableTypeCast, targetVariable, \
422 configFileObject, sectionNameStr) \
423 targetVariable = static_cast<variableTypeCast>( \
424 configFileObject.read_##variableType( \
425 sectionNameStr, #variableName, targetVariable));
427 #define MRPT_LOAD_HERE_CONFIG_VAR_CAST_NO_DEFAULT( \
428 variableName, variableType, variableTypeCast, targetVariable, \
429 configFileObject, sectionNameStr) \
433 targetVariable = static_cast<variableTypeCast>( \
434 configFileObject.read_##variableType( \
435 sectionNameStr, #variableName, targetVariable, true)); \
437 catch (std::exception&) \
441 "Value for '%s' not found in config file in section '%s'", \
442 static_cast<const char*>(#variableName), \
443 std::string(sectionNameStr).c_str())); \
447 #define MRPT_SAVE_CONFIG_VAR(variableName, configFileObject, sectionNameStr) \
449 configFileObject.write(sectionNameStr, #variableName, variableName); \
452 #define MRPT_SAVE_CONFIG_VAR_DEGREES( \
453 variableName, configFileObject, sectionNameStr) \
455 configFileObject.write( \
456 sectionNameStr, #variableName, mrpt::RAD2DEG(variableName)); \
459 #define MRPT_SAVE_CONFIG_VAR_COMMENT(variableName, __comment) \
462 s, #variableName, variableName, \
463 mrpt::config::MRPT_SAVE_NAME_PADDING(), \
464 mrpt::config::MRPT_SAVE_VALUE_PADDING(), __comment); \
466 #define MRPT_SAVE_CONFIG_VAR_DEGREES_COMMENT( \
467 __entryName, __variable, __comment) \
470 s, __entryName, mrpt::RAD2DEG(__variable), \
471 mrpt::config::MRPT_SAVE_NAME_PADDING(), \
472 mrpt::config::MRPT_SAVE_VALUE_PADDING(), __comment); \
const Scalar * const_iterator
void write(const std::string §ion, const std::string &name, enum_t value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
void read_matrix(const std::string §ion, const std::string &name, MATRIX_TYPE &outMatrix, const MATRIX_TYPE &defaultMatrix=MATRIX_TYPE(), bool failIfNotFound=false) const
Reads a configuration parameter as a matrix written in a matlab-like format - for example: "[2 3 4 ; ...
virtual std::string readString(const std::string §ion, const std::string &name, const std::string &defaultStr, bool failIfNotFound=false) const =0
A virtual method to read a generic string.
double read_double(const std::string §ion, const std::string &name, double defaultValue, bool failIfNotFound=false) const
std::string std::string to_string(T v)
Just like std::to_string(), but with an overloaded version for std::string arguments.
void write(const std::string §ion, const std::string &name, const data_t &value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void tokenize(const std::string &inString, const std::string &inDelimiters, OUT_CONTAINER &outTokens, bool skipBlankTokens=true) noexcept
Tokenizes a string according to a set of delimiting characters.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
GLuint const GLchar * name
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
virtual void writeString(const std::string §ion, const std::string &name, const std::string &str)=0
A virtual method to write a generic string.
This class allows loading and storing values and vectors of different types from a configuration text...
A wrapper for other CConfigFileBase-based objects that prefixes a given token to every key and/or sec...
unsigned __int64 uint64_t
virtual void getAllSections(std::vector< std::string > §ions) const =0
Returns a list with all the section names.
uint64_t read_uint64_t(const std::string §ion, const std::string &name, uint64_t defaultValue, bool failIfNotFound=false) const
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
ENUMTYPE read_enum(const std::string §ion, const std::string &name, const ENUMTYPE &defaultValue, bool failIfNotFound=false) const
Reads an "enum" value, where the value in the config file can be either a numerical value or the symb...
int MRPT_SAVE_VALUE_PADDING()
GLsizei const GLfloat * value
bool sectionExists(const std::string §ion_name) const
Checks if a given section exists (name is case insensitive)
virtual void getAllKeys(const std::string §ion, std::vector< std::string > &keys) const =0
Returs a list with all the keys into a section.
GLsizei const GLchar ** string
void write(const std::string §ion, const std::string &name, const std::vector< data_t > &value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
void read_vector(const std::string §ion, const std::string &name, const VECTOR_TYPE &defaultValue, VECTOR_TYPE &outValues, bool failIfNotFound=false) const
Reads a configuration parameter of type vector, stored in the file as a string: "[v1 v2 v3 ....
int MRPT_SAVE_NAME_PADDING()
Default padding sizes for macros MRPT_SAVE_CONFIG_VAR_COMMENT(), etc.
std::string read_string_first_word(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
Reads a configuration parameter of type "string", and keeps only the first word (this can be used to ...
virtual ~CConfigFileBase()
dtor
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 | |