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. | |
| observable (T &&t, const std::function< void(T)> &callback) | |
| Constructor. | |
| ~observable ()=default | |
| Destructor. | |
| bool | callback_enabled () const |
| Check if the callback is currently enabled. | |
| void | callback_enabled (bool is_enabled) |
| Enable or disable the callback temporarily. | |
| operator T const () const | |
| Return the observed value. | |
| operator T () | |
| Return the observed value. | |
| T | value () const |
| Return the observed value. | |
| observable & | operator= (T &&t) |
| Update the observed value. | |
| observable & | operator= (const T &t) |
| Update the observed value. | |
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.
|
inlineprotected |
Definition at line 162 of file observable.hpp.
|
inlineprotected |
Definition at line 175 of file observable.hpp.