LeviLamina
Loading...
Searching...
No Matches
Event.h
1#pragma once
2
3#include <concepts>
4#include <typeindex>
5#include <type_traits>
6
7#include "ll/api/base/Macro.h"
8#include "ll/api/event/EventId.h"
9
10class CompoundTag;
11
12namespace ll::event {
13template <class T>
14class Cancellable;
15class CallbackStream;
16
17class Event {
18private:
19 template <class T>
20 friend class ::ll::event::Cancellable;
21
22 friend class CallbackStream;
23
24 bool mCancelled{false};
25
26 LLAPI void serializeWithCancel(CompoundTag&) const;
27 LLAPI void deserializeWithCancel(CompoundTag const&);
28
29protected:
30 constexpr Event() = default;
31
32public:
33 LLAPI virtual ~Event() = default;
34
35 LLAPI virtual void serialize(CompoundTag&) const;
36 LLAPI virtual void deserialize(CompoundTag const&);
37
38 LLAPI virtual EventId getId() const;
39
40 static constexpr EventIdView CustomEventId{EmptyEventId};
41};
42
43namespace detail {
44LLAPI void registerRuntimeEventId(std::type_index type, EventIdView eventId);
45
46template <class T>
47 requires std::derived_from<std::remove_cvref_t<T>, Event>
48void registerRuntimeEventId() {
49 using EventType = std::remove_cvref_t<T>;
50 static const bool registered = [] {
51 registerRuntimeEventId(std::type_index{typeid(EventType)}, getEventId<EventType>);
52 return true;
53 }();
54 static_cast<void>(registered);
55}
56} // namespace detail
57} // namespace ll::event
Definition CompoundTag.h:23
Definition Cancellable.h:8
Definition EventId.h:17
Definition EventId.h:8
Definition Event.h:17