HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Data Structures | Public Types | Public Member Functions | Data Fields
hi::v1::observer< T > Class Template Reference

#include <hikogui/observer/observer_intf.hpp>

Data Structures

class  proxy_type
 A proxy object of the observer. More...
 

Public Types

using value_type = T
 
using notifier_type = notifier<void(value_type)>
 
using callback_type = notifier_type::callback_type
 
using awaiter_type = notifier_type::awaiter_type
 
using path_type = observable_msg::path_type
 
using const_reference = value_type const &
 
using pointer = proxy_type
 
using const_pointer = value_type const *
 

Public Member Functions

template<forward_of< std::shared_ptr< hi::observed_base > > Observed>
 observer (Observed &&observed_base) noexcept
 Create an observer from an observed_base.
 
constexpr observer () noexcept
 Create a observer linked to an anonymous default initialized observed_base-value.
 
template<std::convertible_to< value_type > Value>
constexpr observer (Value &&value) noexcept
 Create a observer linked to an anonymous observed_base-value.
 
constexpr observer (observer const &other) noexcept
 Copy construct.
 
constexpr observer (observer &&other) noexcept
 Move construct.
 
constexpr observeroperator= (observer const &other) noexcept
 Copy assign.
 
constexpr observeroperator= (observer &&other) noexcept
 Move assign.
 
void reset () noexcept
 Reset the observer.
 
const_pointer get () const noexcept
 Read the observed_base value.
 
pointer get () noexcept
 Make a copy of the observed_base value for modification.
 
template<forward_of< void(value_type)> Func>
callback< void(value_type)> subscribe (Func &&func, callback_flags flags=callback_flags::synchronous) noexcept
 Subscribe a callback to this observer.
 
awaiter_type operator co_await () const noexcept
 
auto sub (auto const &index) const noexcept
 Create a sub-observer by indexing into the value.
 
template<fixed_string Name>
auto sub () const noexcept
 Create a sub-observer by selecting a member-variable of the value.
 
template<typename Rhs >
requires requires (value_type &a, Rhs &&b) { a = std::forward<Rhs>(b); }
observeroperator= (Rhs &&rhs) noexcept
 Assign a new value to the observed_base value.
 
const_reference operator* () const noexcept
 Get the value being observed_base.
 
const_pointer operator& () const noexcept
 
const_pointer operator-> () const noexcept
 Constant pointer-to-member of the value being observed_base.
 
pointer operator-> () noexcept
 Constant pointer-to-member of the value being observed_base.
 
 X (++) X(--) X(++) X(--) X(+
 
template<forward_of< observed_type > ObservedBase, forward_of< path_type > Path, forward_of< void *(void *)> Converter>
 observer (ObservedBase &&observed_base, Path &&path, Converter &&converter) noexcept
 Construct an observer from an observed_base.
 
void notify () const noexcept
 
value_type * convert (void *base) const noexcept
 
value_type constconvert (void const *base) const noexcept
 
void update_state_callback () noexcept
 

Data Fields

observed_type _observed = {}
 
path_type _path = {}
 
std::function< void *(void *) _convert ) = {}
 
notifier_type _notifier
 
value_type _debug_value
 

Detailed Description

template<typename T>
class hi::v1::observer< T >

A observer pointing to the whole or part of a observed_base.

A observer will point to a observed_base that was created, or possibly an anonymous observed_base, which is created when a observer is created as empty.

Template Parameters
TThe type of observer.

Constructor & Destructor Documentation

◆ observer() [1/6]

template<typename T >
template<forward_of< std::shared_ptr< hi::observed_base > > Observed>
hi::v1::observer< T >::observer ( Observed && observed_base)
inlinenoexcept

Create an observer from an observed_base.

Parameters
observed_baseThe observed_base which will be observed_base by this observer.

◆ observer() [2/6]

template<typename T >
constexpr hi::v1::observer< T >::observer ( )
inlineexplicitconstexprnoexcept

Create a observer linked to an anonymous default initialized observed_base-value.

Note
marked 'explicit' so that accidental assignment with {} is not allowed.

◆ observer() [3/6]

template<typename T >
template<std::convertible_to< value_type > Value>
constexpr hi::v1::observer< T >::observer ( Value && value)
inlineconstexprnoexcept

