本文整理汇总了C++中EventListener::Handle方法的典型用法代码示例。如果您正苦于以下问题:C++ EventListener::Handle方法的具体用法?C++ EventListener::Handle怎么用?C++ EventListener::Handle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventListener
的用法示例。
在下文中一共展示了EventListener::Handle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Trigger
bool EventManager::Trigger(const Event *event) const
{
// TODO: validate type
// trigger events for wildcard listeners first
EventListenerMap::const_iterator wildcardItor = m_registry.find(EVENT_TYPE_WILDCARD);
if (wildcardItor != m_registry.end())
{
const EventListenerTable &table = wildcardItor->second;
for (EventListenerTable::const_iterator i = table.begin(); i != table.end(); ++i)
{
EventListener *listener = *i;
listener->Handle(event);
}
}
// find the listener list for the event type
EventListenerMap::const_iterator itor = m_registry.find(event->GetTypeOf());
if (itor == m_registry.end())
return false;
bool result = false;
// trigger the event in each listener
const EventListenerTable &table = itor->second;
for (EventListenerTable::const_iterator i = table.begin(); i != table.end(); ++i)
{
EventListener *listener = *i;
if (listener->Handle(event))
{
// only return true if a listener signals they handled the event
result = true;
}
}
return result;
}
示例2: ProcessQueue
bool EventManager::ProcessQueue()
{
EventListenerMap::const_iterator wildcardItor = m_registry.find(EVENT_TYPE_WILDCARD);
// swap active queues and empty the new queue
uint queueToProcess = m_activeQueue;
m_activeQueue = (m_activeQueue + 1) % NUM_EVENT_QUEUES;
m_queues[m_activeQueue].clear();
// process the queue!
EventQueue &queue = m_queues[queueToProcess];
while (queue.size() > 0)
{
// pop the next event off the queue
const Event *event = queue.front();
queue.pop_front();
EVENT_TYPE type = event->GetTypeOf();
// process wildcard listeners first (if any)
if (wildcardItor != m_registry.end())
{
const EventListenerTable &table = wildcardItor->second;
for (EventListenerTable::const_iterator i = table.begin(); i != table.end(); ++i)
{
EventListener *listener = *i;
listener->Handle(event);
}
}
EventListenerMap::const_iterator listenerItor = m_registry.find(type);
if (listenerItor != m_registry.end())
{
const EventListenerTable &table = listenerItor->second;
for (EventListenerTable::const_iterator i = table.begin(); i != table.end(); ++i)
{
EventListener *listener = *i;
if (listener->Handle(event))
break; // don't let other listeners handle the event if this one signals it handled it
}
}
SAFE_DELETE(event);
}
// if there are any events left in the queue, push them onto the active queue
if (queue.size() != 0)
{
while (queue.size() > 0)
{
// to preserve sequencing, go bottom-up on the remainder of the queue that was processed
// inserting them at the head of the active queue
const Event *event = queue.back();
queue.pop_back();
m_queues[m_activeQueue].push_front(event);
}
return false;
}
else
return true;
}