DART  6.10.1
dart::common::sub_ptr< T > Class Template Reference

sub_ptr is a pointer to a Subject. More...

#include <sub_ptr.hpp>

Inheritance diagram for dart::common::sub_ptr< T >:
dart::common::Observer

Public Member Functions

 sub_ptr ()
 Default constructor. More...
 
 sub_ptr (T *_ptr)
 Alternative constructor. More...
 
 sub_ptr (const sub_ptr &other)
 User defined copy constructor. More...
 
sub_ptroperator= (const sub_ptr &_sp)
 Change the Subject of this sub_ptr. More...
 
sub_ptroperator= (T *_ptr)
 Change the Subject of this sub_ptr. More...
 
 operator T* () const
 Implicit conversion to pointer type. More...
 
T & operator* () const
 Dereferencing operator. More...
 
T * operator-> () const
 Dereferencing operation. More...
 
T * get () const
 Get the Subject of this sub_ptr. More...
 
void set (T *_ptr)
 Set the subject of this sub_ptr. More...
 
bool valid ()
 True if and only if this sub_ptr still points to a valid Subject. More...
 

Protected Member Functions

void handleDestructionNotification (const Subject *_subject) override
 Called by receiveDestructionNotification(). More...
 
void receiveDestructionNotification (const Subject *_subject)
 Called whenever a Subject is destroyed (or sends out a destruction notification). More...
 
void addSubject (const Subject *_subject)
 Add a Subject for this Observer. More...
 
void removeSubject (const Subject *_subject)
 Remove a Subject from this Observer. More...
 
void removeAllSubjects ()
 Remove all Subjects from this Observer. More...
 

Protected Attributes

T * mT
 Store the pointer to the full object. More...
 
SubjectmSubjectBase
 Store the pointer to the virtual Subject base. More...
 
std::set< const Subject * > mSubjects
 List of current Subjects for this Observer. More...
 

Detailed Description

template<class T>
class dart::common::sub_ptr< T >

sub_ptr is a pointer to a Subject.

It can be used as a pointer to any class that publicly inherits Subject. If the instance that it is pointing to is ever destroyed, the sub_ptr class will start pointing to a nullptr. You can check the return of sub_ptr::valid() to see if the pointer is still valid.

Constructor & Destructor Documentation

◆ sub_ptr() [1/3]

template<class T >
dart::common::sub_ptr< T >::sub_ptr

Default constructor.

◆ sub_ptr() [2/3]

template<class T >
dart::common::sub_ptr< T >::sub_ptr ( T *  _ptr)

Alternative constructor.

_ptr must be a valid pointer when passed to this constructor.

◆ sub_ptr() [3/3]

template<class T >
dart::common::sub_ptr< T >::sub_ptr ( const sub_ptr< T > &  other)

User defined copy constructor.

Member Function Documentation

◆ addSubject()

void dart::common::Observer::addSubject ( const Subject _subject)
protectedinherited

Add a Subject for this Observer.

◆ get()

template<class T >
T * dart::common::sub_ptr< T >::get

Get the Subject of this sub_ptr.

◆ handleDestructionNotification()

template<class T >
void dart::common::sub_ptr< T >::handleDestructionNotification ( const Subject _subject)
overrideprotectedvirtual

Called by receiveDestructionNotification().

Override this function to customize your class's response to destruction notifications.

Reimplemented from dart::common::Observer.

◆ operator T*()

template<class T >
dart::common::sub_ptr< T >::operator T*

Implicit conversion to pointer type.

◆ operator*()

template<class T >
T & dart::common::sub_ptr< T >::operator*

Dereferencing operator.

◆ operator->()

template<class T >
T * dart::common::sub_ptr< T >::operator->

Dereferencing operation.

◆ operator=() [1/2]

template<class T >
sub_ptr< T > & dart::common::sub_ptr< T >::operator= ( const sub_ptr< T > &  _sp)

Change the Subject of this sub_ptr.

◆ operator=() [2/2]

template<class T >
sub_ptr< T > & dart::common::sub_ptr< T >::operator= ( T *  _ptr)

Change the Subject of this sub_ptr.

◆ receiveDestructionNotification()

void dart::common::Observer::receiveDestructionNotification ( const Subject _subject)
protectedinherited

Called whenever a Subject is destroyed (or sends out a destruction notification).

Override handleDestructionNotification() in order to customize your class's response to destruction notifications.

◆ removeAllSubjects()

void dart::common::Observer::removeAllSubjects ( )
protectedinherited

Remove all Subjects from this Observer.

◆ removeSubject()

void dart::common::Observer::removeSubject ( const Subject _subject)
protectedinherited

Remove a Subject from this Observer.

◆ set()

template<class T >
void dart::common::sub_ptr< T >::set ( T *  _ptr)

Set the subject of this sub_ptr.

◆ valid()

template<class T >
bool dart::common::sub_ptr< T >::valid

True if and only if this sub_ptr still points to a valid Subject.

Member Data Documentation

◆ mSubjectBase

template<class T >
Subject* dart::common::sub_ptr< T >::mSubjectBase
protected

Store the pointer to the virtual Subject base.

◆ mSubjects

std::set<const Subject*> dart::common::Observer::mSubjects
protectedinherited

List of current Subjects for this Observer.

◆ mT

template<class T >
T* dart::common::sub_ptr< T >::mT
protected

Store the pointer to the full object.