SDL++
C++wrapperfortheSDLlibrary.

event/Listener.h

Go to the documentation of this file.
00001 
00021 #ifndef SDL_EVENT_LISTENER_H
00022 #define SDL_EVENT_LISTENER_H
00023 
00024 #include <SDL.h>
00025 
00026 namespace sdl {
00027 namespace event {
00032     class basic_Listener {
00033         public:
00037             virtual ~basic_Listener () {
00038             };
00039 
00047             virtual bool operator== (const SDL_Event* event) { 
00048                 return false; 
00049             };
00050 
00056             virtual void operator() (const SDL_Event* event) = 0;
00057     }; //basic_Listener
00058 
00066     template<class EventType, class Handler>
00067     class Listener : public basic_Listener {
00068         public:
00075             typedef void (Handler::*HandleFunc) (const EventType& event);
00076 
00084             virtual bool operator== (const SDL_Event* event) { 
00085                 return EventType::is (event); 
00086             };
00087 
00094             Listener (Handler& h, HandleFunc func)
00095               : basic_Listener (), h_ (h), func_ (func) {
00096             }; 
00097 
00101             virtual ~Listener () {
00102             };
00103 
00109             virtual void operator() (const SDL_Event* event) {
00110               (h_.*func_) (EventType (event));
00111             };
00112 
00113         private:
00117             Handler& h_;
00118 
00122             HandleFunc func_;
00123     }; //Listener
00124 }; //event
00125 }; //sdl
00126 
00127 #endif //SDL_EVENT_LISTENER_H
00128 
 All Classes Namespaces Files Functions Variables Typedefs