Nui
event_context.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <memory>
6 
7 namespace Nui
8 {
9  class EventEngine
10  {
11  public:
12  EventEngine() = default;
13  EventEngine(const EventEngine&) = default;
14  EventEngine(EventEngine&&) = default;
15  EventEngine& operator=(const EventEngine&) = default;
17  virtual ~EventEngine() = default;
18 
19  virtual EventRegistry& eventRegistry() = 0;
20  };
21 
23  {
24  public:
26  {
27  return eventRegistry_;
28  }
29 
30  private:
31  EventRegistry eventRegistry_;
32  };
33 
38  {
39  public:
42 
44  : impl_{std::make_shared<DefaultEventEngine>()}
45  {}
46  EventContext(EventContext const&) = default;
47  EventContext(EventContext&&) = default;
48  EventContext& operator=(EventContext const&) = default;
50  ~EventContext() = default;
51 
53  {
54  return impl_->eventRegistry().registerEvent(std::move(event));
55  }
57  {
58  return impl_->eventRegistry().activateEvent(id);
59  }
61  {
62  return impl_->eventRegistry().activateAfterEffect(id);
63  }
65  {
66  impl_->eventRegistry().executeActiveEvents();
67  }
69  {
70  impl_->eventRegistry().executeEvent(id);
71  }
73  {
74  return impl_->eventRegistry().registerAfterEffect(std::move(event));
75  }
77  {
78  impl_->eventRegistry().cleanInvalidEvents();
79  }
81  {
82  impl_->eventRegistry().removeAfterEffect(id);
83  }
84  void reset()
85  {
86  impl_->eventRegistry().clear();
87  }
88 
89  private:
90  std::shared_ptr<EventEngine> impl_;
91  };
92 
93  extern thread_local EventContext globalEventContext;
94 }
Definition: event_context.hpp:23
EventRegistry & eventRegistry() override
Definition: event_context.hpp:25
This object can be copied with low cost.
Definition: event_context.hpp:38
void removeAfterEffect(EventIdType id)
Definition: event_context.hpp:80
EventIdType registerAfterEffect(Event event)
Definition: event_context.hpp:72
auto activateEvent(EventIdType id)
Definition: event_context.hpp:56
EventContext()
Definition: event_context.hpp:43
void executeEvent(EventIdType id)
Definition: event_context.hpp:68
void reset()
Definition: event_context.hpp:84
EventContext & operator=(EventContext &&)=default
void cleanInvalidEvents()
Definition: event_context.hpp:76
~EventContext()=default
EventContext(EventContext &&)=default
auto activateAfterEffect(EventIdType id)
Definition: event_context.hpp:60
EventRegistry::EventIdType EventIdType
Definition: event_context.hpp:40
void executeActiveEventsImmediately()
Definition: event_context.hpp:64
EventContext & operator=(EventContext const &)=default
constexpr static auto invalidEventId
Definition: event_context.hpp:41
EventIdType registerEvent(Event event)
Definition: event_context.hpp:52
EventContext(EventContext const &)=default
Definition: event_context.hpp:10
EventEngine(EventEngine &&)=default
EventEngine & operator=(EventEngine &&)=default
virtual EventRegistry & eventRegistry()=0
EventEngine & operator=(const EventEngine &)=default
virtual ~EventEngine()=default
EventEngine()=default
EventEngine(const EventEngine &)=default
Definition: event_registry.hpp:14
constexpr static EventIdType invalidEventId
Definition: event_registry.hpp:18
SelectablesRegistry< Event >::IdType EventIdType
Definition: event_registry.hpp:17
Definition: event.hpp:40
Definition: file_dialog.hpp:6
thread_local EventContext globalEventContext
Definition: event_context.cpp:5