Public Member Functions | Protected Attributes | List of all members
cras::BoundParamHelper Class Reference

Bound param helper (allows omitting the param adapter in each getParam call). More...

#include <bound_param_helper.hpp>

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

Public Member Functions

 BoundParamHelper (const ::cras::LogHelperPtr &log, const ::cras::GetParamAdapterPtr &param)
 
inline ::std::string getNamespace () const
 Return the namespace this helper operates in. More...
 
inline ::std::string getParam (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...
 
template<typename ResultType , typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type, ::cras::check_get_param_types< ResultType, ParamServerType > * = nullptr>
ResultType getParam (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...
 
inline ::std::string getParam (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>
ResultType getParam (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 ::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...
 
template<typename ResultType , typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type, ::cras::check_get_param_types< ResultType, ParamServerType > * = nullptr>
inline ::cras::GetParamResult< ResultType > getParamVerbose (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...
 
inline ::cras::GetParamResult< std::string > getParamVerbose (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 ::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...
 
bool hasParam (const ::std::string &name, const bool searchNested=true) const
 Whether a parameter with the given name exists. More...
 
inline ::cras::BoundParamHelperPtr paramsInNamespace (const ::std::string &ns) const
 Return a parameter helper of a sub-namespace. More...
 
 ~BoundParamHelper () override=default
 

Protected Attributes

::cras::GetParamAdapterPtr param
 The bound parameter adapter. More...
 
- Protected Attributes inherited from cras::HasLogger
::cras::LogHelperPtr log
 Log helper. More...
 

Additional Inherited Members

- Protected Member Functions inherited from cras::ParamHelper
::cras::LogHelperPtr getLogger () const
 Return the log helper used for logging. 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...
 
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...
 
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>
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 ::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...
 
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...
 
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...
 
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...
 
 ParamHelper (const ::cras::LogHelperPtr &log)
 
void setLogger (const ::cras::LogHelperPtr &logger)
 Set the log helper used for logging. More...
 
virtual ~ParamHelper ()=default
 
- Protected 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...
 

Detailed Description

Bound param helper (allows omitting the param adapter in each getParam call).

Definition at line 30 of file bound_param_helper.hpp.

Constructor & Destructor Documentation

◆ BoundParamHelper()

cras::BoundParamHelper::BoundParamHelper ( const ::cras::LogHelperPtr log,
const ::cras::GetParamAdapterPtr param 
)
inline

Create the bound param helper.

Parameters
logThe log helper to use for logging parameter read messages.
paramThe raw parameter adapter to bind to.

Definition at line 38 of file bound_param_helper.hpp.

◆ ~BoundParamHelper()

cras::BoundParamHelper::~BoundParamHelper ( )
overridedefault

Member Function Documentation

◆ getNamespace()

inline ::std::string cras::BoundParamHelper::getNamespace ( ) const
inline

Return the namespace this helper operates in.

Returns
The namespace.

Definition at line 271 of file bound_param_helper.hpp.

◆ getParam() [1/4]

inline ::std::string cras::BoundParamHelper::getParam ( 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]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 202 of file bound_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::BoundParamHelper::getParam ( 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]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 116 of file bound_param_helper.hpp.

◆ getParam() [3/4]

inline ::std::string cras::BoundParamHelper::getParam ( 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]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 221 of file bound_param_helper.hpp.

◆ getParam() [4/4]

template<typename ResultType , typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type, ::cras::check_get_param_types< ResultType, ParamServerType > * = nullptr>
ResultType cras::BoundParamHelper::getParam ( 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]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 141 of file bound_param_helper.hpp.

◆ getParamVerbose() [1/4]

inline ::cras::GetParamResult<::std::string> cras::BoundParamHelper::getParamVerbose ( 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]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 163 of file bound_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::BoundParamHelper::getParamVerbose ( 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]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 64 of file bound_param_helper.hpp.

◆ getParamVerbose() [3/4]

inline ::cras::GetParamResult<std::string> cras::BoundParamHelper::getParamVerbose ( 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]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 182 of file bound_param_helper.hpp.

◆ getParamVerbose() [4/4]

template<typename ResultType , typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type, ::cras::check_get_param_types< ResultType, ParamServerType > * = nullptr>
inline ::cras::GetParamResult<ResultType> cras::BoundParamHelper::getParamVerbose ( 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]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 89 of file bound_param_helper.hpp.

◆ hasParam()

bool cras::BoundParamHelper::hasParam ( const ::std::string &  name,
const bool  searchNested = true 
) const
inline

Whether a parameter with the given name exists.

Parameters
[in]nameName of the parameter.
[in]searchNestedIf true, nested parameters (containing slash) will be looked up recursively. Otherwise, exact name match is required and slashes in name will result in failure (returning false).
Returns
Whether the parameter exists.

Definition at line 235 of file bound_param_helper.hpp.

◆ paramsInNamespace()

inline ::cras::BoundParamHelperPtr cras::BoundParamHelper::paramsInNamespace ( const ::std::string &  ns) const
inline

Return a parameter helper of a sub-namespace.

Parameters
[in]nsNamespace.
Returns
The new helper.

Definition at line 262 of file bound_param_helper.hpp.

Member Data Documentation

◆ param

::cras::GetParamAdapterPtr cras::BoundParamHelper::param
protected

The bound parameter adapter.

Definition at line 280 of file bound_param_helper.hpp.


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


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Tue Nov 26 2024 03:49:04