Inviwo 0.9.12-pre
Inviwo documentation
Loading...
Searching...
No Matches
inviwo::Observable< T > Class Template Reference

#include <observer.h>

+ Inheritance diagram for inviwo::Observable< T >:

Public Member Functions

 Observable (const Observable< T > &other)
 
 Observable (Observable< T > &&other) noexcept
 
Observable< T > & operator= (const Observable< T > &other)
 
Observable< T > & operator= (Observable< T > &&other) noexcept
 
void addObserver (T *observer)
 
void removeObserver (T *observer)
 
virtual void startBlockingNotifications () override final
 
virtual void stopBlockingNotifications () override final
 
- Public Member Functions inherited from inviwo::ObservableInterface

Protected Member Functions

template<typename C >
void forEachObserver (C callback)
 
- Protected Member Functions inherited from inviwo::ObservableInterface
void addObservationHelper (Observer *observer)
 
void removeObservationHelper (Observer *observer)
 

Detailed Description

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

Class to support observer pattern.

Example of how to apply it to a simple button.

class ButtonObservable;
class IVW_XXX_API ButtonObserver: public Observer {
public:
friend ButtonObservable;
ButtonObserver() = default
// Override to be notified when the observed button is pressed.
virtual void onButtonPressed(){};
};
class IVW_XXX_API ButtonObservable: public Observable<ButtonObserver> {
protected:
ButtonObservable() = default;
void notifyObserversAboutButtonPressed() {
forEachObserver([](ButtonObserver* o) { o->onButtonPressed(); });
}
};
Definition observer.h:47

Usage:

class Button : public ButtonObservable {
...
void handleButtonPress() {
...
notifyObserversAboutButtonPressed();
...
}
...
};
class MyClass : public ButtonObserver {
public:
MyClass(Button* button) {
button->addObserver(this);
}
...
private:
virtual void onButtonPressed() override {
// Do stuff on button press
};
...
};
See also
Observer
VoidObserver

Constructor & Destructor Documentation

◆ Observable() [1/2]

template<typename T >
inviwo::Observable< T >::Observable ( const Observable< T > & other)

This operation does nothing. We will not touch the observers of other.

◆ Observable() [2/2]

template<typename T >
inviwo::Observable< T >::Observable ( Observable< T > && other)
noexcept

This operation will remove all observers from other and add them to this.

Member Function Documentation

◆ operator=() [1/2]

template<typename T >
Observable< T > & inviwo::Observable< T >::operator= ( const Observable< T > & other)

This operation does nothing. We will not touch the observers of other.

◆ operator=() [2/2]

template<typename T >
Observable< T > & inviwo::Observable< T >::operator= ( Observable< T > && other)
noexcept

This operation will remove all observers of this, and make all observers of other observe this instead.

◆ startBlockingNotifications()

template<typename T >
void inviwo::Observable< T >::startBlockingNotifications ( )
finaloverridevirtual

◆ stopBlockingNotifications()

template<typename T >
void inviwo::Observable< T >::stopBlockingNotifications ( )
finaloverridevirtual

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