LeviLamina
Loading...
Searching...
No Matches
ListenerBase.h
1#pragma once
2
3#include <memory>
4
5#include "ll/api/base/StdInt.h"
6#include "ll/api/event/EventId.h"
7#include "ll/api/mod/NativeMod.h"
8
9namespace ll::event {
10class EventBus;
11class Event;
12class CallbackStream;
13
14enum class EventPriority {
15 Highest = 0,
16 High = 100,
17 Normal = 200,
18 Low = 300,
19 Lowest = 400,
20};
21
22using ListenerId = uint64;
23
25 friend CallbackStream;
26 friend EventBus;
27 ListenerId id;
28 EventPriority priority;
29
30protected:
31 LLAPI explicit ListenerBase(EventPriority priority, std::weak_ptr<mod::Mod> mod = mod::NativeMod::current());
32
33public:
34 std::weak_ptr<mod::Mod> modPtr;
35
36 ListenerBase(ListenerBase&&) = delete;
37 ListenerBase(ListenerBase const&) = delete;
38 ListenerBase& operator=(ListenerBase&&) = delete;
39 ListenerBase& operator=(ListenerBase const&) = delete;
40
41 [[nodiscard]] constexpr ListenerId getId() const { return id; }
42 [[nodiscard]] constexpr EventPriority getPriority() const { return priority; }
43
44 [[nodiscard]] constexpr bool operator==(ListenerBase const& other) const noexcept { return id == other.id; }
45
46 [[nodiscard]] constexpr std::strong_ordering operator<=>(ListenerBase const& other) const noexcept {
47 if (priority != other.priority) {
48 return priority <=> other.priority;
49 }
50 return id <=> other.id;
51 }
52
53 virtual ~ListenerBase() = default;
54
55 virtual void call(Event& event) = 0;
56};
57
58using ListenerPtr = std::shared_ptr<ListenerBase>;
59} // namespace ll::event
Definition EventBus.h:25
Definition Event.h:14
Definition ListenerBase.h:24