Public Member Functions | List of all members
cras::ParamHelper Class Reference

This class provides a unified experience for nodes, nodelets and filters for getting ROS parameter values. Each parameter has to be provided a default value, and each parameter read is logged - specified parameters with INFO verbosity level, defaulted parameters with WARN level. There are also lots of template specializations for builtin ROS types or unsigned values which ease the process of reading the parameters correctly. More...

#include <param_helper.hpp>

Inheritance diagram for cras::ParamHelper:
Inheritance graph
[legend]

Public Member Functions

::cras::LogHelperPtr getLogger () const
 Return the log helper used for logging. More...
 
template<typename ResultType , typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type, ::cras::check_get_param_types< ResultType, ParamServerType > * = nullptr>
ResultType getParam (const ::cras::GetParamAdapter &param, const ::std::string &name, const ::cras::optional< ResultType > &defaultValue=ResultType(), const ::std::string &unit="", const ::cras::GetParamOptions< ResultType, ParamServerType > &options={}) const
 Get the value of the given ROS parameter, falling back to the specified default value (if not nullopt), and print out a ROS log message with the loaded values (if specified). More...
 
template<typename ResultType , typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type, ::cras::check_get_param_types< ResultType, ParamServerType > * = nullptr>
ResultType getParam (const ::cras::GetParamAdapter &param, const ::std::string &name, const ResultType &defaultValue=ResultType(), const ::std::string &unit="", const ::cras::GetParamOptions< ResultType, ParamServerType > &options={}) const
 Get the value of the given ROS parameter, falling back to the specified default value, and print out a ROS log message with the loaded values (if specified). More...
 
inline ::std::string getParam (const ::cras::GetParamAdapter &param, const ::std::string &name, const ::cras::optional< const char *> &defaultValue, const ::std::string &unit="", const ::cras::GetParamOptions<::std::string > &options={}) const
 Get the value of the given ROS parameter, falling back to the specified default value (if not nullopt), and print out a ROS log message with the loaded values (if specified). More...
 
inline ::std::string getParam (const ::cras::GetParamAdapter &param, const ::std::string &name, const char *defaultValue, const ::std::string &unit="", const ::cras::GetParamOptions<::std::string > &options={}) const
 Get the value of the given ROS parameter, falling back to the specified default value, and print out a ROS log message with the loaded values (if specified). More...
 
template<typename ResultType , typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type, ::cras::check_get_param_types< ResultType, ParamServerType > * = nullptr>
inline ::cras::GetParamResult< ResultType > getParamVerbose (const ::cras::GetParamAdapter &param, const ::std::string &name, const ::cras::optional< ResultType > &defaultValue=ResultType(), const ::std::string &unit="", const ::cras::GetParamOptions< ResultType, ParamServerType > &options={}) const
 Get the value of the given ROS parameter, falling back to the specified default value (if not nullopt), and print out a ROS log message with the loaded values (if specified). More...
 
template<typename ResultType , typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type, ::cras::check_get_param_types< ResultType, ParamServerType > * = nullptr>
inline ::cras::GetParamResult< ResultType > getParamVerbose (const ::cras::GetParamAdapter &param, const ::std::string &name, const ResultType &defaultValue=ResultType(), const ::std::string &unit="", const ::cras::GetParamOptions< ResultType, ParamServerType > &options={}) const
 Get the value of the given ROS parameter, falling back to the specified default value, and print out a ROS log message with the loaded values (if specified). More...
 
inline ::cras::GetParamResult<::std::string > getParamVerbose (const ::cras::GetParamAdapter &param, const ::std::string &name, const ::cras::optional< const char *> &defaultValue, const ::std::string &unit="", const ::cras::GetParamOptions<::std::string > &options={}) const
 Get the value of the given ROS parameter, falling back to the specified default value (if not nullopt), and print out a ROS log message with the loaded values (if specified). More...
 
inline ::cras::GetParamResult<::std::string > getParamVerbose (const ::cras::GetParamAdapter &param, const ::std::string &name, const char *defaultValue, const ::std::string &unit="", const ::cras::GetParamOptions<::std::string > &options={}) const
 Get the value of the given ROS parameter, falling back to the specified default value, and print out a ROS log message with the loaded values (if specified). More...
 
 ParamHelper (const ::cras::LogHelperPtr &log)
 
