Event

A generic implementation of the Observer design pattern.  The Event class allows a generic event handler to be created.  The template parameter of the class is the type of the object in the one and only parameter of the receivers.  Each time a function is added to an Event, a function object is created for that function and class object using the boost::bind function.  The function object is then stored in the list of receivers for the Event.  When the Event is notified to transmit data, all receivers for the Event are called with the given object as their one and only parameter.  Any particular class object may store only one function in the Event’s receiver list--any other functions it tries to add will not be stored.

Project

ModelCore

Include

Event.h

Summary
A generic implementation of the Observer design pattern.
The Event constructor.
Adds a new function object to the receiver list for this Event.
Removes a function object from the receiver list for this Event.
Calls all of the function objects for this Event.
Returns how many receivers this Event has.
Indicates whether the Event is transmitting to receivers right now.
Turns a function signature and class object into a function object.
Deletes a function object from the receiver list.
Whether the Event is transmitting to receivers right now.
The list of receivers for this Event.
The list of receivers to be deleted when this Event stops transmitting.

Public

Summary
The Event constructor.
Adds a new function object to the receiver list for this Event.
Removes a function object from the receiver list for this Event.
Calls all of the function objects for this Event.
Returns how many receivers this Event has.
Indicates whether the Event is transmitting to receivers right now.

Constructor

Event

Event() : mInTransmit(false)

The Event constructor.  Initializes the in transmit flag to false.

Functions

AddReceiver

template <typename R> void AddReceiver(void (R::*func)(T),
*object)

Adds a new function object to the receiver list for this Event.

Parameters

funcThe function signature of the receiver.
objectThe class object the function signature belongs to.

RemoveReceiver

template <typename R> void RemoveReceiver(void (R::*func)(T),
*object)

Removes a function object from the receiver list for this Event.  If the receiver is currently being trasmitted to, it is set aside in a special list marked for deletion later.

Parameters

funcThe function signature of the receiver.
objectThe class object the function signature belongs to.

Transmit

void Transmit(const &object)

Calls all of the function objects for this Event.  The given object is passed to the receiver function objects as the one and only parameter.

Parameters

objectThe object to pass to the receivers.

NumReceivers

const wxUint32 NumReceivers()

Returns how many receivers this Event has.

Returns

The number of receivers in this Event.

IsTransmitting

const bool IsTransmitting()

Indicates whether the Event is transmitting to receivers right now.

Returns

A boolean giving whether the Event is transmitting.  The value is true if transmitting, false if not.

Private

Summary
Turns a function signature and class object into a function object.
Deletes a function object from the receiver list.
Whether the Event is transmitting to receivers right now.
The list of receivers for this Event.
The list of receivers to be deleted when this Event stops transmitting.

Functions

MakeReceiver

template <typename R> Receiver MakeReceiver(void (R::*func)(T),
*object) const

Turns a function signature and class object into a function object.

Parameters

funcThe function signature of the receiver.
objectThe class object the function signature belongs to.

Returns

A function object wrapping the function signature and class object.

DeleteReceiver

void DeleteReceiver(const Receiver &receiver)

Deletes a function object from the receiver list.

Parameters

receiverThe function object to delete.

Variables

mInTransmit

bool mInTransmit

Whether the Event is transmitting to receivers right now.

mReceiverList

ReceiverList mReceiverList

The list of receivers for this Event.

mRemoveList

ReceiverList mRemoveList

The list of receivers to be deleted when this Event stops transmitting.

Event() : mInTransmit(false)
The Event constructor.
template <typename R> void AddReceiver(void (R::*func)(T),
*object)
Adds a new function object to the receiver list for this Event.
template <typename R> void RemoveReceiver(void (R::*func)(T),
*object)
Removes a function object from the receiver list for this Event.
void Transmit(const &object)
Calls all of the function objects for this Event.
const wxUint32 NumReceivers()
Returns how many receivers this Event has.
const bool IsTransmitting()
Indicates whether the Event is transmitting to receivers right now.
template <typename R> Receiver MakeReceiver(void (R::*func)(T),
*object) const
Turns a function signature and class object into a function object.
void DeleteReceiver(const Receiver &receiver)
Deletes a function object from the receiver list.
bool mInTransmit
Whether the Event is transmitting to receivers right now.
ReceiverList mReceiverList
The list of receivers for this Event.
ReceiverList mRemoveList
The list of receivers to be deleted when this Event stops transmitting.
ModelCore provides all of the data classes and associated helper classes and functions required to represent a complete game.