Slot Class Reference

Class for specifying which method to call in response to a call to notify by a Subject. More...

#include <Slot.h>

Inheritance diagram for Slot:

Inheritance graph

List of all members.

Public Member Functions

 Slot ()
template<class T, typename Method>
 Slot (T *pT, Method pMethod)
 Slot (const Slot &slot)
Slotoperator= (const Slot &rhs)
bool isValid () const
void update (Subject &subject, const std::string &signal, const boost::any &data) const
void callAttachMethod (Subject &subject, const std::string &signal) const
void callDetachMethod (Subject &subject, const std::string &signal) const
bool operator== (const Slot &rhs) const
const std::type_info & getType () const
 ~Slot ()

Protected Attributes

SlotWrappermpSlot

Classes

class  SlotValue
class  SlotWrapper
 This class provides an abstract interface that implements the details of the slot and hides the type information behind a generic interface. More...


Detailed Description

Class for specifying which method to call in response to a call to notify by a Subject.

Typically, only the constructors of this class will be used outside of the underlying implementation of the Subject class.

When a Subject calls 'notify' with a particular signal name, all slots that are attached to that signal on the Subject will have their update method called. The slot's update method will in turn call the method on the object provided via the slot's constructor. Slot methods need to have the following signature:

  void T::method(Subject &subject, const std::string &signal, const boost::any &v);

When called, the arguments will be as follows: subject: the Subject notifying with the signal signal: the name of the signal the Subject notified v: data provided to the notify method by the Subject

When a Slot is attached to a signal on a Subject, if the slot method is on an object derived from Observer, the object's attached method will be called. Similarly, when a Slot is detached from an object derived from Observer, the object's detached method will be called.

See also:
Subject::attach, Subject::detach, Observer::attached, Observer::detached

Definition at line 59 of file Slot.h.


Constructor & Destructor Documentation

Slot::Slot (  ) 

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 71 of file Slot.h.

template<class T, typename Method>
Slot::Slot ( T *  pT,
Method  pMethod 
)

Creates a slot.

Creates a slot. Assuming neither of the input arguments is NULL, the Slot will return true from isValid and will test equal to other Slots 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);

Definition at line 100 of file Slot.h.

Slot::Slot ( const Slot slot  ) 

Creates a copy of the input slot.

Parameters:
slot The Slot to copy from.

Definition at line 114 of file Slot.h.

Slot::~Slot (  ) 

Destroys the Slot.

Definition at line 259 of file Slot.h.


Member Function Documentation

Slot& Slot::operator= ( const Slot rhs  ) 

Copies the state of one slot into another slot.

Parameters:
rhs The Slot to copy from: on the right-hand-side of the =.
Returns:
a reference to the slot assigned to.

Definition at line 131 of file Slot.h.

bool Slot::isValid (  )  const

Indicates if the Slot is a valid Slot.

Returns:
false if the Slot was created via the default constructor or copied from an invalid Slot, or true otherwise.

Definition at line 152 of file Slot.h.

void Slot::update ( Subject subject,
const std::string &  signal,
const boost::any &  data 
) const

Calls the method on the Slot.

Parameters:
subject The Subject that called notify.
signal The name of the signal the Subject is notifying.
data The ancillary data the Subject provided to its notification.

Definition at line 169 of file Slot.h.

void Slot::callAttachMethod ( Subject subject,
const std::string &  signal 
) const

Calls the attached method on the observer, if it derives from Observer.

This method is typically only called by Subject::attach.

Parameters:
subject The Subject that the slot is being attached to.
signal The name of the signal the Slot is being attached to.

Definition at line 188 of file Slot.h.

void Slot::callDetachMethod ( Subject subject,
const std::string &  signal 
) const

Calls the detached method on the observer, if it derives from Observer.

This method is typically only called by Subject::detach.

Parameters:
subject The Subject that the slot is being detached from.
signal The name of the signal the Slot is being detached from.

Definition at line 207 of file Slot.h.

bool Slot::operator== ( const Slot rhs  )  const

Indicates if two Slots are equivalent.

Parameters:
rhs The slot on the right-hand-side of the comparison.
Returns:
true if the two Slots are both invalid or if they were constructed with the same arguments, or false otherwise.

Definition at line 224 of file Slot.h.

const std::type_info& Slot::getType (  )  const

Gets the typeid of the object the Slot was constructed with.

Returns:
the typeid of the object the Slot was constructed with or typeid(void) if the Slot is invalid.

Definition at line 246 of file Slot.h.


Member Data Documentation

SlotWrapper* Slot::mpSlot [protected]

Definition at line 347 of file Slot.h.


Software Development Kit - Opticks 4.9.0 Build 16218