void setLogger (const ::cras::LogHelperPtr &logger)
 Set the log helper used for logging. More...
 
virtual ~ParamHelper ()=default
 
- Public Member Functions inherited from cras::HasLogger
::cras::LogHelperConstPtr getCrasLogger () const
 This is the function picked up by CRAS_* logging macros. More...
 
 HasLogger (const ::cras::LogHelperPtr &log)
 Associate the logger with this interface. More...
 
void setCrasLogger (const ::cras::LogHelperPtr &log)
 Set the logger to be used for logging. More...
 

Additional Inherited Members

- Protected Attributes inherited from cras::HasLogger
::cras::LogHelperPtr log
 Log helper. More...
 

Detailed Description

This class provides a unified experience for nodes, nodelets and filters for getting ROS parameter values. Each parameter has to be provided a default value, and each parameter read is logged - specified parameters with INFO verbosity level, defaulted parameters with WARN level. There are also lots of template specializations for builtin ROS types or unsigned values which ease the process of reading the parameters correctly.

Definition at line 31 of file param_utils/param_helper.hpp.

Constructor & Destructor Documentation

◆ ParamHelper()

cras::ParamHelper::ParamHelper ( const ::cras::LogHelperPtr log)
inlineexplicit

Create the param helper using the given log helper for logging messages.

Parameters
logThe log helper to use for logging.

Definition at line 38 of file param_utils/param_helper.hpp.

◆ ~ParamHelper()

virtual cras::ParamHelper::~ParamHelper ( )
virtualdefault

Member Function Documentation

◆ getLogger()

::cras::LogHelperPtr cras::ParamHelper::getLogger ( ) const
inline

Return the log helper used for logging.

Returns
The log helper.

Definition at line 251 of file param_utils/param_helper.hpp.

◆ getParam() [1/4]

template<typename ResultType , typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type, ::cras::check_get_param_types< ResultType, ParamServerType > * = nullptr>
ResultType cras::ParamHelper::getParam ( const ::cras::GetParamAdapter param,
const ::std::string &  name,
const ::cras::optional< ResultType > &  defaultValue = ResultType(),
const ::std::string &  unit = "",
const ::cras::GetParamOptions< ResultType, ParamServerType > &  options = {} 
) const
inline

Get the value of the given ROS parameter, falling back to the specified default value (if not nullopt), and print out a ROS log message with the loaded values (if specified).

Template Parameters
ResultTypeParam type (the C++ type). It is converted from the intermediate ParamServerType using options.toResult function (which defaults to static_cast).
ParamServerTypeIntermediate type to which the XmlRpcValue read from parameter server is converted. The conversion is done using options.toParam function (which defaults to cras::convert). Most overloads of cras::convert are in xmlrpc_value_utils.hpp, but you can add your own.
Parameters
[in]paramThe parameter adapter from which parameters are read.
[in]nameName of the parameter.
[in]defaultValueThe default value to use. If std::nullopt, then the parameter is required. If a required param is not found, a GetParamException is thrown.
[in]unitOptional string serving as a [physical/SI] unit of the parameter, just to make the messages more informative.
[in]optionsOptions specifying detailed behavior of this function. Use the braced initializer syntax for comfortable writing, e.g. {.throwIfConvertFails = true, .allowNestedParams = false}.
Returns
The loaded parameter value.

Definition at line 122 of file param_utils/param_helper.hpp.

◆ getParam() [2/4]

template<typename ResultType , typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type, ::cras::check_get_param_types< ResultType, ParamServerType > * = nullptr>
ResultType cras::ParamHelper::getParam ( const ::cras::GetParamAdapter param,
const ::std::string &  name,
const ResultType &  defaultValue = ResultType(),
const ::std::string &  unit = "",
const ::cras::GetParamOptions< ResultType, ParamServerType > &  options = {} 
) const
inline

Get the value of the given ROS parameter, falling back to the specified default value, and print out a ROS log message with the loaded values (if specified).

Template Parameters
ResultTypeParam type (the C++ type). It is converted from the intermediate ParamServerType using options.toResult function (which defaults to static_cast).
ParamServerTypeIntermediate type to which the XmlRpcValue read from parameter server is converted. The conversion is done using options.toParam function (which defaults to cras::convert). Most overloads of cras::convert are in xmlrpc_value_utils.hpp, but you can add your own.
Parameters
[in]paramThe parameter adapter from which parameters are read.
[in]nameName of the parameter.
[in]defaultValueThe default value to use.
[in]unitOptional string serving as a [physical/SI] unit of the parameter, just to make the messages more informative.
[in]optionsOptions specifying detailed behavior of this function. Use the braced initializer syntax for comfortable writing, e.g. {.throwIfConvertFails = true, .allowNestedParams = false}.
Returns
The loaded parameter value.

