MRPT  1.9.9
List of all members | Public Types | Public Member Functions | Public Attributes
mrpt::system::TParameters< T > Struct Template Reference

Detailed Description

template<typename T>
struct mrpt::system::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 nullptr 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, nullptr); //
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
Examples:
comms_http_client/test.cpp.

Definition at line 54 of file TParameters.h.

#include <mrpt/system/TParameters.h>

Inheritance diagram for mrpt::system::TParameters< T >:

Public Types

using BASE = std::map< std::string, T >
 
using iterator = typename BASE::iterator
 
using const_iterator = typename BASE::const_iterator
 

Public Member Functions

 TParameters ()
 Default constructor (initializes empty) More...
 
 TParameters (std::initializer_list< typename BASE::value_type > init)
 Constructor with a list of initial values (see the description and use example in mrpt::system::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...
 
template<typename RET >
RET getWithDefaultVal (const std::string &s, const RET &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...
 
void clear ()
 
iterator find (const std::string &key)
 
const_iterator find (const std::string &key) const
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 

Public Attributes

BASE base
 

Member Typedef Documentation

◆ BASE

template<typename T>
using mrpt::system::TParameters< T >::BASE = std::map<std::string, T>

Definition at line 56 of file TParameters.h.

◆ const_iterator

template<typename T>
using mrpt::system::TParameters< T >::const_iterator = typename BASE::const_iterator

Definition at line 59 of file TParameters.h.

◆ iterator

template<typename T>
using mrpt::system::TParameters< T >::iterator = typename BASE::iterator

Definition at line 58 of file TParameters.h.

Constructor & Destructor Documentation

◆ TParameters() [1/2]

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

Default constructor (initializes empty)

Definition at line 62 of file TParameters.h.

◆ TParameters() [2/2]

template<typename T>
mrpt::system::TParameters< T >::TParameters ( std::initializer_list< typename BASE::value_type >  init)
inline

Constructor with a list of initial values (see the description and use example in mrpt::system::TParameters)

Definition at line 65 of file TParameters.h.

Member Function Documentation

◆ begin() [1/2]

template<typename T>
iterator mrpt::system::TParameters< T >::begin ( )
inlinenoexcept

Definition at line 134 of file TParameters.h.

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

Here is the caller graph for this function:

◆ begin() [2/2]

template<typename T>
const_iterator mrpt::system::TParameters< T >::begin ( ) const
inlinenoexcept

Definition at line 135 of file TParameters.h.

◆ clear()

template<typename T>
void mrpt::system::TParameters< T >::clear ( )
inline

Definition at line 131 of file TParameters.h.

Referenced by mrpt::comms::net::http_request(), and mrpt::hwdrivers::CNTRIPClient::retrieveListOfMountpoints().

Here is the caller graph for this function:

◆ dumpToConsole()

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

Dumps to console the output from getAsString()

Definition at line 102 of file TParameters.h.

◆ end() [1/2]

template<typename T>
iterator mrpt::system::TParameters< T >::end ( )
inlinenoexcept

Definition at line 136 of file TParameters.h.

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

Here is the caller graph for this function:

◆ end() [2/2]

template<typename T>
const_iterator mrpt::system::TParameters< T >::end ( ) const
inlinenoexcept

Definition at line 137 of file TParameters.h.

◆ find() [1/2]

template<typename T>
iterator mrpt::system::TParameters< T >::find ( const std::string &  key)
inline

Definition at line 132 of file TParameters.h.

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

Here is the caller graph for this function:

◆ find() [2/2]

template<typename T>
const_iterator mrpt::system::TParameters< T >::find ( const std::string &  key) const
inline

Definition at line 133 of file TParameters.h.

◆ getAsString() [1/2]

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

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

Definition at line 109 of file TParameters.h.

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

Here is the caller graph for this function:

◆ getAsString() [2/2]

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

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

Definition at line 118 of file TParameters.h.

◆ getWithDefaultVal()

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

◆ has()

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

Definition at line 69 of file TParameters.h.

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

Here is the caller graph for this function:

◆ operator[]() [1/2]

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

◆ operator[]() [2/2]

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

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

Definition at line 100 of file TParameters.h.

Member Data Documentation

◆ base

template<typename T>
BASE mrpt::system::TParameters< T >::base



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020