bound_param_helper.hpp
Go to the documentation of this file.
1 #pragma once
2 
11 #include <memory>
12 #include <string>
13 
20 
21 namespace cras
22 {
23 
25 typedef ::std::shared_ptr<::cras::BoundParamHelper> BoundParamHelperPtr;
26 
31 {
32 public:
40  {
41  }
42 
43  ~BoundParamHelper() override = default;
44 
62  template<typename ResultType, typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type,
64  inline ::cras::GetParamResult<ResultType> getParamVerbose(
65  const ::std::string& name, const ::cras::optional<ResultType>& defaultValue = ResultType(),
66  const ::std::string& unit = "", const ::cras::GetParamOptions<ResultType, ParamServerType>& options = {}) const
67  {
68  return ::cras::ParamHelper::getParamVerbose(*this->param, name, defaultValue, unit, options);
69  }
70 
87  template<typename ResultType, typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type,
89  inline ::cras::GetParamResult<ResultType> getParamVerbose(
90  const ::std::string& name, const ResultType& defaultValue = ResultType(),
91  const ::std::string& unit = "", const ::cras::GetParamOptions<ResultType, ParamServerType>& options = {}) const
92  {
94  *this->param, name, ::cras::optional<ResultType>(defaultValue), unit, options);
95  }
96 
114  template<typename ResultType, typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type,
116  inline ResultType getParam(
117  const ::std::string& name, const ::cras::optional<ResultType>& defaultValue = ResultType(),
118  const ::std::string& unit = "", const ::cras::GetParamOptions<ResultType, ParamServerType>& options = {}) const
119  {
120  return ::cras::ParamHelper::getParam(*this->param, name, defaultValue, unit, options);
121  }
122 
139  template<typename ResultType, typename ParamServerType = typename ::cras::DefaultParamServerType<ResultType>::type,
141  inline ResultType getParam(
142  const ::std::string& name, const ResultType& defaultValue = ResultType(),
143  const ::std::string& unit = "", const ::cras::GetParamOptions<ResultType, ParamServerType>& options = {}) const
144  {
145  return ::cras::ParamHelper::getParam(*this->param, name, ::cras::optional<ResultType>(defaultValue), unit, options);
146  }
147 
148  // std::string - char interop specializations
149 
163  inline ::cras::GetParamResult<::std::string> getParamVerbose(
164  const ::std::string& name, const ::cras::optional<const char *>& defaultValue, const ::std::string& unit = "",
165  const ::cras::GetParamOptions<::std::string>& options = {}) const
166  {
167  return ::cras::ParamHelper::getParamVerbose(*this->param, name, defaultValue, unit, options);
168  }
169 
182  inline ::cras::GetParamResult<std::string> getParamVerbose(
183  const ::std::string& name, const char* defaultValue, const ::std::string& unit = "",
184  const ::cras::GetParamOptions<::std::string>& options = {}) const
185  {
186  return ::cras::ParamHelper::getParamVerbose(*this->param, name, defaultValue, unit, options);
187  }
188 
202  inline ::std::string getParam(
203  const ::std::string& name, const ::cras::optional<const char *>& defaultValue, const ::std::string& unit = "",
204  const ::cras::GetParamOptions<::std::string>& options = {}) const
205  {
206  return ::cras::ParamHelper::getParam(*this->param, name, defaultValue, unit, options);
207  }
208 
221  inline ::std::string getParam(
222  const ::std::string& name, const char* defaultValue, const ::std::string& unit = "",
223  const ::cras::GetParamOptions<std::string>& options = {}) const
224  {
225  return ::cras::ParamHelper::getParam(*this->param, name, defaultValue, unit, options);
226  }
227 
235  inline bool hasParam(const ::std::string& name, const bool searchNested = true) const
236  {
237  if (this->param->hasParam(name))
238  return true;
239  if (!searchNested)
240  return false;
241 
242  // try searching for a nested parameter
243  const auto parts = ::cras::split(name, "/", 1);
244  if (parts.size() == 1)
245  return false;
246  const auto& head = parts[0];
247  const auto& tail = parts[1];
248  if (!this->param->hasParam(head))
249  return false;
251  this->param->getParam(head, x);
253  return false;
254  return this->paramsInNamespace(head)->hasParam(tail);
255  }
256 
263  {
264  return ::std::make_shared<::cras::BoundParamHelper>(this->log, this->param->getNamespaced(ns));
265  }
266 
271  inline ::std::string getNamespace() const
272  {
273  return this->param->getNamespace();
274  }
275 
276  using ::cras::ParamHelper::getLogger;
277 
278 protected:
281 };
282 
283 }
cras::BoundParamHelper::getParamVerbose
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...
Definition: bound_param_helper.hpp:64
cras::ParamHelper
This class provides a unified experience for nodes, nodelets and filters for getting ROS parameter va...
Definition: param_utils/param_helper.hpp:31
cras
Definition: any.hpp:15
cras::BoundParamHelperPtr
::std::shared_ptr<::cras::BoundParamHelper > BoundParamHelperPtr
Definition: bound_param_helper.hpp:24
cras::BoundParamHelper::getParam
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...
Definition: bound_param_helper.hpp:116
cras::BoundParamHelper::getParamVerbose
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,...
Definition: bound_param_helper.hpp:182
cras::BoundParamHelper
Bound param helper (allows omitting the param adapter in each getParam call).
Definition: bound_param_helper.hpp:30
get_param_adapter.hpp
An adapter that allows getting ROS parameters from various sources.
XmlRpc::XmlRpcValue::TypeStruct
TypeStruct
cras::BoundParamHelper::getParamVerbose
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,...
Definition: bound_param_helper.hpp:89
cras::BoundParamHelper::~BoundParamHelper
~BoundParamHelper() override=default
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 > check_get_param_types
This type is a TrueType if the combination of ResultType and ParamServerType is valid.
Definition: param_utils.hpp:67
cras::getParamVerbose
GetParamResult< ResultType > getParamVerbose(const ::ros::NodeHandle &node, const ::std::string &name, const ::cras::optional< ResultType > &defaultValue=ResultType(), const ::std::string &unit="", const ::cras::GetParamOptions< ResultType, ParamServerType > &options={})
Get the value of the given ROS parameter, falling back to the specified default value (if not nullopt...
Definition: node_utils.hpp:51
cras::BoundParamHelper::getParamVerbose
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...
Definition: bound_param_helper.hpp:163
cras::getParam
ResultType getParam(const ::ros::NodeHandle &node, const ::std::string &name, const ::cras::optional< ResultType > &defaultValue=ResultType(), const ::std::string &unit="", const ::cras::GetParamOptions< ResultType, ParamServerType > &options={})
Get the value of the given ROS parameter, falling back to the specified default value (if not nullopt...
Definition: node_utils.hpp:110
cras::GetParamAdapterPtr
::std::shared_ptr<::cras::GetParamAdapter > GetParamAdapterPtr
Definition: get_param_adapter.hpp:57
param_helper.hpp
This class provides a unified experience for nodes, nodelets and filters for getting ROS parameter va...
cras::split
::std::vector<::std::string > split(const ::std::string &str, const ::std::string &delimiter, int maxSplits=-1)
Split the given string by the given delimiter.
get_param_result.hpp
Wrapper of getParam() call results.
log_utils.h
ROS logging helpers.
cras::BoundParamHelper::param
::cras::GetParamAdapterPtr param
The bound parameter adapter.
Definition: bound_param_helper.hpp:280
XmlRpc::XmlRpcValue::getType
const Type & getType() const
cras::BoundParamHelper::getParam
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,...
Definition: bound_param_helper.hpp:141
cras::BoundParamHelper::BoundParamHelper
BoundParamHelper(const ::cras::LogHelperPtr &log, const ::cras::GetParamAdapterPtr &param)
Definition: bound_param_helper.hpp:38
cras::BoundParamHelper::getParam
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,...
Definition: bound_param_helper.hpp:221
get_param_options.hpp
Options for getParam() calls.
cras::LogHelperPtr
::cras::LogHelper::Ptr LogHelperPtr
Pointer to LogHelper.
Definition: log_utils.h:202
cras::HasLogger::log
::cras::LogHelperPtr log
Log helper.
Definition: log_utils.h:252
cras::BoundParamHelper::hasParam
bool hasParam(const ::std::string &name, const bool searchNested=true) const
Whether a parameter with the given name exists.
Definition: bound_param_helper.hpp:235
XmlRpc::XmlRpcValue
cras::BoundParamHelper::getParam
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...
Definition: bound_param_helper.hpp:202
cras::BoundParamHelper::getNamespace
inline ::std::string getNamespace() const
Return the namespace this helper operates in.
Definition: bound_param_helper.hpp:271
cras::BoundParamHelper::paramsInNamespace
inline ::cras::BoundParamHelperPtr paramsInNamespace(const ::std::string &ns) const
Return a parameter helper of a sub-namespace.
Definition: bound_param_helper.hpp:262
optional.hpp
A C++11 shim for std::optional. Uses std::optional when used in C++17 mode.


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