10#ifndef mrpt_utils_parameters_H
11#define mrpt_utils_parameters_H
48 typedef std::map<std::string,T>
BASE;
59 BASE::operator[](std::string(nam1)) = val;
63 nam = va_arg(args,
const char*);
66 BASE::operator[](std::string(nam)) = val;
71 inline bool has(
const std::string &s)
const {
return std::map<std::string,T>::end()!=BASE::find(s); }
76 typename BASE::const_iterator it =BASE::find(s);
78 throw std::logic_error(std::string(
"Parameter '")+s+std::string(
"' is not present.").c_str());
84 typename BASE::const_iterator it =BASE::find(s);
87 else return it->second;
90 inline T &
operator[](
const std::string &s) {
return BASE::operator[](s); }
100 size_t maxStrLen = 10;
101 for (
typename BASE::const_iterator it=BASE::begin();it!=BASE::end();++it) maxStrLen = std::max(maxStrLen, it->first.size() );
103 std::stringstream str;
104 for (
typename BASE::const_iterator it=BASE::begin();it!=BASE::end();++it)
105 str << it->first << std::string(maxStrLen-it->first.size(),
' ') <<
" = " << it->second << std::endl;
TParameters< std::string > TParametersString
See the generic template mrpt::utils::TParameters.
TParameters< double > TParametersDouble
See the generic template mrpt::utils::TParameters.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
For usage when passing a dynamic number of (numeric) arguments to a function, by name.
void getAsString(std::string &s) const
Returns a multi-like string representation of the parameters like : 'nam = val\nnam2 = val2....
T & operator[](const std::string &s)
The write (non-const) version of the [] operator.
TParameters(const char *nam1,...)
Constructor with a list of initial values (see the description and use example in mrpt::utils::TParam...
void dumpToConsole() const
Dumps to console the output from getAsString()
T operator[](const std::string &s) const
A const version of the [] operator, for usage as read-only.
std::string getAsString() const
Returns a multi-like string representation of the parameters like : 'nam = val\nnam2 = val2....
TParameters()
Default constructor (initializes empty)
T getWithDefaultVal(const std::string &s, const T &defaultVal) const
A const version of the [] operator and with a default value in case the parameter is not set (for usa...
std::map< std::string, T > BASE
bool has(const std::string &s) const