AttachmentPtr< T > Class Template Reference

Smart pointer used to simplify Subject attachment lifetimes. More...

#include <AttachmentPtr.h>

Inheritance diagram for AttachmentPtr< T >:

Inheritance graph

List of all members.

Public Member Functions

 AttachmentPtr ()
 AttachmentPtr (T *pSubject)
 AttachmentPtr (const std::string &signalName, const Slot &slot)
 AttachmentPtr (T *pSubject, const std::string &signalName, const Slot &slot)
virtual ~AttachmentPtr ()
void addSignal (const std::string &signalName, const Slot &slot)
void reset (T *pSubject=NULL)


Detailed Description

template<typename T>
class AttachmentPtr< T >

Smart pointer used to simplify Subject attachment lifetimes.

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 observed 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 in the case that 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) with AttachmentPtr::addSignal().

When used in conjunction with a SafeSlot, the attachments will additionally be automatically detached when the SafeSlot's invalidator object is destroyed.

Definition at line 43 of file AttachmentPtr.h.


Constructor & Destructor Documentation

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

Default constructor.

No Subject is observed.

Definition at line 51 of file AttachmentPtr.h.

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

Construct with a subject to observe.

Parameters:
pSubject The subject to observe.

Definition at line 61 of file AttachmentPtr.h.

template<typename T>
AttachmentPtr< T >::AttachmentPtr ( const std::string &  signalName,
const Slot slot 
)

Construct with a single signal/slot connection registered, no Subject observed.

Parameters:
signalName The signal to register interest in.
slot The slot to call when the signal is emitted.

Definition at line 75 of file AttachmentPtr.h.

template<typename T>
AttachmentPtr< T >::AttachmentPtr ( T *  pSubject,
const std::string &  signalName,
const Slot slot 
)

Construct with a subject to observe, and a single signal/slot connection registered.

Parameters:
pSubject The subject to observe.
signalName The signal to register interest in.
slot The slot to call when the signal is emitted.

Definition at line 91 of file AttachmentPtr.h.

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

Destructor.

This will take care of detaching from any signals.

Definition at line 102 of file AttachmentPtr.h.


Member Function Documentation

template<typename T>
void AttachmentPtr< T >::addSignal ( const std::string &  signalName,
const Slot slot 
)

Add a new signal to be observed.

The attachment will be made immediately if there is currently a valid Subject. The attachment will automatically be made whenever the observed Subject is changed.

Parameters:
signalName The signal to register interest in.
slot The slot to call when the signal is emitted.

Definition at line 119 of file AttachmentPtr.h.

template<typename T>
void AttachmentPtr< 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 from SafePtr< T >.

Definition at line 135 of file AttachmentPtr.h.


Software Development Kit - Opticks 4.9.0 Build 16218