LeviLamina
Loading...
Searching...
No Matches
EventId.h
1#pragma once
2
3#include "ll/api/reflection/TypeName.h"
4#include "ll/api/utils/HashUtils.h"
5
6namespace ll::event {
7class EventIdView;
8class EventId : public hash_utils::HashedIdBase {
9public:
10 std::string name;
11
12 [[nodiscard]] constexpr explicit EventId(std::string_view id) noexcept
13 : HashedIdBase(hash_utils::doHash(id)),
14 name(id) {}
15 [[nodiscard]] constexpr EventId(EventIdView const& id) noexcept;
16};
17class EventIdView : public hash_utils::HashedIdBase {
18public:
19 std::string_view name;
20
21 [[nodiscard]] constexpr explicit EventIdView(std::string_view id) noexcept
22 : HashedIdBase(hash_utils::doHash(id)),
23 name(id) {}
24 [[nodiscard]] constexpr EventIdView(EventId const& id) noexcept : HashedIdBase(id.hash), name(id.name) {}
25};
26[[nodiscard]] constexpr EventId::EventId(EventIdView const& id) noexcept : HashedIdBase(id.hash), name(id.name) {}
27
28static constexpr inline EventIdView EmptyEventId{{}};
29
30template <class T>
31constexpr EventIdView getEventId = []() -> EventIdView {
32 using self = std::remove_cvref_t<T>;
33 if constexpr (self::CustomEventId != EmptyEventId) {
34 return self::CustomEventId;
35 } else {
36 static_assert(std::is_final_v<self>, "Only final classes can use getEventId");
37 return EventIdView{reflection::type_unprefix_name_v<self>};
38 }
39}();
40} // namespace ll::event
Definition EventId.h:17
Definition EventId.h:8