Controller

The communication mechanism between the View and the Model.  The Controller class is the go-between for the Model classes and the View, however the View is implemented.  By using the Observer design pattern, complete decoupling is acheived between the visual representation of the game data and the game data itself as neither knows anything about the other.  The View adds receivers to the Controller by supplying a function and class as a receiver, and the name of the event to listen to.  The Model triggers events by supplying the data to be transmitted and the name of the event to transmit to.  There are safeguards in place to ensure that type-safety is maintained when transmitting data from the Model to the View.  All receiver functions that are registered must take exactly one parameter.

Derived From

Singleton

Project

ModelCore

Include

Controller.h

Summary
The communication mechanism between the View and the Model.
Adds a receiver to the list of receivers for the specified event.
Removes a receiver from the list of receivers for the specified event.
Calls all of the receivers for the given event with the given object as the parameter.
The Controller destructor.
Returns the type information associated with the template parameter.
The map of event names to the Events themselves.

Public

Summary
Adds a receiver to the list of receivers for the specified event.
Removes a receiver from the list of receivers for the specified event.
Calls all of the receivers for the given event with the given object as the parameter.

Functions

AddReceiver

template <typename T, typename R> void AddReceiver(const wxString &event,
void (R::*func)(T),
*object)

Adds a receiver to the list of receivers for the specified event.  If the receiver is the first for the given event name, a new Event is created, and the receiver is added to it.  If other receivers have already been added, the new receiver is checked to ensure that the type of its one and only parameter is the exact same as all previously added receivers.

Parameters

eventThe name of the event the receiver will listen to.
funcThe function signature of the receiver.
objectThe class object the function signature belongs to.

RemoveReceiver

template <typename T, typename R> void RemoveReceiver(const wxString &event,
void (R::*func)(T),
*object)

Removes a receiver from the list of receivers for the specified event.  If the receiver is currently executing, it will be safely deleted after it has finished, thus preventing corruption in the call stack.  If the receiver is the last listener to the Event, then the Event is destroyed.

Parameters

eventThe name of the event the receiver is listening to.
funcThe function signature of the receiver.
objectThe class object the function signature belongs to.

Transmit

template <typename T> void Transmit(const wxString &event,
const &object)

Calls all of the receivers for the given event with the given object as the parameter.  If the type of the object does not match the type of a receiver’s stored parameter type, an error is thrown to the screen.

Parameters

eventThe name of the event to trigger.
objectThe object to pass to the receivers.

Private

Summary
The Controller destructor.
Returns the type information associated with the template parameter.
The map of event names to the Events themselves.

Destructor

~Controller

~Controller()

The Controller destructor.  Cleans up any Event objects that have not been already destroyed.

Functions

typeinfo

template <typename T> wxString typeinfo()

Returns the type information associated with the template parameter.

Returns

A string containing the type information of the template parameter.

Variables

mEventMap

EventMap mEventMap

The map of event names to the Events themselves.  The Event objects are stored as void * because they are template objects and every instance of a template class is a brand new type, making it is impossible to store them as Event *, for example.  To get around this, the Events are changed to void * using static_cast<> and stored in the map, then converted back into the proper Event<> type, later when needed, using the stored type information for each Event.

template <typename T, typename R> void AddReceiver(const wxString &event,
void (R::*func)(T),
*object)
Adds a receiver to the list of receivers for the specified event.
template <typename T, typename R> void RemoveReceiver(const wxString &event,
void (R::*func)(T),
*object)
Removes a receiver from the list of receivers for the specified event.
template <typename T> void Transmit(const wxString &event,
const &object)
Calls all of the receivers for the given event with the given object as the parameter.
~Controller()
The Controller destructor.
template <typename T> wxString typeinfo()
Returns the type information associated with the template parameter.
EventMap mEventMap
The map of event names to the Events themselves.
A generic implementation of the Observer design pattern.
A template class that provides an implementation of the Singleton pattern.
ModelCore provides all of the data classes and associated helper classes and functions required to represent a complete game.