SafeSlot Class Reference

Subclass of Slot that allows the specification of an object whose destructor will cause the Slot to be automatically detached. More...

#include <SafeSlot.h>

Inheritance diagram for SafeSlot:

Inheritance graph

List of all members.

Public Member Functions

 SafeSlot ()
template<class T, typename Method>
 SafeSlot (T *pT, Method pMethod, SlotInvalidator *pInvalidator)
 SafeSlot (const Slot &slot)
 ~SafeSlot ()

Classes

class  SafeSlotValue
class  SafeSlotWrapper
 A class that extends the Slot::SlotWrapper class to add the ability to query an invalidator. More...


Detailed Description

Subclass of Slot that allows the specification of an object whose destructor will cause the Slot to be automatically detached.

This addresses the problem of stale pointers being left behind when an observer is destroyed while attached to a Subject.

The SafeSlot constructor takes a third argument that is an 'invalidator.' If this argument is NULL, the SafeSlot behaves exactly like a normal Slot. If it is not NULL, the destructor of the invalidator object will cause the SafeSlot to be invalidated. An invalid slot's update method will never be called, and it will be automatically removed from the Subject's list of slots.

A SafeSlot does not need to be detached when its invalidator goes away, because the SafeSlot will be automatically destroyed.

See also:
Slot

Definition at line 52 of file SafeSlot.h.


Constructor & Destructor Documentation

SafeSlot::SafeSlot (  ) 

Creates an empty slot object.

The default constructor creates an empty slot object. The object will return false from isValid() and will test equal to other empty slots.

Definition at line 64 of file SafeSlot.h.

template<class T, typename Method>
SafeSlot::SafeSlot ( T *  pT,
Method  pMethod,
SlotInvalidator pInvalidator 
)

Creates an auto-detaching slot.

Creates an auto-detaching slot. Assuming neither of the first two input arguments is NULL, the SafeSlot will return true from isValid() and will test equal to other SafeSlots created with the same arguments.

Parameters:
pT The object to call in Slot::update.
pMethod The method to call on the object in Slot::update. The method should not be virtual. Virtual slot methods may cause Subject::detach to fail. If a virtual slot is needed, make the slot method non-virtual and have it call a virtual method. On notify, the slot method will be called as follows:
           (pT->*pMethod)(subject, signal, v);
pMethod needs to have the following signature:
           T::method(Subject &subject, const std::string &signal, const boost::any &v);
pInvalidator If this is non- NULL, when pInvalidator is destroyed, this slot will automatically detach from the Subject it is attached to. If this is NULL, the SafeSlot will behave like a normal slot.

Definition at line 98 of file SafeSlot.h.

SafeSlot::SafeSlot ( const Slot slot  ) 

Creates a copy of the input slot.

Parameters:
slot The Slot to copy from.

Definition at line 112 of file SafeSlot.h.

SafeSlot::~SafeSlot (  ) 

Destroys the SafeSlot, detaching from the Subject if necessary.

Definition at line 120 of file SafeSlot.h.


Software Development Kit - Opticks 4.9.0 Build 16218