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.
Controller.h
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. |
|
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.
| event | The name of the event the receiver will listen to. |
| func | The function signature of the receiver. |
| object | The class object the function signature belongs to. |
|
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.
| event | The name of the event the receiver is listening to. |
| func | The function signature of the receiver. |
| object | The class object the function signature belongs to. |
|
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.
| event | The name of the event to trigger. |
| object | The object to pass to the receivers. |
The Controller destructor. | |
Returns the type information associated with the template parameter. | |
The map of event names to the Events themselves. |
| 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.
|
|
|
| ~Controller() |
| template <typename T> wxString typeinfo() |
| EventMap mEventMap |