Observable Reference
Generic observable objects for C++
Modules | Classes | Macros | Functions
Observable

Top-level observable classes. More...

Modules

 Expressions
 Everything related to observable expressions.
 
 Private
 These classes are internal to the library, they may change at any time.
 

Classes

class  observable::updater
 Update all observable values that were associated with an updater instance. More...
 
class  observable::subject< void(Args ...)>
 Store observers and provide a way to notify them when events occur. More...
 
class  observable::subject< ObserverType, EnclosingType >
 Subject specialization that can be used inside a class, as a member, to prevent external code from calling notify(), but still allow anyone to subscribe. More...
 
class  observable::infinite_subscription
 Infinite subscription that will not unsubscribe the associated observer when destroyed. More...
 
class  observable::unique_subscription
 Unsubscribe the associated observer when destroyed. More...
 
class  observable::shared_subscription
 Unsubscribe the associated observer when the last instance of the class is destroyed. More...
 
class  observable::value< ValueType >
 Get notified when a value-type changes. More...
 
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. More...
 
class  observable::value_updater< ValueType >
 Interface used to update a value. More...
 

Macros

#define OBSERVABLE_PROPERTIES(EnclosingType)   using Observable_Property_EnclosingType_ = EnclosingType;
 Macro that enables observable properties for a class. More...
 
#define observable_property   typename ::observable::detail::prop_<Observable_Property_EnclosingType_>::type
 Declare an observable property member of a class. More...
 

Functions

template<typename ... T>
auto observable::observe (value< T ... > &val)
 Observe changes to a single value with automatic synchronization. More...
 
template<typename ValueType >
auto observable::observe (expr::expression_node< ValueType > &&root)
 Observe changes to an expression tree with automatic evaluation. More...
 
template<typename UpdaterType , typename ... T>
auto observable::observe (UpdaterType &ud, value< T ... > &val)
 Observe changes to a single value with manual synchronization. More...
 
template<typename UpdaterType , typename ValueType >
auto observable::observe (UpdaterType &ud, expr::expression_node< ValueType > &&root)
 Observe changes to an expression tree with manual synchronization. More...
 

Detailed Description

Top-level observable classes.

Macro Definition Documentation

◆ OBSERVABLE_PROPERTIES

#define OBSERVABLE_PROPERTIES (   EnclosingType)    using Observable_Property_EnclosingType_ = EnclosingType;

Macro that enables observable properties for a class.

You must use this macro inside a class that will have observable_property members.

To enable observable properties, just use the macro, with the class type as a parameter before declaring the first observable property member.

Example:

class MyClass
{
    OBSERVABLE_PROPERTIES(MyClass)

public:
    observable_property<int> my_val;
};

◆ observable_property

#define observable_property   typename ::observable::detail::prop_<Observable_Property_EnclosingType_>::type

Declare an observable property member of a class.

Note
You must use the OBSERVABLE_PROPERTIES macro before declaring any observable_property members inside a class.

The macro expands to an observable value that takes two template parameters: ValueType and EqualityComparator.

The value's setters will only be accessible from inside the class passed as a parameter to the OBSERVABLE_PROPERTIES macro.

See also
observable::value<ValueType, EqualityComparator>
observable::value<ValueType, EqualityComparator, EnclosingType>

Function Documentation

◆ observe() [1/4]

template<typename ... T>
auto observable::observe ( value< T ... > &  val)
inline

Observe changes to a single value with automatic synchronization.

Returns an observable value that is kept in-sync with the provided value.

Parameters
[in]valValue to observe.
Returns
An observable value that automatically mirrors the provided parameter.

◆ observe() [2/4]

template<typename ValueType >
auto observable::observe ( expr::expression_node< ValueType > &&  root)
inline

Observe changes to an expression tree with automatic evaluation.

Returns a value that is updated whenever the provided expression tree changes.

Parameters
[in]rootExpression tree to observe.
Returns
An observable value that is automatically updated when the provided expression tree changes.

◆ observe() [3/4]

template<typename UpdaterType , typename ... T>
auto observable::observe ( UpdaterType &  ud,
value< T ... > &  val 
)
inline

Observe changes to a single value with manual synchronization.

Returns an observable value that is synchronized with the provided value whenever the update() method is called on the provided updater.

Parameters
[in]udAn updater instance to be used for manually synchronizing the returned value to the provided value.
[in]valA value to synchronize with the returned value.
Returns
An observable value that is manually synchronized to the provided value.

◆ observe() [4/4]

template<typename UpdaterType , typename ValueType >
auto observable::observe ( UpdaterType &  ud,
expr::expression_node< ValueType > &&  root 
)
inline

Observe changes to an expression tree with manual synchronization.

Returns an observable value that is updated when the update() method is called on the provided updater.

Note
The expression tree will only be evaluated if there have been changes since the last update() call.
Parameters
[in]udAn updater instance to be used for manually updating the returned value with the expression tree.
[in]rootAn expression tree to be used for updating the returned value.
Returns
An observable value that is updated from the provided expression.