Definition at line 150 of file param_utils/param_helper.hpp.

◆ getParam() [3/4]

inline ::std::string cras::ParamHelper::getParam ( const ::cras::GetParamAdapter param,
const ::std::string &  name,
const ::cras::optional< const char *> &  defaultValue,
const ::std::string &  unit = "",
const ::cras::GetParamOptions<::std::string > &  options = {} 
) const
inline

Get the value of the given ROS parameter, falling back to the specified default value (if not nullopt), and print out a ROS log message with the loaded values (if specified).

This is a variant allowing use of C-string instead of std::string.

Parameters
[in]paramThe parameter adapter from which parameters are read.
[in]nameName of the parameter.
[in]defaultValueThe default value to use. If std::nullopt, then the parameter is required. If a required param is not found, a GetParamException is thrown.
[in]unitOptional string serving as a [physical/SI] unit of the parameter, just to make the messages more informative.
[in]optionsOptions specifying detailed behavior of this function. Use the braced initializer syntax for comfortable writing, e.g. {.throwIfConvertFails = true, .allowNestedParams = false}.
Returns
The loaded parameter value.

Definition at line 218 of file param_utils/param_helper.hpp.

◆ getParam() [4/4]

inline ::std::string cras::ParamHelper::getParam ( const ::cras::GetParamAdapter param,
const ::std::string &  name,
const char *  defaultValue,
const ::std::string &  unit = "",
const ::cras::GetParamOptions<::std::string > &  options = {} 
) const
inline

Get the value of the given ROS parameter, falling back to the specified default value, and print out a ROS log message with the loaded values (if specified).

This is a variant allowing use of C-string instead of std::string.

Parameters
[in]paramThe parameter adapter from which parameters are read.
[in]nameName of the parameter.
[in]defaultValueThe default value to use.
[in]unitOptional string serving as a [physical/SI] unit of the parameter, just to make the messages more informative.
[in]optionsOptions specifying detailed behavior of this function. Use the braced initializer syntax for comfortable writing, e.g. {.throwIfConvertFails = true, .allowNestedParams = false}.
Returns
The loaded parameter value.

Definition at line 239 of file param_utils/param_helper.hpp.

◆ getParamVerbose() [1/4]

template<typename ResultType , typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type, ::cras::check_get_param_types< ResultType, ParamServerType > * = nullptr>
inline ::cras::GetParamResult<ResultType> cras::ParamHelper::getParamVerbose ( const ::cras::GetParamAdapter param,
const ::std::string &  name,
const ::cras::optional< ResultType > &  defaultValue = ResultType(),
const ::std::string &  unit = "",
const ::cras::GetParamOptions< ResultType, ParamServerType > &  options = {} 
) const
inline

Get the value of the given ROS parameter, falling back to the specified default value (if not nullopt), and print out a ROS log message with the loaded values (if specified).

Overloads defining conversion to various types can be defined in several forms. You can either overload cras::convert() that converts the XmlRpcValue to an intermediate value, or you can make the intermediate value autoconvertible to the result type, or you can overload getParamVerbose() itself.

Template Parameters
ResultTypeParam type (the C++ type). It is converted from the intermediate ParamServerType using options.toResult function (which defaults to static_cast).
ParamServerTypeIntermediate type to which the XmlRpcValue read from parameter server is converted. The conversion is done using options.toParam function (which defaults to cras::convert). Most overloads of cras::convert are in xmlrpc_value_utils.hpp, but you can add your own.
Parameters
[in]paramThe parameter adapter from which parameters are read.
[in]nameName of the parameter.
[in]defaultValueThe default value to use. If std::nullopt, then the parameter is required. If a required param is not found, a GetParamException is thrown.
[in]unitOptional string serving as a [physical/SI] unit of the parameter, just to make the messages more informative.
[in]optionsOptions specifying detailed behavior of this function. Use the braced initializer syntax for comfortable writing, e.g. {.throwIfConvertFails = true, .allowNestedParams = false}.
Returns
A wrapper containing the loaded parameter value and details about the function execution.

