Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes

EventHandler Class Reference

Recieves Event messages and calls registered handler callbacks. More...

#include <EventHandler.h>

Inheritance diagram for EventHandler:
Listener GameEventHandler

List of all members.

Public Types

typedef std::tr1::function
< void(Event *) 
EventHandlerCallback )

Public Member Functions

 EventHandler ()
 ~EventHandler ()
void registerHandler (int eventType, EventHandlerCallback callback)
 Registers a handler callback to a given Event type.
void unregisterHandler (int eventType)
void push (Event *event)

Protected Member Functions

const EventHandlerCallbackgetCallback (int eventType) const

Private Types

typedef std::map< int,
EventHandlerCallback
CallbackList

Private Member Functions

void defaultCallback (Event *)

Private Attributes

CallbackList mCallbackList
EventHandlerCallback mDefaultCallback

Detailed Description

Recieves Event messages and calls registered handler callbacks.

The EventHandler implements a centralized object that calls Event handler functions, function objects or member functions for a given Event type.


Member Typedef Documentation

typedef std::map<int, EventHandlerCallback> EventHandler::CallbackList [private]
typedef std::tr1::function<void(Event*) EventHandler::EventHandlerCallback)

Constructor & Destructor Documentation

EventHandler::EventHandler (  )  [inline]
EventHandler::~EventHandler (  )  [inline]

Member Function Documentation

void EventHandler::defaultCallback ( Event  )  [inline, private]

Default callback implementation.

Intentionally does nothing. Provided as a backup in the case that a requested callback is not registered.

const EventHandler::EventHandlerCallback & EventHandler::getCallback ( int  eventType  )  const [protected]

Used internally to get a reference to a handler callback.

Parameters:
eventType An int value corresponding to an Event type.

If the given Event type is not currently registered, a default callback will be returned instead which does nothing.

void EventHandler::push ( Event event  )  [virtual]

Implements Listener.

void EventHandler::registerHandler ( int  eventType,
EventHandlerCallback  callback 
)

Registers a handler callback to a given Event type.

Parameters:
eventType An int value corresponding to an Event type.
callback The handler callback to bind to the eventType parameter.

The callback can be static function, a non-static class member function or a function object. Using non-static class member functions can be done by using the std::tr1::bind function. Assuming a class Foo, it would look like this:

bind(&Foo::Function, this, std::tr1::placeholders::_1)

Attempts to register a handler function for an Event type that's already been registered will be ignored and a warning message added to the log. If you need to change an existing handler for a given Event type, use EventHandler::unregisterHandler to remove the current binding first and then register the new handler.

void EventHandler::unregisterHandler ( int  eventType  ) 

Removes a handler callback from a given Event type.

Parameters:
eventType An int value corresponding to an Event type.

If the given Event type is not currently registered, the call will be ignored and a warning message will be added to the log.


Member Data Documentation

Internal list of handler callbacks associated with a particluar Event type.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines