#include <observable.h>
Public Member Functions | |
Observable (T *self) | |
Constructor. | |
virtual | ~Observable () |
Destructor. | |
void | addObserver (Observer< T > *observer) |
Adds a new observer to the list of observers. | |
void | deleteObserver (Observer< T > *observer) |
Deletes selected observer from the list of observers. | |
void | cleanObservers () |
Deletes all observers. | |
void | notifyObservers () |
Notifies all stored observers by calling Observer::update() on them. | |
Private Types | |
typedef std::deque< Observer < T > * > | ObserverContainer |
Type of a container to store observers. | |
Private Attributes | |
T * | _self |
Actual object that will be passed to Observer::update() calls. | |
ObserverContainer | _observers |
Stored observers. |
Implements "observer" design pattern.
Usage:
class View: public Observable<View> { private: std::string _name; public: View(std::string name): Observable<View>(this), _name(name) {} ~View() {} std::string getName() {return _name;} };
typedef std::deque<Observer<T> *> Templates::Observable< T >::ObserverContainer [private] |
Type of a container to store observers.
Templates::Observable< T >::Observable | ( | T * | self | ) | [inline] |
virtual Templates::Observable< T >::~Observable | ( | ) | [inline, virtual] |
Destructor.
void Templates::Observable< T >::addObserver | ( | Observer< T > * | observer | ) | [inline] |
void Templates::Observable< T >::deleteObserver | ( | Observer< T > * | observer | ) | [inline] |
Deletes selected observer from the list of observers.
[in] | observer | Observer to be deleted. |
void Templates::Observable< T >::cleanObservers | ( | ) | [inline] |
Deletes all observers.
void Templates::Observable< T >::notifyObservers | ( | ) | [inline] |
T* Templates::Observable< T >::_self [private] |
Actual object that will be passed to Observer::update() calls.
Referenced by Templates::Observable< Camera >::notifyObservers().
ObserverContainer Templates::Observable< T >::_observers [private] |