Classes | Namespaces | Macros | Typedefs | Functions
param_utils.hpp File Reference

This file provides helper methods easing access to parameters passed to nodes, nodelets and filters. More...

#include <functional>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <vector>
#include <cras_cpp_common/log_utils.h>
#include <cras_cpp_common/optional.hpp>
#include <cras_cpp_common/string_utils.hpp>
#include <cras_cpp_common/type_utils.hpp>
#include <cras_cpp_common/xmlrpc_value_utils.hpp>
#include <cras_cpp_common/param_utils/get_param_adapter.hpp>
#include <cras_cpp_common/param_utils/get_param_options.hpp>
#include <cras_cpp_common/param_utils/get_param_result.hpp>
Include dependency graph for param_utils.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  cras::GetParamException
 Exception thrown when conversion of a parameter fails during getParam() if option throwIfConvertFails is true or when a missing parameter is required. More...
 

Namespaces

 cras
 

Macros

#define DEFINE_CONVERTING_GET_PARAM(resultType, paramServerType, defaultUnit, convertToResultFn)
 Generate definitions of "specializations" of getParam(Verbose) that use different ResultType and ParamServerType. They will be automatically used when the user requests a parameter of type ResultType. If cras::to_string() cannot convert ResultType to string, you have to declare overload ::cras::to_string(const ResultType&) prior to calling this macro. More...
 
#define DEFINE_CONVERTING_GET_PARAM_WITH_CAST(resultType, paramServerType, defaultUnit)
 Generate definitions of "specializations" of getParam(Verbose) that use different ResultType and ParamServerType. They will be automatically used when the user requests a parameter of type ResultType. paramServerType is converted to resultType via static_cast. More...
 
#define DEFINE_CONVERTING_GET_PARAM_WITH_CONSTRUCTOR(resultType, paramServerType, defaultUnit)
 Generate definitions of "specializations" of getParam(Verbose) that use different ResultType and ParamServerType. They will be automatically used when the user requests a parameter of type ResultType. paramServerType is converted to resultType via resultType one-arg constructor. More...
 

Typedefs

template<typename ResultType , typename ParamServerType >
using cras::check_get_param_types = typename std::enable_if_t< !::cras::is_optional< ResultType >::value &&!::cras::is_c_string< ResultType >::value &&!::cras::is_c_string< ParamServerType >::value >
 This type is a TrueType if the combination of ResultType and ParamServerType is valid. More...
 

Functions

inline ::std::string cras::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 ::cras::LogHelper *const logger=nullptr)
 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 cras::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 ::cras::LogHelper *const logger=nullptr)
 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 cras::getParam (const ::cras::GetParamAdapter &param, const ::std::string &name, const char *defaultValue, const ::std::string &unit="", const ::cras::GetParamOptions<::std::string > &options={}, const ::cras::LogHelper *const logger=nullptr)
 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 cras::getParam (const ::cras::GetParamAdapter &param, const ::std::string &name, const ResultType &defaultValue=ResultType(), const ::std::string &unit="", const ::cras::GetParamOptions< ResultType, ParamServerType > &options={}, const ::cras::LogHelper *const logger=nullptr)
 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 > cras::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 ::cras::LogHelper *const logger=nullptr)
 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 > cras::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 ::cras::LogHelper *const logger=nullptr)
 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 > cras::getParamVerbose (const ::cras::GetParamAdapter &param, const ::std::string &name, const char *defaultValue, const ::std::string &unit="", const ::cras::GetParamOptions<::std::string > &options={}, const ::cras::LogHelper *const logger=nullptr)
 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 > cras::getParamVerbose (const ::cras::GetParamAdapter &param, const ::std::string &name, const ResultType &defaultValue=ResultType(), const ::std::string &unit="", const ::cras::GetParamOptions< ResultType, ParamServerType > &options={}, const ::cras::LogHelper *const logger=nullptr)
 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...
 

