예제 #1
0
// *****************************************************************************
void cEventManager::VAddListener(const EventListenerCallBackFn & fnListener,
	const EventType & eventType)
{
	Log_Write(ILogger::LT_EVENT, 2, "Attempting to add listener for event " + eventType.GetString());
	
	EventListenerList & eventListeners = m_eventListeners[eventType.GetHash()];

    for (auto it = eventListeners.begin(); it != eventListeners.end(); it++)
    {
		if (fnListener.target_type() == (*it).target_type())
        {
			Log_Write(ILogger::LT_WARNING, 2, "Attempting to double-register a listener for event " + eventType.GetString());
            return;
        }
    }

	eventListeners.push_back(fnListener);
	Log_Write(ILogger::LT_EVENT, 2, "Successfully added delegate for event type " + eventType.GetString());
}
예제 #2
0
// *****************************************************************************
void cEventManager::VRemoveListener(const EventListenerCallBackFn & fnListener,
	const EventType & eventType)
{
	bool success = false;
	Log_Write(ILogger::LT_EVENT, 2, "Attempting to remove delegate function from event type " + eventType.GetString());
	
	EventListenerList & eventListeners = m_eventListeners[eventType.GetHash()];

	auto findIt = m_eventListeners.find(eventType.GetHash());
    if (findIt != m_eventListeners.end())
	{
		EventListenerList & listeners = findIt->second;
		for (auto it = listeners.begin(); it != listeners.end(); it++)
		{
			if (fnListener == (*it))
			{
				listeners.erase(it);
				Log_Write(ILogger::LT_EVENT, 2, "Successfully removed delegate for event type " + eventType.GetString());
				return;
			}
		}
	}

	if(!success)
	{
		Log_Write(ILogger::LT_WARNING, 2, "Attempting to double-register a listener for event " + eventType.GetString());
	}
}