1 #ifndef SWRI_ROSCPP_PARAMETERS_H_ 2 #define SWRI_ROSCPP_PARAMETERS_H_ 9 #include <boost/bind.hpp> 23 const std::string &
name,
27 _used_params.insert(resolved_name);
30 ROS_ERROR(
"Required int parameter %s does not exist", name.c_str());
33 ROS_INFO(
"Read parameter %s = %d", name.c_str(), variable);
39 const std::string &
name,
43 _used_params.insert(resolved_name);
46 ROS_ERROR(
"Required double parameter %s does not exist", name.c_str());
49 ROS_INFO(
"Read parameter %s = %lf", name.c_str(), variable);
55 const std::string &
name,
61 ROS_ERROR(
"Required double parameter %s does not exist", name.c_str());
65 ROS_INFO(
"Read parameter %s = %f", name.c_str(), variable);
71 const std::string &
name,
72 std::string &variable)
75 _used_params.insert(resolved_name);
78 ROS_ERROR(
"Required string parameter %s does not exist", name.c_str());
81 ROS_INFO(
"Read parameter %s = %s", name.c_str(), variable.c_str());
87 const std::string &
name,
91 _used_params.insert(resolved_name);
94 ROS_ERROR(
"Required bool parameter %s does not exist", name.c_str());
97 ROS_INFO(
"Read parameter %s = %s", name.c_str(), variable ?
"true" :
"false");
103 const std::string &
name,
105 const int default_value)
108 _used_params.insert(resolved_name);
109 nh.
param(name, variable, default_value);
110 ROS_INFO(
"Read parameter %s = %d", name.c_str(), variable);
115 const std::string &
name,
117 const double default_value)
120 _used_params.insert(resolved_name);
121 nh.
param(name, variable, default_value);
122 ROS_INFO(
"Read parameter %s = %lf", name.c_str(), variable);
127 const std::string &
name,
129 const float default_value)
132 double dbl_default = default_value;
133 nh.
param(name, dbl_value, dbl_default);
134 variable = dbl_value;
135 ROS_INFO(
"Read parameter %s = %f", name.c_str(), variable);
140 const std::string &
name,
141 std::string &variable,
142 const std::string default_value)
145 _used_params.insert(resolved_name);
146 nh.
param(name, variable, default_value);
147 ROS_INFO(
"Read parameter %s = \"%s\"", name.c_str(), variable.c_str());
152 const std::string &
name,
154 const bool default_value)
157 _used_params.insert(resolved_name);
158 nh.
param(name, variable, default_value);
159 ROS_INFO(
"Read parameter %s = %s", name.c_str(), variable ?
"true" :
"false");
172 inline int comparePrefix(std::string
const&
string, std::string
const& prefix)
174 return string.compare(0, prefix.size(), prefix);
186 inline bool isPrefixOf(std::string
const&
string, std::string
const& prefix)
228 std::vector<std::string> all_params;
232 std::sort(all_params.begin(), all_params.end());
236 boost::function<bool(std::string)> inNamespace = boost::bind(
isPrefixOf, _1, n_namespace);
238 std::vector<std::string>::const_iterator first_param_in_namespace = find_if(all_params.begin(), all_params.end(), inNamespace);
240 std::vector<std::string>::const_iterator after_last_param_in_namespace = find_if(all_params.begin(), all_params.end(), std::not1(inNamespace));
245 std::vector<std::string> unused_params(all_params.size());
248 std::vector<std::string>::iterator last_unused_param = std::set_difference(
249 first_param_in_namespace, after_last_param_in_namespace,
250 _used_params.begin(), _used_params.end(),
251 unused_params.begin(),
256 unused_params.resize(last_unused_param - unused_params.begin());
258 return unused_params;
270 for (std::vector<std::string>::const_iterator itr = unused_params.begin(); itr != unused_params.end(); ++itr)
272 ROS_WARN(
"Parameter %s was set, but not used by this node", itr->c_str());
276 #endif // SWRI_ROSCPP_PARAMETERS_H_ static std::set< std::string > _used_params
int prefixLessThan(std::string const &string, std::string const &prefix)
static std::vector< std::string > getUnusedParamKeys(ros::NodeHandle const &n)
int comparePrefix(std::string const &string, std::string const &prefix)
bool isPrefixOf(std::string const &string, std::string const &prefix)
static void warnUnusedParams(ros::NodeHandle const &n)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
bool getParam(const std::string &key, std::string &s) const
std::string resolveName(const std::string &name, bool remap=true) const
void param(swri::NodeHandle &nh, const std::string name, std::string &value, const std::string def, const std::string description)
bool getParamNames(std::vector< std::string > &keys) const
const std::string & getNamespace() const
bool getParam(swri::NodeHandle &nh, const std::string name, T &value, const std::string description)