|
HikoGUI
A low latency retained GUI
|
#include <hikogui/observable.hpp>
Public Types | |
| using | value_type = T |
| using | impl_type = detail::observable_impl<value_type> |
| using | proxy_type = impl_type::proxy_type |
| using | const_proxy_type = impl_type::const_proxy_type |
| using | reference = value_type& |
| using | const_reference = value_type const& |
| using | notifier_type = notifier<void(value_type)> |
| using | token_type = notifier_type::token_type |
| using | awaiter_type = notifier_type::awaiter_type |
Public Member Functions | |
| observable () noexcept | |
| Construct an observable. | |
| observable (observable const &other) noexcept | |
| Construct an observable and chain it to another. | |
| observable & | operator= (observable const &other) noexcept |
| Chain with another observable. | |
| token_type | subscribe (callback_flags flags, std::invocable< value_type > auto &&callback) noexcept |
| token_type | subscribe (std::invocable< value_type > auto &&callback) noexcept |
| awaiter_type | operator co_await () const noexcept |
| const_proxy_type | const_proxy () const noexcept |
| proxy a constant reference to the shared value. | |
| proxy_type | proxy () const noexcept |
| proxy a constant reference to the shared value. | |
| proxy_type | proxy () noexcept |
| proxy a writable reference to the shared-value. | |
| const_reference | operator* () const noexcept |
| Dereference to the value. | |
| const_proxy_type | operator-> () const noexcept |
| Member select. | |
| observable (std::convertible_to< value_type > auto &&value) noexcept | |
| Construct an observable with its value set. | |
| observable & | operator= (std::convertible_to< value_type > auto &&value) noexcept |
| Assign a new value. | |
| auto | operator++ () noexcept |
| Pre increment. | |
| auto | operator-- () noexcept |
| Pre decrement. | |
| auto | operator++ (int) noexcept |
| Post increment. | |
| auto | operator-- (int) noexcept |
| Post decrement. | |
| auto | operator+= (auto &&rhs) noexcept |
| Inplace add. | |
| auto | operator-= (auto &&rhs) noexcept |
| Inplace subtract. | |
| auto | operator*= (auto &&rhs) noexcept |
| Inplace multiply. | |
| auto | operator/= (auto &&rhs) noexcept |
| Inplace divide. | |
| auto | operator%= (auto &&rhs) noexcept |
| Inplace remainder. | |
| auto | operator&= (auto &&rhs) noexcept |
| Inplace bitwise and. | |
| auto | operator|= (auto &&rhs) noexcept |
| Inplace bitwise or. | |
| auto | operator^= (auto &&rhs) noexcept |
| Inplace bitwise xor. | |
| auto | operator<<= (auto &&rhs) noexcept |
| Inplace shift left. | |
| auto | operator>>= (auto &&rhs) noexcept |
| Inplace shift right. | |
An observable value.
Typically owners of an observable will subscribe a callback that will be called when the observed value has changed.
Multiple observables will be able to share the same value by assigning observables to each other, as shown in the example below. The callback subscribtion on each observable will not change with these assignments.
Access to the value is done through either a proxy or const-proxy. Only one proxy xor multiple const-proxies can be outstanding at a time. This is checked on debug builds.
The const-proxy is cheap and possibly completely optimized away for accessing the value read-only. The (non-const) proxy may be quite expensive as it makes a copy of the value to compare against to determine if change-notification is needed.
For this reason almost all operators of observable will work on const-proxies.
If you want to modify the value, or make multiple modifications you may explicitly use the proxy() function to get a proxy object and dereference it.
| T | The type of the value to be observed. |
|
inlinenoexcept |
Construct an observable.
The observer is created with a value that is default constructed.
|
inlinenoexcept |
Construct an observable and chain it to another.
The new observable will share a value with the other observable.
| other | The other observable to share the value with. |
|
inlinenoexcept |
Construct an observable with its value set.
| value | The value to assign to the shared-value. |
|
inlinenoexcept |
proxy a constant reference to the shared value.
In reality the reference is a proxy object which makes available operations to be used with the shared value. This proxy object will make sure any state is done atomically.
|
inlinenoexcept |
Inplace remainder.
Short for *lhs.proxy() %= rhs
| rhs | The right hand side value. |
|
inlinenoexcept |
Inplace bitwise and.
Short for *lhs.proxy() &= rhs
| rhs | The right hand side value. |
|
inlinenoexcept |
Dereference to the value.
|
inlinenoexcept |
Inplace multiply.
Short for *lhs.proxy() *= rhs
| rhs | The right hand side value. |
|
inlinenoexcept |
Pre increment.
Short for ++*lhs.proxy()
| rhs | The right hand side value. |
|
inlinenoexcept |
Post increment.
Short for (*lhs.proxy())++
| rhs | The right hand side value. |
|
inlinenoexcept |
Inplace add.
Short for *lhs.proxy() += rhs
| rhs | The right hand side value. |
|
inlinenoexcept |
Pre decrement.
Short for --*lhs.proxy()
| rhs | The right hand side value. |
|
inlinenoexcept |
Post decrement.
Short for (*lhs.proxy())--
| rhs | The right hand side value. |
|
inlinenoexcept |
Inplace subtract.
Short for *lhs.proxy() -= rhs
| rhs | The right hand side value. |
|
inlinenoexcept |
Member select.
Member selection is done recursive through a read-only proxy object.
|
inlinenoexcept |
Inplace divide.
Short for *lhs.proxy() /= rhs
| rhs | The right hand side value. |
|
inlinenoexcept |
Inplace shift left.
Short for *lhs.proxy() <<= rhs
| rhs | The right hand side value. |
|
inlinenoexcept |
Chain with another observable.
Replace the current shared value, with the value of the other observer. This means the other observers that share the current value will also be reseated with the new value.
| other | The other observable to share the value with. |
|
inlinenoexcept |
Assign a new value.
| value | The value to assign to the shared-value. |
|
inlinenoexcept |
Inplace shift right.
Short for *lhs.proxy() >>= rhs
| rhs | The right hand side value. |
|
inlinenoexcept |
Inplace bitwise xor.
Short for *lhs.proxy() ^= rhs
| rhs | The right hand side value. |
|
inlinenoexcept |
Inplace bitwise or.
Short for *lhs.proxy() |= rhs
| rhs | The right hand side value. |
|
inlinenoexcept |
proxy a constant reference to the shared value.
In reality the reference is a proxy object which makes available operations to be used with the shared value. This proxy object will make sure any state is done atomically.
|
inlinenoexcept |
proxy a writable reference to the shared-value.
In reality the reference is a proxy object which makes available operations to be used with the shared-value. This proxy object will make sure any state is done atomically and that subscribers are notified when the proxy's lifetime has ended.