Main MRPT website > C++ reference
MRPT logo
Public Types | Public Member Functions
mrpt::utils::TParameters Struct Reference

Detailed Description

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".

See also:
the example in MRPT/samples/params-by-name

#include <mrpt/utils/TParameters.h>

Inheritance diagram for mrpt::utils::TParameters:
Inheritance graph
[legend]

List of all members.

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
operator[] (const std::string &s) const
 A const version of the [] operator, for usage as read-only.
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...'.

Member Typedef Documentation

Definition at line 66 of file TParameters.h.


Constructor & Destructor Documentation

mrpt::utils::TParameters::TParameters ( ) [inline]

Default constructor (initializes empty)

Definition at line 68 of file TParameters.h.

mrpt::utils::TParameters::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 70 of file TParameters.h.


Member Function Documentation

void mrpt::utils::TParameters::dumpToConsole ( ) const [inline]

Dumps to console the output from getAsString()

Definition at line 111 of file TParameters.h.

std::string mrpt::utils::TParameters::getAsString ( ) const [inline]

Returns a multi-like string representation of the parameters like : 'nam = val = val2...'.

Definition at line 114 of file TParameters.h.

Referenced by mrpt::utils::TParameters< double >::dumpToConsole(), and mrpt::utils::TParameters< double >::getAsString().

void mrpt::utils::TParameters::getAsString ( std::string s) const [inline]

Returns a multi-like string representation of the parameters like : 'nam = val = val2...'.

Definition at line 117 of file TParameters.h.

T mrpt::utils::TParameters::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 101 of file TParameters.h.

Referenced by mrpt::opengl::graph_tools::graph_visualize().

bool mrpt::utils::TParameters::has ( const std::string s) const [inline]

Definition at line 89 of file TParameters.h.

T mrpt::utils::TParameters::operator[] ( const std::string s) const [inline]

A const version of the [] operator, for usage as read-only.

Exceptions:
std::logic_errorOn parameter not present. Please, check existence with "has" before reading.

Definition at line 93 of file TParameters.h.

Referenced by mrpt::utils::TParameters< double >::TParameters(), and mrpt::utils::TParameters< double >::operator[]().

T& mrpt::utils::TParameters::operator[] ( const std::string s) [inline]

The write (non-const) version of the [] operator.

Definition at line 108 of file TParameters.h.




Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011