LeviLamina
Loading...
Searching...
No Matches
typeid_t.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5#include "ll/api/reflection/TypeName.h"
6#include "ll/api/utils/HashUtils.h"
7
8namespace Json {
9class Value;
10}
11class CommandRegistry;
12class Command;
15template <typename>
16class CommandSelector;
17template <typename>
19class CommandPosition;
21
22namespace Bedrock {
23
24template <typename Category>
25class typeid_t {
26public:
27 ushort value{};
28 [[nodiscard]] constexpr typeid_t(typeid_t const& other) : value(other.value) {}
29 constexpr typeid_t& operator=(typeid_t const& other) {
30 value = other.value;
31 return *this;
32 }
33
34 [[nodiscard]] constexpr typeid_t(ushort value) : value(value) {}
35 [[nodiscard]] constexpr typeid_t() = default;
36
37 constexpr bool operator==(typeid_t const& other) const { return value == other.value; }
38
39 static std::atomic_ushort& _getCounter() {
40
41 // MCAPI // error C2201
42 static std::atomic_ushort storage;
43
44 return storage;
45 }
46};
47
48template <>
49LLAPI std::atomic_ushort& typeid_t<CommandRegistry>::_getCounter();
50
51// if dll reload, typeid can't keep, so we need a static implementation
52LLAPI ushort crtypidImpl(size_t Type);
53
54template <typename Category, typename Type>
55typeid_t<Category> type_id() {
56 if constexpr (std::is_same_v<Category, CommandRegistry>) {
57 constexpr size_t hash = ll::hash_utils::doHash(ll::reflection::type_raw_name_v<Type>);
58 return crtypidImpl(hash);
59 } else {
60 static typeid_t<Category> id{++typeid_t<Category>::_getCounter()};
61 return id;
62 }
63}
64
65}; // namespace Bedrock
66
67// clang-format off
68MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, int>();
69MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, bool>();
70MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, float>();
71MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, std::string>();
72MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, std::unique_ptr<::Command>>();
73MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, std::vector<class BlockStateCommandParam>>();
74MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, class CommandBlockName>();
75MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, class CommandFilePath>();
76MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, class CommandMessage>();
77MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, class CommandPosition>();
78MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, class CommandPositionFloat>();
79MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, class CommandRawText>();
80MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, class CommandSelector<class Actor>>();
81MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, class CommandSelector<class Player>>();
82MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, class CommandWildcardInt>();
83MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, class Json::Value>();
84MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, class RelativeFloat>();
85MCTAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, class WildcardCommandSelector<class Actor>>();
86
87template<> LLAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, DimensionType>();
88template<> LLAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, class CommandItem>();
89template<> LLAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, CommandIntegerRange>();
90template<> LLAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, class MobEffect const*>();
91template<> LLAPI Bedrock::typeid_t<CommandRegistry> Bedrock::type_id<CommandRegistry, ActorDefinitionIdentifier const*>();
92
93// clang-format on
Definition typeid_t.h:25
Definition CommandIntegerRange.h:5
Definition CommandPositionFloat.h:8
Definition CommandPosition.h:13
Definition CommandRegistry.h:44
Definition CommandSelector.h:11
Definition Command.h:17
Definition WildcardCommandSelector.h:7
Definition ActorDefinitionIdentifier.h:13