ezEngine  Milestone 7
Event_inl.h
1 #pragma once
2 
3 template <typename EventData, typename MutexType>
4 ezEventBase<EventData, MutexType>::ezEventBase(ezAllocatorBase* pAllocator) : m_EventHandlers(pAllocator)
5 {
6  m_bBroadcasting = false;
7 }
8 
11 template <typename EventData, typename MutexType>
13 {
14  EZ_LOCK(m_Mutex);
15 
16  m_EventHandlers.PushBack(handler);
17 }
18 
21 template <typename EventData, typename MutexType>
23 {
24  EZ_LOCK(m_Mutex);
25 
26  bool bResult = m_EventHandlers.Remove(handler);
27  EZ_IGNORE_UNUSED(bResult);
28  EZ_ASSERT_DEV(bResult, "ezEvent::RemoveEventHandler: Handler %p has not been registered or already been unregistered.", &handler);
29 }
30 
32 template <typename EventData, typename MutexType>
34 {
35  EZ_LOCK(m_Mutex);
36 
37  EZ_ASSERT_DEV(!m_bBroadcasting, "The event has been triggered recursively or from several threads simultaneously.");
38 
39  if (m_bBroadcasting)
40  return;
41 
42  m_bBroadcasting = true;
43 
44  for (ezUInt32 ui = 0; ui < m_EventHandlers.GetCount(); ++ui)
45  m_EventHandlers[ui](eventData);
46 
47  m_bBroadcasting = false;
48 }
49 
50 
51 template <typename EventData, typename MutexType, typename AllocatorWrapper>
52 ezEvent<EventData, MutexType, AllocatorWrapper>::ezEvent() : ezEventBase<EventData, MutexType>(AllocatorWrapper::GetAllocator())
53 {
54 }
55 
56 template <typename EventData, typename MutexType, typename AllocatorWrapper>
57 ezEvent<EventData, MutexType, AllocatorWrapper>::ezEvent(ezAllocatorBase* pAllocator) : ezEventBase<EventData, MutexType>(pAllocator)
58 {
59 }
60