mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
param_provider.hpp
1 #ifndef PARAM_PROVIDER_HPP
2 #define PARAM_PROVIDER_HPP
3 
5 
6 namespace mrs_lib
7 {
8  template <typename T>
9  bool ParamProvider::getParam(const std::string& param_name, T& value_out) const
10  {
11  try
12  {
13  return getParamImpl(param_name, value_out);
14  }
15  catch (const YAML::Exception& e)
16  {
17  ROS_ERROR_STREAM("[" << m_node_name << "]: YAML-CPP threw an unknown exception: " << e.what());
18  return false;
19  }
20  }
21 
22  template <typename T>
23  bool ParamProvider::getParamImpl(const std::string& param_name, T& value_out) const
24  {
25  {
26  const auto found_node = findYamlNode(param_name);
27  if (found_node.has_value())
28  {
29  try
30  {
31  // try catch is the only type-generic option...
32  value_out = found_node.value().as<T>();
33  return true;
34  }
35  catch (const YAML::BadConversion& e)
36  {}
37  }
38 
39  }
40 
41  if (m_use_rosparam)
42  return m_nh.getParam(param_name, value_out);
43 
44  return false;
45  }
46 }
47 
48 #endif // PARAM_PROVIDER_HPP
mrs_lib::ParamProvider::getParam
bool getParam(const std::string &param_name, T &value_out) const
Gets the value of a parameter.
Definition: param_provider.hpp:9
mrs_lib
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition: attitude_converter.h:29
param_provider.h
Defines ParamProvider - a helper class for ParamLoader.