00001 #ifndef LISTENER_H
00002 #define LISTENER_H
00003
00022 template <typename EvType>
00023 class Listener
00024 {
00025 public:
00027 Listener(): _registered(false), _ignoringHeardEvent(false),
00028 _processingEvent(false) {}
00029
00031 virtual ~Listener() { ignoreEvents(); }
00032
00033 void ignoreEvents();
00034 void listenForEvents();
00035 void ignoreThisEvent();
00036 inline void processEventPublic(const EvType&);
00037
00044 bool isRegistered() const {return _registered;}
00045
00046 protected:
00051 virtual void processEvent(const EvType& event) = 0;
00052
00053 private:
00054 inline void preProcessEvent();
00055 inline void postProcessEvent();
00056
00057 private:
00061 bool _registered;
00063 bool _ignoringHeardEvent;
00065 bool _processingEvent;
00066 };
00067
00069 template <typename EvType>
00070 inline void
00071 Listener<EvType>::preProcessEvent()
00072 {
00073 _ignoringHeardEvent = false;
00074 _processingEvent = true;
00075 }
00076
00078 template <typename EvType>
00079 inline void
00080 Listener<EvType>::postProcessEvent()
00081 {
00082 _processingEvent = false;
00083
00084 }
00085
00098 template <typename EvType>
00099 inline void
00100 Listener<EvType>::processEventPublic(const EvType& event)
00101 {
00102 preProcessEvent();
00103 try {
00104 processEvent(event);
00105 }
00106 catch (...) {
00107 postProcessEvent();
00108 throw;
00109 }
00110 postProcessEvent();
00111 }
00112
00113 #ifdef __GNUG__
00114
00115 #include "Listener.cc"
00116 #endif
00117
00118 #endif // LISTENER_H