DART
6.10.1
|
The Subject class is a base class for any object that wants to report when it gets destroyed. More...
#include <Subject.hpp>
Public Member Functions | |
virtual | ~Subject () |
Destructor will notify all Observers that it is destructing. More... | |
Protected Member Functions | |
void | sendDestructionNotification () const |
Send a destruction notification to all Observers. More... | |
void | addObserver (Observer *_observer) const |
Add an Observer to the list of Observers. More... | |
void | removeObserver (Observer *_observer) const |
Remove an Observer from the list of Observers. More... | |
Protected Attributes | |
std::set< Observer * > | mObservers |
List of current Observers. More... | |
Friends | |
class | Observer |
The Subject class is a base class for any object that wants to report when it gets destroyed.
This is useful for complex frameworks in which it is difficult or impossible to know when an object or resource might destroyed by some other part of the code, or when special cleanup might be needed upon the destruction of an object. Simply by inheriting the Subject class, any class can have the destruction notification feature.
Note that the Subject class should ALWAYS be virtually inherited. No other special considerations are needed when virtually inheriting the Subject class.
dart::sub_ptr is a templated smart pointer that will change itself into a nullptr when its Subject is destroyed. It offers one of the easiest ways to take advantage of the Subject/Observer pattern.
|
virtual |
Destructor will notify all Observers that it is destructing.
|
protected |
Add an Observer to the list of Observers.
|
protected |
Remove an Observer from the list of Observers.
|
protected |
Send a destruction notification to all Observers.
This will cause all Observers to behave as if this Subject has been permanently deleted, so it should only be called when that behavior is desired.
|
friend |
|
mutableprotected |
List of current Observers.