dart
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
dart::common::Subject Class Reference

The Subject class is a base class for any object that wants to report when it gets destroyed. More...

#include <Subject.hpp>

Inheritance diagram for dart::common::Subject:
Inheritance graph
[legend]

Public Member Functions

virtual ~Subject ()
 Destructor will notify all Observers that it is destructing.
 

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.
 
void removeObserver (Observer *_observer) const
 Remove an Observer from the list of Observers.
 

Protected Attributes

std::set< Observer * > mObservers
 List of current Observers.
 

Friends

class Observer
 

Detailed Description

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.

Member Function Documentation

◆ sendDestructionNotification()

void dart::common::Subject::sendDestructionNotification ( ) const
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.


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