LuciadCPillar 2025.0.11
Loading...
Searching...
No Matches
luciad::Observable< T > Class Template Reference

This class makes it possible to hold and observe a value that can change over time. More...

#include <luciad/utils/Observable.h>

Public Member Functions

 Observable (T initialValue)
 Constructs the observable with an initial value.
virtual ~Observable ()
void addCallback (std::shared_ptr< IInvalidationCallback > callback)
 Adds a callback that is notified when setValue is called.
const T & getValue () const
 Returns the observable value.
void removeCallback (const std::shared_ptr< IInvalidationCallback > &callback)
 Remove the given callback.
void setValue (T value)
 Sets the observable value.

Static Public Member Functions

static std::shared_ptr< Observable< T > > create (T initialValue)
 Creates a new Observable with the given initial value.

Detailed Description

template<typename T>
class luciad::Observable< T >

This class makes it possible to hold and observe a value that can change over time.

Template Parameters
Tthe type to hold
Since
2022.0

Constructor & Destructor Documentation

◆ Observable()

template<typename T>
luciad::Observable< T >::Observable ( T initialValue)
inlineexplicit

Constructs the observable with an initial value.

Parameters
initialValuethe initial value.

◆ ~Observable()

template<typename T>
virtual luciad::Observable< T >::~Observable ( )
inlinevirtual

Member Function Documentation

◆ addCallback()

template<typename T>
void luciad::Observable< T >::addCallback ( std::shared_ptr< IInvalidationCallback > callback)
inline

Adds a callback that is notified when setValue is called.

Parameters
callbacka callback
Exceptions
luciad::InvalidArgumentExceptionwhen the call back is already added.

◆ create()

template<typename T>
std::shared_ptr< Observable< T > > luciad::Observable< T >::create ( T initialValue)
inlinestatic

Creates a new Observable with the given initial value.

Parameters
initialValuethe initial value.

◆ getValue()

template<typename T>
const T & luciad::Observable< T >::getValue ( ) const
inline

Returns the observable value.

Returns
the observable value.

◆ removeCallback()

template<typename T>
void luciad::Observable< T >::removeCallback ( const std::shared_ptr< IInvalidationCallback > & callback)
inline

Remove the given callback.

Parameters
callbacka callback
Exceptions
luciad::InvalidArgumentExceptionwhen the call back is not known.

◆ setValue()

template<typename T>
void luciad::Observable< T >::setValue ( T value)
inline

Sets the observable value.

This triggers a call to the configured callbacks.

Parameters
valuethe new value
Exceptions
luciad::LogicExceptionwhen calling setValue on derived instances for example.