Definition at line 65 of file param_utils/param_helper.hpp.

◆ getParamVerbose() [2/4]

template<typename ResultType , typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type, ::cras::check_get_param_types< ResultType, ParamServerType > * = nullptr>
inline ::cras::GetParamResult<ResultType> cras::ParamHelper::getParamVerbose ( const ::cras::GetParamAdapter param,
const ::std::string &  name,
const ResultType &  defaultValue = ResultType(),
const ::std::string &  unit = "",
const ::cras::GetParamOptions< ResultType, ParamServerType > &  options = {} 
) const
inline

Get the value of the given ROS parameter, falling back to the specified default value, and print out a ROS log message with the loaded values (if specified).

Template Parameters
ResultTypeParam type (the C++ type). It is converted from the intermediate ParamServerType using options.toResult function (which defaults to static_cast).
ParamServerTypeIntermediate type to which the XmlRpcValue read from parameter server is converted. The conversion is done using options.toParam function (which defaults to cras::convert). Most overloads of cras::convert are in xmlrpc_value_utils.hpp, but you can add your own.
Parameters
[in]paramThe parameter adapter from which parameters are read.
[in]nameName of the parameter.
[in]defaultValueThe default value to use.
[in]unitOptional string serving as a [physical/SI] unit of the parameter, just to make the messages more informative.
[in]optionsOptions specifying detailed behavior of this function. Use the braced initializer syntax for comfortable writing, e.g. {.throwIfConvertFails = true, .allowNestedParams = false}.
Returns
A wrapper containing the loaded parameter value and details about the function execution.

Definition at line 93 of file param_utils/param_helper.hpp.

◆ getParamVerbose() [3/4]

inline ::cras::GetParamResult<::std::string> cras::ParamHelper::getParamVerbose ( const ::cras::GetParamAdapter param,
const ::std::string &  name,
const ::cras::optional< const char *> &  defaultValue,
const ::std::string &  unit = "",
const ::cras::GetParamOptions<::std::string > &  options = {} 
) const
inline

Get the value of the given ROS parameter, falling back to the specified default value (if not nullopt), and print out a ROS log message with the loaded values (if specified).

This is a variant allowing use of C-string instead of std::string.

Parameters
[in]paramThe parameter adapter from which parameters are read.
[in]nameName of the parameter.
[in]defaultValueThe default value to use. If std::nullopt, then the parameter is required. If a required param is not found, a GetParamException is thrown.
[in]unitOptional string serving as a [physical/SI] unit of the parameter, just to make the messages more informative.
[in]optionsOptions specifying detailed behavior of this function. Use the braced initializer syntax for comfortable writing, e.g. {.throwIfConvertFails = true, .allowNestedParams = false}.
Returns
A wrapper containing the loaded parameter value and details about the function execution.

Definition at line 175 of file param_utils/param_helper.hpp.

◆ getParamVerbose() [4/4]

inline ::cras::GetParamResult<::std::string> cras::ParamHelper::getParamVerbose ( const ::cras::GetParamAdapter param,
const ::std::string &  name,
const char *  defaultValue,
const ::std::string &  unit = "",
const ::cras::GetParamOptions<::std::string > &  options = {} 
) const
inline

Get the value of the given ROS parameter, falling back to the specified default value, and print out a ROS log message with the loaded values (if specified).

This is a variant allowing use of C-string instead of std::string.

Parameters
[in]paramThe parameter adapter from which parameters are read.
[in]nameName of the parameter.
[in]defaultValueThe default value to use.
[in]unitOptional string serving as a [physical/SI] unit of the parameter, just to make the messages more informative.
[in]optionsOptions specifying detailed behavior of this function. Use the braced initializer syntax for comfortable writing, e.g. {.throwIfConvertFails = true, .allowNestedParams = false}.
Returns
A wrapper containing the loaded parameter value and details about the function execution.

Definition at line 196 of file param_utils/param_helper.hpp.

◆ setLogger()

void cras::ParamHelper::setLogger ( const ::cras::LogHelperPtr logger)
inline

Set the log helper used for logging.

Parameters
[in]loggerThe new log helper.

Definition at line 260 of file param_utils/param_helper.hpp.


The documentation for this class was generated from the following file:


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Sat Jun 17 2023 02:32:53