Recieves Event messages and calls registered handler callbacks. More...
#include <EventHandler.h>
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 EventHandlerCallback & | getCallback (int eventType) const |
Private Types | |
| typedef std::map< int, EventHandlerCallback > | CallbackList |
Private Member Functions | |
| void | defaultCallback (Event *) |
Private Attributes | |
| CallbackList | mCallbackList |
| EventHandlerCallback | mDefaultCallback |
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.
typedef std::map<int, EventHandlerCallback> EventHandler::CallbackList [private] |
| typedef std::tr1::function<void(Event*) EventHandler::EventHandlerCallback) |
| EventHandler::EventHandler | ( | ) | [inline] |
| EventHandler::~EventHandler | ( | ) | [inline] |
| 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] |
| void EventHandler::registerHandler | ( | int | eventType, | |
| EventHandlerCallback | callback | |||
| ) |
Registers a handler callback to a given Event type.
| 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 | ) |
CallbackList EventHandler::mCallbackList [private] |
Internal list of handler callbacks associated with a particluar Event type.
Default callback.
1.7.1