예제 #1
0
파일: EventManager.cpp 프로젝트: mangeg/MG3
//------------------------------------------------------------------------|
bool EventManager::RegisterEvent(EventType const& Type, IEventHandler* pHandler)
{
	if(!ValidateType(Type))
		return false;

	EventHandlerMap::iterator elmIt = m_Registry.find(Type.GetIdent());

	// If this event is not registered at all yet, initialize a list of handlers for this event.
	if(elmIt == m_Registry.end())
	{
		EventHandlerMapIRes elmIRes = m_Registry.insert(
			EventHandlerMapEnt(Type.GetIdent(), EventHandlerTable()));

		if(!elmIRes.second)
			return false;
		if(elmIRes.first == m_Registry.end())
			return false;

		elmIt = elmIRes.first;
	}

	EventHandlerTable& evhTable = (*elmIt).second;

	// Check if event is already registered
	for(EventHandlerTable::iterator it = evhTable.begin(), itEnd = evhTable.end(); it != itEnd; it++)
	{
		bool bHandlerMatch = (*it == pHandler);
		if(bHandlerMatch)
			return false;
	}

	evhTable.push_back(pHandler);

	return true;
}
예제 #2
0
파일: EventManager.cpp 프로젝트: mangeg/MG3
//------------------------------------------------------------------------|
bool EventManager::UnregisterEvent(EventType const& Type, IEventHandler* pHandler)
{
	if(!ValidateType(Type))
		return false;

	bool rc = false;
	
	// Find the currently registered handlers for the event.
	EventHandlerMap::iterator elmIt = m_Registry.find(Type.GetIdent());

	if(elmIt != m_Registry.end())
	{
		EventHandlerTable& table = elmIt->second;
		for(EventHandlerTable::iterator it2 = table.begin(), it2End = table.end(); it2 != it2End; it2++)
		{
			if(*it2 == pHandler)
			{
				table.erase(it2);
				rc = true;
				break;
			}
		}
	}

	return rc;
}
예제 #3
0
파일: EventManager.cpp 프로젝트: mangeg/MG3
//------------------------------------------------------------------------|
bool EventManager::ValidateType(EventType const& Type) const
{
	if(0 == Type.GetStr().length())
		return false;
	if(Type == skAllEvents)
		return true;
	if(Type.GetIdent() == 0 && wcscmp(Type.GetStr().c_str(), skpWildCardEventType) == 0)
		return false;

	EventTypeSet::const_iterator evIt = m_TypeList.find(Type);

	if(evIt == m_TypeList.end())
		return false;

	return true;
}