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
virtual void onButtonPressed(){};
};
class IVW_XXX_API ButtonObservable: public Observable<ButtonObserver> {
protected:
ButtonObservable() = default;
void notifyObserversAboutButtonPressed() {
forEachObserver([](ButtonObserver* o) { o->onButtonPressed(); });
}
};
Usage:
class Button : public ButtonObservable {
...
void handleButtonPress() {
...
notifyObserversAboutButtonPressed();
...
}
...
};
class MyClass : public ButtonObserver {
public:
MyClass(Button* button) {
button->addObserver(this);
}
...
private:
virtual void onButtonPressed() override {
};
...
};
- See also
- Observer
-
VoidObserver