Enigma  3.2.0
A Simple, Reliable and Efficient Encryption Tool
EventDispatcher.hpp
Go to the documentation of this file.
1 #pragma once
2 #ifndef ENIGMA_EVENT_DISPATCHER_H
3 #define ENIGMA_EVENT_DISPATCHER_H
4 
5 #include <Core/Core.hpp>
6 #include <Core/Types.hpp>
7 
8 #include <functional>
9 
10 #include "Event.hpp"
11 
13 
16  template<typename T>
17  using EventFun = std::function<bool(T&)>;
18 
19  public:
20  explicit EventDispatcher(Event& event)
21  : m_event(event) {
22  }
23 
24  template<typename T>
25  bool Dispatch(EventFun<T> func) {
26  if (m_event.GetEventType() == T::GetStaticType()) {
27  m_event.SetHandled(func(*(T *) &m_event));
28  return true;
29  }
30  return false;
31  }
32 
33  private:
34  Event& m_event;
35 };
37 
38 #endif // !ENIGMA_EVENT_DISPATCHER_H
#define NS_ENIGMA_BEGIN
Enable/Disable Assertions.
Definition: Macros.hpp:13
#define NS_ENIGMA_END
Definition: Macros.hpp:14
bool Dispatch(EventFun< T > func)
EventDispatcher(Event &event)
Definition: Event.hpp:66
void SetHandled(const bool handled) noexcept
Definition: Event.hpp:78
virtual EventType GetEventType() const =0