30 #ifndef REGISTERED_PARAM_H 31 #define REGISTERED_PARAM_H 36 #include <type_traits> 37 #include <boost/function.hpp> 38 #include <dynamic_reconfigure/ParamDescription.h> 45 RegisteredParam(
const std::string &name,
const std::string &description, T min_value,
46 T max_value, std::map<std::string, T> enum_dictionary = {},
47 const std::string &enum_description =
"",
const std::string &group =
"")
67 if (std::is_same<T, int>::value)
71 else if (std::is_same<T, double>::value)
75 else if (std::is_same<T, bool>::value)
79 else if (std::is_same<T, std::string>::value)
83 throw std::runtime_error(
"Unexpected type for param " +
name_);
91 if (std::is_same<T, std::string>::value)
93 return "'" + ss.str() +
"'";
100 dynamic_reconfigure::ParamDescription p;
115 std::stringstream ret;
122 ret <<
makeConst(it->first, it->second,
"");
125 ret <<
", " <<
makeConst(it->first, it->second,
"");
134 std::string
makeConst(
const std::string &name, T value,
const std::string &desc)
const 136 std::stringstream ret;
139 ret <<
"'srcline': 0, ";
141 ret <<
"'description': '" << desc <<
"', ";
142 ret <<
"'srcfile': '/does/this/really/matter.cfg', ";
144 ret <<
"'cconsttype': 'const " <<
getTypeName() <<
"', ";
148 ret <<
"'name': '" << name <<
"'";
164 template <
typename T>
169 T min_value, T max_value, T *variable,
170 boost::function<
void(T value)> callback = {},
171 std::map<std::string, T> enum_dictionary = {},
172 const std::string &enum_description =
"",
const std::string &group =
"")
174 enum_description, group)
175 , variable_(variable)
176 , callback_(callback)
186 *variable_ = new_value;
187 if (!callback_.empty())
188 callback_(new_value);
196 template <
typename T>
201 T max_value, T current_value, boost::function<
void(T value)> callback,
202 std::map<std::string, T> enum_dictionary = {},
203 const std::string &enum_description =
"",
204 const std::string &group =
"")
206 enum_description, group)
207 , current_value_(current_value)
208 , callback_(callback)
214 return current_value_;
219 callback_(new_value);
220 current_value_ = new_value;
231 #endif // REGISTERED_PARAM_H