Main MRPT website > C++ reference for MRPT 1.5.9
List of all members | Public Types | Public Member Functions | Public Attributes
mrpt::utils::TParameters< T > Struct Template Reference

Detailed Description

template<typename T>
struct mrpt::utils::TParameters< T >

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

Definition at line 51 of file TParameters.h.

#include <mrpt/utils/TParameters.h>

Inheritance diagram for mrpt::utils::TParameters< T >:
Inheritance graph

Public Types

typedef std::map< std::string, T > BASE
 

Public Member Functions

 TParameters ()
 Default constructor (initializes empty) More...
 
 TParameters (const char *nam1,...)
 Constructor with a list of initial values (see the description and use example in mrpt::utils::TParameters) More...
 
bool has (const std::string &s) const
 
operator[] (const std::string &s) const
 A const version of the [] operator, for usage as read-only. More...
 
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). More...
 
T & operator[] (const std::string &s)
 The write (non-const) version of the [] operator. More...
 
void dumpToConsole () const
 Dumps to console the output from getAsString() More...
 
std::string getAsString () const
 Returns a multi-line string representation of the parameters like : 'nam = val = val2...'. More...
 
void getAsString (std::string &s) const
 Returns a multi-line string representation of the parameters like : 'nam = val = val2...'. More...
 

Public Attributes

keys
 STL member. More...
 
elements
 STL member. More...
 

Member Typedef Documentation

◆ BASE

template<typename T>
typedef std::map<std::string,T> mrpt::utils::TParameters< T >::BASE

Definition at line 53 of file TParameters.h.

Constructor & Destructor Documentation

◆ TParameters() [1/2]

template<typename T>
mrpt::utils::TParameters< T >::TParameters ( )
inline

Default constructor (initializes empty)

Definition at line 55 of file TParameters.h.

◆ TParameters() [2/2]

template<typename T>
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 57 of file TParameters.h.

Member Function Documentation

◆ dumpToConsole()

template<typename T>
void mrpt::utils::TParameters< T >::dumpToConsole ( ) const
inline

Dumps to console the output from getAsString()

Definition at line 98 of file TParameters.h.

◆ getAsString() [1/2]

template<typename T>
std::string mrpt::utils::TParameters< T >::getAsString ( ) const
inline

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

Definition at line 101 of file TParameters.h.

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

◆ getAsString() [2/2]

template<typename T>
void mrpt::utils::TParameters< T >::getAsString ( std::string s) const
inline

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

Definition at line 104 of file TParameters.h.

◆ getWithDefaultVal()

template<typename T>
T mrpt::utils::TParameters< T >::getWithDefaultVal ( const std::string s,
const T &  defaultVal 
) const
inline

◆ has()

template<typename T>
bool mrpt::utils::TParameters< T >::has ( const std::string s) const
inline

Definition at line 76 of file TParameters.h.

Referenced by mrpt::utils::net::http_request().

◆ operator[]() [1/2]

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

◆ operator[]() [2/2]

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

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

Definition at line 95 of file TParameters.h.

Member Data Documentation

◆ elements

T std::map< K, T >::elements
inherited

STL member.

◆ keys

K std::map< K, T >::keys
inherited

STL member.




Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020