For usage when passing a dynamic number of (numeric) arguments to a function, by name.
TParameters<double> p; // or TParametersDouble p["v_max"] = 1.0; // Write ... cout << p["w_max"]; // Read, even if "p" was const.
A default list of parameters can be passed to the constructor as a sequence of pairs "name, value", which MUST end in a NULL name string. Names MUST BE "const char*" (that is, "old plain strings" are OK), not std::string objects!. See this example:
TParameters<double> p("par1",2.0, "par2",-4.5, "par3",9.0, NULL); // MUST end with a NULL
VERY IMPORTANT: If you use the NULL-ended constructor above, make sure all the values are of the proper type or it will crash in runtime. For example, in a TParametersDouble all values must be double's, so if you type "10" the compiler will make it an "int". Instead, write "10.0".
Definition at line 253 of file base/include/mrpt/utils/types.h.
#include <mrpt/utils/types.h>

Public Types | |
| typedef std::map< std::string, T > | BASE |
Public Member Functions | |
| TParameters () | |
| Default constructor (initializes empty) | |
| TParameters (const char *nam1,...) | |
| Constructor with a list of initial values (see the description and use example in mrpt::utils::TParameters) | |
| bool | has (const std::string &s) const |
| T | operator[] (const std::string &s) const |
| A const version of the [] operator, for usage as read-only. | |
| 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 usage as read-only). | |
| T & | operator[] (const std::string &s) |
| The write (non-const) version of the [] operator. | |
| void | dumpToConsole () const |
| Dumps to console the output from getAsString() | |
| std::string | getAsString () const |
| Returns a multi-like string representation of the parameters like : 'nam = val = val2...'. | |
| void | getAsString (std::string &s) const |
| Returns a multi-like string representation of the parameters like : 'nam = val = val2...'. | |
| typedef std::map<std::string,T> mrpt::utils::TParameters< T >::BASE |
Definition at line 255 of file base/include/mrpt/utils/types.h.
| mrpt::utils::TParameters< T >::TParameters | ( | ) | [inline] |
Default constructor (initializes empty)
Definition at line 257 of file base/include/mrpt/utils/types.h.
| mrpt::utils::TParameters< T >::TParameters | ( | const char * | nam1, |
| ... | |||
| ) | [inline] |
Constructor with a list of initial values (see the description and use example in mrpt::utils::TParameters)
Definition at line 259 of file base/include/mrpt/utils/types.h.
| void mrpt::utils::TParameters< T >::dumpToConsole | ( | ) | const [inline] |
Dumps to console the output from getAsString()
Definition at line 300 of file base/include/mrpt/utils/types.h.
| void mrpt::utils::TParameters< T >::getAsString | ( | std::string & | s ) | const [inline] |
Returns a multi-like string representation of the parameters like : 'nam = val = val2...'.
Definition at line 306 of file base/include/mrpt/utils/types.h.
| std::string mrpt::utils::TParameters< T >::getAsString | ( | ) | const [inline] |
Returns a multi-like string representation of the parameters like : 'nam = val = val2...'.
Definition at line 303 of file base/include/mrpt/utils/types.h.
Referenced by mrpt::utils::TParameters< double >::dumpToConsole(), and mrpt::utils::TParameters< double >::getAsString().
| T mrpt::utils::TParameters< T >::getWithDefaultVal | ( | const std::string & | s, |
| const T & | defaultVal | ||
| ) | const [inline] |
A const version of the [] operator and with a default value in case the parameter is not set (for usage as read-only).
Definition at line 290 of file base/include/mrpt/utils/types.h.
| bool mrpt::utils::TParameters< T >::has | ( | const std::string & | s ) | const [inline] |
Definition at line 278 of file base/include/mrpt/utils/types.h.
| T& mrpt::utils::TParameters< T >::operator[] | ( | const std::string & | s ) | [inline] |
The write (non-const) version of the [] operator.
Definition at line 297 of file base/include/mrpt/utils/types.h.
| T mrpt::utils::TParameters< T >::operator[] | ( | const std::string & | s ) | const [inline] |
A const version of the [] operator, for usage as read-only.
| std::logic_error | On parameter not present. Please, check existence with "has" before reading. |
Definition at line 282 of file base/include/mrpt/utils/types.h.
Referenced by mrpt::utils::TParameters< double >::operator[](), and mrpt::utils::TParameters< double >::TParameters().
| Page generated by Doxygen 1.7.2 for MRPT 0.9.4 SVN: at Mon Jan 10 22:30:30 UTC 2011 |