00001
00002
00003
00004
00005
00006
00007 #ifndef EVENTGENERATOR_H_
00008 #define EVENTGENERATOR_H_
00009
00010 #include <list>
00011
00012 namespace srchilite {
00013
00018 template <class EventListener, class EventType> class EventGenerator {
00020 std::list<EventListener *> listeners;
00021 public:
00022 void addListener(EventListener *listener) {
00023 listeners.push_back(listener);
00024 }
00025
00026 void removeListener(EventListener *listener) {
00027 listeners.remove(listener);
00028 }
00029
00030 bool hasListeners() const {
00031 return listeners.size();
00032 }
00033
00038 void notify(const EventType &event) {
00039 for (typename std::list<EventListener *>::const_iterator it =
00040 listeners.begin(); it != listeners.end(); ++it) {
00041 (*it)->notify(event);
00042 }
00043 }
00044 };
00045
00046 }
00047
00048 #endif