HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends
tt::observable< T > Class Template Reference

#include <ttauri/observable.hpp>

Public Types

using value_type = T
 
using notifier_type = notifier<void()>
 
using callback_type = typename notifier_type::callback_type
 
using callback_ptr_type = typename notifier_type::callback_ptr_type
 

Public Member Functions

 observable (observable &&other) noexcept
 
observableoperator= (observable &&other) noexcept
 
 observable (observable const &other) noexcept
 
observableoperator= (observable const &other) noexcept
 
 observable () noexcept
 Default construct a observable holding a default constructed value.
 
 observable (value_type const &value) noexcept
 Construct a observable holding value.
 
 operator bool () const noexcept
 Is the internal value true.
 
observableoperator= (value_type const &value) noexcept
 Assign a new value.
 
observableoperator+= (value_type const &value) noexcept
 Inplace add a value.
 
observableoperator-= (value_type const &value) noexcept
 Inplace subtract a value.
 
value_type load () const noexcept
 Load the value.
 
value_type operator* () const noexcept
 Load the value.
 
bool store (value_type const &new_value) noexcept
 Assign a new value.
 
template<typename Callback >
requires (std::is_invocable_v<Callback>)
callback_ptr_type subscribe (Callback &&callback) noexcept
 Subscribe a callback function.
 
callback_ptr_type subscribe (callback_ptr_type const &callback) noexcept
 Subscribe a callback function.
 
void unsubscribe (callback_ptr_type const &callback_ptr) noexcept
 Unsubscribe a callback function.
 
value_type operator- () const noexcept
 Negate and return the value.
 

Friends

class detail::observable_base< value_type >
 
bool operator== (observable const &lhs, observable const &rhs) noexcept
 Compare the value of two observables.
 
bool operator== (observable const &lhs, value_type const &rhs) noexcept
 Compare and observable with a value.
 
bool operator== (value_type const &lhs, observable const &rhs) noexcept
 Compare and observable with a value.
 
auto operator<=> (observable const &lhs, observable const &rhs) noexcept
 Compare the value of two observables.
 
auto operator<=> (observable const &lhs, value_type const &rhs) noexcept
 Compare and observable with a value.
 
auto operator<=> (value_type const &lhs, observable const &rhs) noexcept
 Compare and observable with a value.
 
auto operator+ (observable const &lhs, observable const &rhs) noexcept
 Add the value of two observables.
 
auto operator+ (observable const &lhs, value_type const &rhs) noexcept
 Add the value of observables to a value.
 
auto operator+ (value_type const &lhs, observable const &rhs) noexcept
 Add the value of observables to a value.
 
auto operator- (observable const &lhs, observable const &rhs) noexcept
 Subtract the value of two observables.
 
auto operator- (observable const &lhs, value_type const &rhs) noexcept
 Subtract a value from an observable to a value.
 
auto operator- (value_type const &lhs, observable const &rhs) noexcept
 Subtract an observable value from a value.
 

Detailed Description

template<typename T>
class tt::observable< T >

An observable value.

An observable-value will notify listeners when a value changes. An observable-value can also observe another observable-value.

For widgets this allows changes to values to be reflected on the screen in multiple places. Or values to be written automatically to a configuration file.

Constructor & Destructor Documentation

◆ observable() [1/2]

template<typename T >
tt::observable< T >::observable ( )
inlinenoexcept

Default construct a observable holding a default constructed value.

◆ observable() [2/2]

template<typename T >
tt::observable< T >::observable ( value_type const & value)
inlinenoexcept

Construct a observable holding value.

Parameters
valueThe value to set the internal value to.

Member Function Documentation

◆ load()

template<typename T >
value_type tt::observable< T >::load ( ) const
inlinenoexcept

Load the value.

Loads the internal or observed value.

Returns
The internal or observed value.

◆ operator bool()

template<typename T >
tt::observable< T >::operator bool ( ) const
inlineexplicitnoexcept

Is the internal value true.

◆ operator*()

template<typename T >
value_type tt::observable< T >::operator* ( ) const
inlinenoexcept

Load the value.

Loads the internal or observed value.

Returns
The internal or observed value.

◆ operator+=()

template<typename T >
observable & tt::observable< T >::operator+= ( value_type const & value)
inlinenoexcept

Inplace add a value.

Updates the internal value or the value that is being observed non-atomically.

Parameters
valueThe value to add.
Returns
*this.
Postcondition
Listeners will be notified.

◆ operator-()

template<typename T >
value_type tt::observable< T >::operator- ( ) const
inlinenoexcept

Negate and return the value.

Returns
The negative of the internal or observed value.

◆ operator-=()

template<typename T >
observable & tt::observable< T >::operator-= ( value_type const & value)
inlinenoexcept

Inplace subtract a value.

Updates the internal value or the value that is being observed non-atomically.

Parameters
valueThe value to subtract.
Returns
*this.
Postcondition
Listeners will be notified.

◆ operator=()

template<typename T >
observable & tt::observable< T >::operator= ( value_type const & value)
inlinenoexcept

Assign a new value.

Updates the internal value or the value that is being observed.

