SafePtr< T > Class Template Reference

Smart pointer used to automatically NULLify when the subject is deleted. More...

#include <SafePtr.h>

Inheritance diagram for SafePtr< T >:

Inheritance graph

List of all members.

Public Member Functions

 SafePtr ()
 SafePtr (T *pSubject)
virtual ~SafePtr ()
void reset (T *pSubject=NULL)
T * get ()
const T * get () const
T * operator-> ()
const T * operator-> () const

Protected Member Functions

void attach (const std::string &signal, const Slot &slot)
void detach (const std::string &signal, const Slot &slot)


Detailed Description

template<typename T>
class SafePtr< T >

Smart pointer used to automatically NULLify when the subject is deleted.

This class handles a number of issues relating to the management of Subject attachment lifetimes:

This class is intended to be used as a member variable, in place of a raw pointer to the Subject. If subclasses are to be allowed to attach to the Subject, the variable should be made protected.

Note that this class will not cause any kind of callback when its Subject has been deleted. It will simply NULLify the pointer. If you require any special handling for when the Subject has been deleted, You should separately attach to SIGNAL_NAME(Subject, Deleted).

Definition at line 34 of file SafePtr.h.


Constructor & Destructor Documentation

template<typename T>
SafePtr< T >::SafePtr (  ) 

Default constructor.

No Subject is observed.

Definition at line 42 of file SafePtr.h.

template<typename T>
SafePtr< T >::SafePtr ( T *  pSubject  ) 

Construct with a subject to observe.

Parameters:
pSubject The subject to observe.

Definition at line 52 of file SafePtr.h.

template<typename T>
virtual SafePtr< T >::~SafePtr (  )  [virtual]

Destructor.

This will take care of detaching from any signals.

Definition at line 63 of file SafePtr.h.


Member Function Documentation

template<typename T>
void SafePtr< T >::reset ( T *  pSubject = NULL  ) 

Change what Subject to observe.

This will automatically detach from the old Subject, and attach to the new one.

Parameters:
pSubject The subject to begin observing.

Reimplemented in AttachmentPtr< T >, AttachmentPtr< DockWindow >, AttachmentPtr< ApplicationServices >, and AttachmentPtr< SessionManager >.

Definition at line 78 of file SafePtr.h.

template<typename T>
T* SafePtr< T >::get (  ) 

Get the observed Subject.

Returns:
The observed Subject.

Definition at line 93 of file SafePtr.h.

template<typename T>
const T* SafePtr< T >::get (  )  const

Get the observed Subject.

Returns:
The observed Subject.

Definition at line 101 of file SafePtr.h.

template<typename T>
T* SafePtr< T >::operator-> (  ) 

Get the observed Subject.

Returns:
The observed Subject.

Definition at line 109 of file SafePtr.h.

template<typename T>
const T* SafePtr< T >::operator-> (  )  const

Get the observed Subject.

Returns:
The observed Subject.

Definition at line 117 of file SafePtr.h.

template<typename T>
void SafePtr< T >::attach ( const std::string &  signal,
const Slot slot 
) [protected]

Attaches the specified slot to the specified signal on the current Subject.

If there is no current Subject, it does nothing.

Parameters:
signal The name of the signal to attach to
slot The slot to attach to the signal

Definition at line 133 of file SafePtr.h.

template<typename T>
void SafePtr< T >::detach ( const std::string &  signal,
const Slot slot 
) [protected]

Detaches the specified slot from the specified signal on the current Subject.

If there is no current Subject, it does nothing.

Parameters:
signal The name of the signal to detach from
slot The slot to detach from the signal

Definition at line 151 of file SafePtr.h.


Software Development Kit - Opticks 4.9.0 Build 16218