Utility class to observe a value with a user provided callback. More...
#include <observable.hpp>
Public Member Functions | |
observable (const T &t, const std::function< void(T)> &callback) | |
Constructor. More... | |
observable (T &&t, const std::function< void(T)> &callback) | |
Constructor. More... | |
~observable ()=default | |
Destructor. More... | |
bool | callback_enabled () const |
Check if the callback is currently enabled. More... | |
void | callback_enabled (bool is_enabled) |
Enable or disable the callback temporarily. More... | |
operator T const () const | |
Return the observed value. More... | |
operator T () | |
Return the observed value. More... | |
T | value () const |
Return the observed value. More... | |
observable & | operator= (T &&t) |
Update the observed value. More... | |
observable & | operator= (const T &t) |
Update the observed value. More... | |
Protected Member Functions | |
void | set (const T &value) |
void | set (T &&value) |
Utility class to observe a value with a user provided callback.
T | Observed item type |
CallbackT | User defined callback type |
The callback is invoked every time the observed value is updated. The observable callback receives as a parameter the updated observed value. Thread safe.
Definition at line 45 of file observable.hpp.
|
inlineexplicit |
Constructor.
T | initial value for the observed value |
CallbackT | callable object that is invoked every time the value is changed |
Creates a tc::sdk::observable instance.
Definition at line 55 of file observable.hpp.
|
inlineexplicit |
Constructor.
T | initial value for the observed value |
CallbackT | callable object that is invoked every time the value is changed |
Creates a tc::sdk::observable instance.
Definition at line 71 of file observable.hpp.
|
default |
Destructor.
Destructs this.
|
inline |
Check if the callback is currently enabled.
Definition at line 91 of file observable.hpp.
|
inline |
Enable or disable the callback temporarily.
is_enabled | enable or disable callback |
Definition at line 101 of file observable.hpp.
|
inline |
Return the observed value.
Definition at line 111 of file observable.hpp.
|
inline |
|
inline |
|
inline |
Update the observed value.
t | the updated value |
If the parameter value is different from the observed one the callback is invoked.
Definition at line 142 of file observable.hpp.
|
inline |
Update the observed value.
t | the updated value |
If the parameter value is different from the observed one the callback is invoked.
Definition at line 155 of file observable.hpp.