Parameters
valueThe value to assign.
Returns
*this.
Postcondition
Listeners will be notified.

◆ store()

template<typename T >
bool tt::observable< T >::store ( value_type const & new_value)
inlinenoexcept

Assign a new value.

Updates the internal value or the value that is being observed.

Parameters
valueThe value to assign.
Returns
*this.
Postcondition
Listeners will be notified.

◆ subscribe() [1/2]

template<typename T >
template<typename Callback >
requires (std::is_invocable_v<Callback>)
callback_ptr_type tt::observable< T >::subscribe ( Callback && callback)
inlinenoexcept

Subscribe a callback function.

The subscribed callback function will be called when the value is modified.

Template Parameters
CallbackA callback-type of the form void().
Parameters
callbackThe callback function to subscribe.
Returns
A std::shared_ptr to the callback function.
Postcondition
A std::weak_ptr to the callback function is retained by the observable. When this pointer is expired the callback will be automatically unsubscribed.

◆ subscribe() [2/2]

template<typename T >
callback_ptr_type tt::observable< T >::subscribe ( callback_ptr_type const & callback)
inlinenoexcept

Subscribe a callback function.

The subscribed callback function will be called when the value is modified.

Parameters
callbackThe callback function to subscribe.
Returns
A std::shared_ptr to the callback function.
Postcondition
A std::weak_ptr to the callback function is retained by the observable. When this pointer is expired the callback will be automatically unsubscribed.

◆ unsubscribe()

template<typename T >
void tt::observable< T >::unsubscribe ( callback_ptr_type const & callback_ptr)
inlinenoexcept

Unsubscribe a callback function.

Parameters
callbackThe callback function to subscribe.

Friends And Related Symbol Documentation

◆ operator+ [1/3]

template<typename T >
auto operator+ ( observable< T > const & lhs,
observable< T > const & rhs )
friend

Add the value of two observables.

Parameters
lhsAn observable-value
rhsAn observable-value
Returns
The sum of the internal or observed value of lhs and rhs.

◆ operator+ [2/3]

template<typename T >
auto operator+ ( observable< T > const & lhs,
value_type const & rhs )
friend

Add the value of observables to a value.

Parameters
lhsAn observable-value
rhsA value
Returns
The sum of the internal or observed value of lhs and rhs.

◆ operator+ [3/3]

template<typename T >
auto operator+ ( value_type const & lhs,
observable< T > const & rhs )
friend

Add the value of observables to a value.

Parameters
lhsA value
rhsAn observable-value
Returns
The sum of lhs with the internal or observed value of rhs.

◆ operator- [1/3]

template<typename T >
auto operator- ( observable< T > const & lhs,
observable< T > const & rhs )
friend

Subtract the value of two observables.

Parameters
lhsAn observable-value
rhsAn observable-value
Returns
The difference between of the internal or observed value of lhs and rhs.

◆ operator- [2/3]

template<typename T >
auto operator- ( observable< T > const & lhs,
value_type const & rhs )
friend

Subtract a value from an observable to a value.

Parameters
lhsAn observable-value
rhsA value
Returns
The different between the internal or observed value of lhs and rhs.

◆ operator- [3/3]

template<typename T >
auto operator- ( value_type const & lhs,
observable< T > const & rhs )
friend

Subtract an observable value from a value.

Parameters
lhsA value
rhsAn observable-value
Returns
The difference between the lhs and the internal or observed value of rhs.

◆ operator<=> [1/3]

template<typename T >
auto operator<=> ( observable< T > const & lhs,
observable< T > const & rhs )
friend

Compare the value of two observables.

Parameters
lhsAn observable-value.
rhsAn observable-value.
Returns
True the comparison result of the internal or observed value of both lhs and rhs.

◆ operator<=> [2/3]

template<typename T >
auto operator<=> ( observable< T > const & lhs,
value_type const & rhs )
friend

Compare and observable with a value.

Parameters
lhsAn observable-value.
rhsA value.
Returns
The comparison result between the internal or observed value of lhs and the rhs.

◆ operator<=> [3/3]

template<typename T >
auto operator<=> ( value_type const & lhs,
observable< T > const & rhs )
friend

Compare and observable with a value.

Parameters
lhsA value.
rhsAn observable-value.
Returns
The comparison result between the lhs and to the internal or observed value of rhs.

◆ operator== [1/3]

template<typename T >
bool operator== ( observable< T > const & lhs,
observable< T > const & rhs )
friend

Compare the value of two observables.

Parameters
lhsAn observable-value.
rhsAn observable-value.
Returns
True if the internal or observed value of both lhs and rhs are equal.

◆ operator== [2/3]

template<typename T >
bool operator== ( observable< T > const & lhs,
value_type const & rhs )
friend

Compare and observable with a value.

Parameters
lhsAn observable-value.
rhsA value.
Returns
True if the internal or observed value of lhs is equal to rhs.

◆ operator== [3/3]

template<typename T >
bool operator== ( value_type const & lhs,
observable< T > const & rhs )
friend

Compare and observable with a value.

Parameters
lhsA value.
rhsAn observable-value.
Returns
True if lhs is equal to the internal or observed value of rhs.

The documentation for this class was generated from the following file: