17#include <teiacare/sdk/non_copyable.hpp>
18#include <teiacare/sdk/non_moveable.hpp>
44template <std::equality_comparable T>
58 , _is_callback_enabled{
true}
74 , _is_callback_enabled{
true}
93 std::lock_guard
lock(_mutex);
94 return _is_callback_enabled.load();
103 std::lock_guard
lock(_mutex);
104 _is_callback_enabled.store(is_enabled);
111 operator T
const()
const
131 std::lock_guard
lock(_mutex);
144 set(std::forward<T>(
t));
162 void set(
const T&
value)
164 std::lock_guard
lock(_mutex);
171 if (_is_callback_enabled)
177 std::lock_guard lock(_mutex);
184 if (_is_callback_enabled)
189 mutable std::mutex _mutex;
191 const std::function<void(T)> _callback;
192 std::atomic_bool _is_callback_enabled;
Thread safe, blocking queue.
Utility class to observe a value with a user provided callback.
observable(T &&t, const std::function< void(T)> &callback)
Constructor.
~observable()=default
Destructor.
void callback_enabled(bool is_enabled)
Enable or disable the callback temporarily.
observable(const T &t, const std::function< void(T)> &callback)
Constructor.
T value() const
Return the observed value.
bool callback_enabled() const
Check if the callback is currently enabled.
observable & operator=(T &&t)
Update the observed value.
observable & operator=(const T &t)
Update the observed value.