DART  6.10.1
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:
dart::dynamics::DegreeOfFreedom dart::dynamics::Entity dart::dynamics::HierarchicalIK dart::dynamics::InverseKinematics dart::dynamics::InverseKinematics::ErrorMethod dart::dynamics::InverseKinematics::GradientMethod dart::dynamics::Joint dart::dynamics::MetaSkeleton dart::dynamics::Node dart::dynamics::PointMass dart::dynamics::Shape dart::gui::osg::DefaultEventHandler dart::gui::osg::DragAndDrop dart::gui::osg::MouseEventHandler dart::gui::osg::Viewer dart::simulation::World

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
 

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.

Constructor & Destructor Documentation

◆ ~Subject()

dart::common::Subject::~Subject ( )
virtual

Destructor will notify all Observers that it is destructing.

Member Function Documentation

◆ addObserver()

void dart::common::Subject::addObserver ( Observer _observer) const
protected

Add an Observer to the list of Observers.

◆ removeObserver()

void dart::common::Subject::removeObserver ( Observer _observer) const
protected

Remove an Observer from the list of Observers.

◆ 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.

Friends And Related Function Documentation

◆ Observer

friend class Observer
friend

Member Data Documentation

◆ mObservers

std::set<Observer*> dart::common::Subject::mObservers
mutableprotected

List of current Observers.