Listing 2
template <typename T >
class EventSource : public EventSrcProxy
{
public:
EventSource() {};
virtual ~EventSource(){};
void pollEvent()
{ std::vector<T *>::iterator it_Event;
it_Event = m_ActiveEventPool.begin();
while (it_Event != m_ActiveEventPool.end())
{ EventProxy *ei =
static_cast<EventProxy*>(*it_Event);
if (ei->eventTrigged()) //an event fired
{ theDispatcher().addEventToDispachQueue(ei);
//remove this event from active pool
ei->deactivateEvent();
m_ActiveEventPool.erase(it_Event);
}
else
it_Event++;
}
}
void addEvent(T * const ei)
{ m_ActiveEventPool.push_back(ei);} //add to event pool
const int getEventCount() const {return m_ActiveEventPool.size();}
protected:
std::vector<T * > m_ActiveEventPool;
};
template <typename T>
class Event : public EventProxy
{
protected:
static T theEventSource;
virtual ~Event () {}
};