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:
39  ::cras::ParamHelper(log), param(param)
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,
88  ::cras::check_get_param_types<ResultType, ParamServerType>* = nullptr>
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,
115  ::cras::check_get_param_types<ResultType, ParamServerType>* = nullptr>
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,
140  ::cras::check_get_param_types<ResultType, ParamServerType>* = nullptr>
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 }
inline ::std::string getNamespace() const
Return the namespace this helper operates in.
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
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...
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
~BoundParamHelper() override=default
A C++11 shim for std::optional. Uses std::optional when used in C++17 mode.
Options for getParam() calls.
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).
::std::shared_ptr<::cras::GetParamAdapter > GetParamAdapterPtr
::cras::LogHelperPtr log
Log helper.
Definition: log_utils.h:252
inline ::cras::BoundParamHelperPtr paramsInNamespace(const ::std::string &ns) const
Return a parameter helper of a sub-namespace.
This class provides a unified experience for nodes, nodelets and filters for getting ROS parameter va...
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...
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).
Type const & getType() const
::std::shared_ptr<::cras::BoundParamHelper > BoundParamHelperPtr
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...
This class provides a unified experience for nodes, nodelets and filters for getting ROS parameter va...
options
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).
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
Bound param helper (allows omitting the param adapter in each getParam call).
bool hasParam(const ::std::string &name, const bool searchNested=true) const
Whether a parameter with the given name exists.
Wrapper of getParam() call results.
Definition: any.hpp:15
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).
::std::vector<::std::string > split(const ::std::string &str, const ::std::string &delimiter, int maxSplits=-1)
Split the given string by the given delimiter.
An adapter that allows getting ROS parameters from various sources.
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...
BoundParamHelper(const ::cras::LogHelperPtr &log, const ::cras::GetParamAdapterPtr &param)
ROS logging helpers.
::cras::GetParamAdapterPtr param
The bound parameter adapter.
::cras::LogHelper::Ptr LogHelperPtr
Pointer to LogHelper.
Definition: log_utils.h:202


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