1 #ifndef _ASTRA_ROS_PARAMETER_HPP_
2 #define _ASTRA_ROS_PARAMETER_HPP_
5 #include <boost/optional.hpp>
20 typedef std::function<bool (
const T &value,
const T &previous)> OnChange;
32 bool set(
const T &value) noexcept
34 std::lock_guard<std::mutex> lock(mutex_);
38 if ((*on_change_)(value, value_))
53 const T &get()
const noexcept
55 std::lock_guard<std::mutex> lock(mutex_);
59 void setOnChangeHandler(
const boost::optional<OnChange> &on_change)
61 on_change_ = on_change;
64 const boost::optional<OnChange> &getOnChangeHandler()
const
70 mutable std::mutex mutex_;
73 boost::optional<OnChange> on_change_;
88 typedef typename ParameterImpl<T>::ValueType ValueType;
89 typedef typename ParameterImpl<T>::OnChange OnChange;
112 return impl_->set(value);
137 impl_->setOnChangeHandler(on_change);
143 template<
typename F,
typename... Args>
155 return impl_->getOnChangeHandler();
161 template<
typename F,
typename... Args>
162 static OnChange
bind(F &&f, Args &&...args)
164 return OnChange(std::bind(f, args..., std::placeholders::_1, std::placeholders::_2));
168 std::shared_ptr<ParameterImpl<T>> impl_;