LuciadCPillar 2024.0.08
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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. More...
 
virtual ~Observable ()
 
void addCallback (std::shared_ptr< IInvalidationCallback > callback)
 Adds a callback that is notified when setValue is called. More...
 
const T & getValue () const
 Returns the observable value. More...
 
void removeCallback (const std::shared_ptr< IInvalidationCallback > &callback)
 Remove the given callback. More...
 
void setValue (T value)
 Sets the observable value. More...
 

Static Public Member Functions

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

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 ( 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 >
static std::shared_ptr< Observable< T > > luciad::Observable< T >::create ( 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 ( 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.