#include <SafeSlot.h>

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... | |
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.
Definition at line 52 of file SafeSlot.h.
| 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.
| 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.
| 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); 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.
| 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.