Create a observer linked to an anonymous observed_base-value.

◆ observer() [4/6]

template<typename T >
constexpr hi::v1::observer< T >::observer ( observer< T > const & other)
inlineconstexprnoexcept

Copy construct.

Note
callback subscriptions are not copied.
Parameters
otherThe other observer.

◆ observer() [5/6]

template<typename T >
constexpr hi::v1::observer< T >::observer ( observer< T > && other)
inlineconstexprnoexcept

Move construct.

Note
callback subscriptions are not copied.
Parameters
otherThe other observer.

◆ observer() [6/6]

template<typename T >
template<forward_of< observed_type > ObservedBase, forward_of< path_type > Path, forward_of< void *(void *)> Converter>
hi::v1::observer< T >::observer ( ObservedBase && observed_base,
Path && path,
Converter && converter )
inlinenoexcept

Construct an observer from an observed_base.

Member Function Documentation

◆ get() [1/2]

template<typename T >
const_pointer hi::v1::observer< T >::get ( ) const
inlinenoexcept

Read the observed_base value.

Returns
A const-proxy object used to access the data being observed_base.

◆ get() [2/2]

template<typename T >
pointer hi::v1::observer< T >::get ( )
inlinenoexcept

Make a copy of the observed_base value for modification.

Returns
A proxy object used to modify the data being observed_base.

◆ operator*()

template<typename T >
const_reference hi::v1::observer< T >::operator* ( ) const
inlinenoexcept

Get the value being observed_base.

◆ operator->() [1/2]

template<typename T >
const_pointer hi::v1::observer< T >::operator-> ( ) const
inlinenoexcept

Constant pointer-to-member of the value being observed_base.

◆ operator->() [2/2]

template<typename T >
pointer hi::v1::observer< T >::operator-> ( )
inlinenoexcept

Constant pointer-to-member of the value being observed_base.

◆ operator=() [1/3]

template<typename T >
constexpr observer & hi::v1::observer< T >::operator= ( observer< T > && other)
inlineconstexprnoexcept

Move assign.

Note
Callback subscriptions remain unchanged and are not moved.
The other shared observer will be attached to the anonymous state.
Parameters
otherThe other observer.
Returns
this

◆ operator=() [2/3]

template<typename T >
constexpr observer & hi::v1::observer< T >::operator= ( observer< T > const & other)
inlineconstexprnoexcept

Copy assign.

Note
callback subscriptions remain unchanged and are not copied.
Parameters
otherThe other observer.
Returns
this

◆ operator=() [3/3]

template<typename T >
template<typename Rhs >
requires requires (value_type &a, Rhs &&b) { a = std::forward<Rhs>(b); }
observer & hi::v1::observer< T >::operator= ( Rhs && rhs)
inlinenoexcept

Assign a new value to the observed_base value.

◆ reset()

template<typename T >
void hi::v1::observer< T >::reset ( )
inlinenoexcept

Reset the observer.

This will link the observer with an anonymous observed_base with a default initialized value.

◆ sub() [1/2]

template<typename T >
template<fixed_string Name>
auto hi::v1::observer< T >::sub ( ) const
inlinenoexcept

Create a sub-observer by selecting a member-variable of the value.

Note
This function requires the hi::selector type-trait to be implemented for value_type.
Template Parameters
NameThe name of the member-variable of value.
Returns
A new sub-observer which monitors the member of value.

◆ sub() [2/2]

template<typename T >
auto hi::v1::observer< T >::sub ( auto const & index) const
inlinenoexcept

Create a sub-observer by indexing into the value.

Parameters
indexThe index into the value being observed_base.
Returns
A new sub-observer which monitors the selected sub-value.

◆ subscribe()

template<typename T >
template<forward_of< void(value_type)> Func>
callback< void(value_type)> hi::v1::observer< T >::subscribe ( Func && func,
callback_flags flags = callback_flags::synchronous )
inlinenoexcept

Subscribe a callback to this observer.

Parameters
flagsThe callback flags on how to call the function.
functionThe function used as callback in the form void()
Returns
A callback-token used to extend the lifetime of the callback function.

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