Detailed Description

This file provides helper methods easing access to parameters passed to nodes, nodelets and filters.

Author
Martin Pecka

Definition in file param_utils.hpp.

Macro Definition Documentation

◆ DEFINE_CONVERTING_GET_PARAM

#define DEFINE_CONVERTING_GET_PARAM (   resultType,
  paramServerType,
  defaultUnit,
  convertToResultFn 
)
Value:
template<>\
struct ParamToStringFn<resultType>\
{\
static ::std::string to_string(const resultType& v){ return ::cras::to_string(v); }\
};\
\
template<>\
struct DefaultToResultFn<resultType, paramServerType>\
{\
static resultType toResult(const paramServerType& v){ return convertToResultFn(v); }\
};\
\
template<>\
struct DefaultParamServerType<resultType>\
{\
typedef paramServerType type;\
};

Generate definitions of "specializations" of getParam(Verbose) that use different ResultType and ParamServerType. They will be automatically used when the user requests a parameter of type ResultType. If cras::to_string() cannot convert ResultType to string, you have to declare overload ::cras::to_string(const ResultType&) prior to calling this macro.

Parameters
resultTypeType of the result values.
paramServerTypeType of the intermediate values to which XmlRpcValues are converted.
defaultUnitThe unit to use if the users doesn't pass any.
convertToResultFnThe ToResultFn to use for parameter conversion.
Note
This macro has to be called in the cras namespace.
If cras::convert() cannot convert XmlRpcValue to paramServerType, you have to define specialization ::cras::DefaultToParamFn<paramServerType> which implements the toParam() conversion function.

Definition at line 484 of file param_utils.hpp.

◆ DEFINE_CONVERTING_GET_PARAM_WITH_CAST

#define DEFINE_CONVERTING_GET_PARAM_WITH_CAST (   resultType,
  paramServerType,
  defaultUnit 
)
Value:
DEFINE_CONVERTING_GET_PARAM(resultType, paramServerType, defaultUnit, \
([](const paramServerType& v) { return static_cast<resultType>(v); }))

Generate definitions of "specializations" of getParam(Verbose) that use different ResultType and ParamServerType. They will be automatically used when the user requests a parameter of type ResultType. paramServerType is converted to resultType via static_cast.

Parameters
resultTypeType of the result values.
paramServerTypeType of the intermediate values to which XmlRpcValues are converted.
defaultUnitThe unit to use if the users doesn't pass any.
Note
This macro has to be called in the cras namespace.

Definition at line 525 of file param_utils.hpp.

◆ DEFINE_CONVERTING_GET_PARAM_WITH_CONSTRUCTOR

#define DEFINE_CONVERTING_GET_PARAM_WITH_CONSTRUCTOR (   resultType,
  paramServerType,
  defaultUnit 
)
Value:
DEFINE_CONVERTING_GET_PARAM(resultType, paramServerType, defaultUnit, \
([](const paramServerType& v) { return resultType(v); }))

Generate definitions of "specializations" of getParam(Verbose) that use different ResultType and ParamServerType. They will be automatically used when the user requests a parameter of type ResultType. paramServerType is converted to resultType via resultType one-arg constructor.

Parameters
resultTypeType of the result values.
paramServerTypeType of the intermediate values to which XmlRpcValues are converted.
defaultUnitThe unit to use if the users doesn't pass any.
Note
This macro has to be called in the cras namespace.

Definition at line 512 of file param_utils.hpp.

DEFINE_CONVERTING_GET_PARAM
#define DEFINE_CONVERTING_GET_PARAM(resultType, paramServerType, defaultUnit, convertToResultFn)
Generate definitions of "specializations" of getParam(Verbose) that use different ResultType and Para...
Definition: param_utils.hpp:484
cras::to_string
inline ::std::string to_string(const ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &value)
Definition: string_utils/eigen.hpp:21


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Sun Jan 14 2024 03:48:14