fysxasteroids/engine/EventManager.h

62 lines
1.6 KiB
C
Raw Normal View History

#ifndef EVENTSMANAGER_H
#define EVENTSMANAGER_H
2010-04-05 23:38:59 +02:00
// #include "Module.h"
2010-04-05 23:38:59 +02:00
#include <boost/shared_ptr.hpp>
#include <string>
#include <map>
#include <vector>
#include <queue>
#include "EventBase.h"
#include "Module.h"
2010-04-05 23:38:59 +02:00
namespace Engine {
2010-04-05 23:38:59 +02:00
/** \brief Keeps track of all the Modules that registered for a given event type
2010-04-05 23:38:59 +02:00
*
*/
class EventManager : public Module {
public:
virtual ~EventManager() {};
/** \brief Registers a listener to a given event type */
bool RegisterListener (Module *listener_module, const int event_type);
2010-04-05 23:38:59 +02:00
/** \brief Calls all event listeners to handle the events */
void Process ();
/** \brief Queues the until Process() gets called */
bool QueueEvent (const EventBasePtr &event);
/** \brief Calls the listener handlers immediately */
bool TriggerEvent (const EventBasePtr &event);
/** \brief Returns true if there is a listener for a given event type */
bool HasEventTypeListener (const int event_type) {
return mEventTypeListeners.find(event_type) != mEventTypeListeners.end();
}
/** \brief Returns the number of listeners for a given event type */
unsigned int GetEventTypeListenerCount (const int event_type) {
if (!HasEventTypeListener (event_type))
return 0;
return (mEventTypeListeners.find(event_type))->second.size();
}
unsigned int GetQueuedEventCount () {
return mQueuedEvents.size();
}
protected:
virtual int OnInit (int argc, char* argv[]);
virtual void OnDestroy();
private:
/** \brief Contains for each event type the list of listeners */
std::map <int, std::vector<Module*> > mEventTypeListeners;
2010-04-05 23:38:59 +02:00
std::queue <EventBasePtr> mQueuedEvents;
};
}
#endif /* EVENTSMANAGER_H */