Observable Reference
Generic observable objects for C++
Public Member Functions | List of all members
observable::value< ValueType, EnclosingType > Class Template Reference

Description

template<typename ValueType, typename EnclosingType>
class observable::value< ValueType, EnclosingType >

Value specialization that can be used inside a class, as a member, to prevent external code from calling set(), but still allow anyone to subscribe.

See also
value<ValueType>

This specialization is exactly the same as the main value specialization, but its setters are only accessible from inside the EnclosingType.

Template Parameters
ValueTypeThe value-type that will be stored inside the observable.
EnclosingTypeA type that will have access to the value's setters.

Public Member Functions

 value ()=default
 
- Public Member Functions inherited from observable::value< ValueType >
 value ()=default
 Create a default-constructed observable value. More...
 
 value (ValueType initial_value) noexcept(std::is_nothrow_move_constructible< ValueType >::value)
 Create an initialized observable value. More...
 
template<typename EqualityComparator >
 value (ValueType initial_value, EqualityComparator equal) noexcept(std::is_nothrow_move_constructible< ValueType >::value &&std::is_nothrow_move_constructible< EqualityComparator >::value)
 Create an initialized observable value. More...
 
template<typename UpdaterType >
 value (std::unique_ptr< UpdaterType > &&ud)
 Create an initialized value that will be updated by the provided value_updater. More...
 
 operator ValueType const & () const noexcept
 Convert the observable value to its stored value type. More...
 
auto get () const noexcept -> ValueType const &
 Retrieve the stored value. More...
 
template<typename Callable >
auto subscribe (Callable &&observer) const
 Subscribe to changes to the observable value. More...
 
template<typename Callable >
auto subscribe_and_call (Callable &&observer) const
 Subscribe to changes to the observable value and also call the observer callback immediately with the current value. More...
 
void set (ValueType new_value)
 Set a new value, possibly notifying any subscribed observers. More...
 
auto operator= (ValueType new_value) -> value &
 Set a new value. More...
 
 ~value ()
 Destructor. More...
 
 value (value< ValueType > const &)=delete
 Observable values are not copy-constructible. More...
 
auto operator= (value< ValueType > const &) -> value< ValueType > &=delete
 Observable values are not copy-assignable. More...
 
template<typename = std::enable_if_t<std::is_move_constructible<ValueType>::value>>
 value (value< ValueType > &&other) noexcept(std::is_nothrow_move_constructible< ValueType >::value)
 Observable values are move-constructible. More...
 
template<typename = std::enable_if_t<std::is_move_assignable<ValueType>::value>>
auto operator= (value< ValueType > &&other) noexcept(std::is_nothrow_move_assignable< ValueType >::value) -> value< ValueType > &
 Observable values are move-assignable. More...
 

Additional Inherited Members

- Public Types inherited from observable::value< ValueType >
using value_type = ValueType
 The observable value's stored value type. More...
 
- Public Attributes inherited from observable::value< ValueType >
subject< void(value< ValueType > &), value< ValueType > > moved
 Subject notified after the value has been moved. More...
 
subject< void(), value< ValueType > > destroyed
 Subject notified before the value is destroyed. More...
 

Constructor & Destructor Documentation

◆ value()

template<typename ValueType , typename EnclosingType >
observable::value< ValueType, EnclosingType >::value ( )
default