diff --git a/lib/Core/Raw.hpp b/lib/Core/Raw.hpp index 36dccc7..60c8bc3 100644 --- a/lib/Core/Raw.hpp +++ b/lib/Core/Raw.hpp @@ -166,8 +166,13 @@ class OffsetPtr static constexpr uintptr_t offset = A; static constexpr bool indirect = std::is_pointer_v; + constexpr OffsetPtr(uintptr_t aBase) + : addr(aBase + offset) + { + } + constexpr OffsetPtr(void* aBase) - : base(reinterpret_cast(aBase)) + : addr(reinterpret_cast(aBase) + offset) { } @@ -229,7 +234,7 @@ class OffsetPtr [[nodiscard]] inline uintptr_t GetAddress() const noexcept { - return base + offset; + return addr; } inline static Type* Get(void* aBase) @@ -242,6 +247,6 @@ class OffsetPtr return OffsetPtr(aBase); } - uintptr_t base; + uintptr_t addr; }; } diff --git a/lib/Red/TypeInfo/Definition.hpp b/lib/Red/TypeInfo/Definition.hpp index fed39fb..799257b 100644 --- a/lib/Red/TypeInfo/Definition.hpp +++ b/lib/Red/TypeInfo/Definition.hpp @@ -754,6 +754,33 @@ class EnumDescriptor : public CEnum { } + bool HasOption(int64_t aValue) + { + for (uint32_t i = 0; i != valueList.size; ++i) + { + if (aValue == valueList.entries[i]) + return true; + } + + return false; + } + + bool HasOption(CName aName) + { + for (uint32_t i = 0; i != valueList.size; ++i) + { + if (aName == hashList.entries[i]) + return true; + } + + return false; + } + + bool HasOption(const char* aName) + { + return HasOption(CName(aName)); + } + void AddOption(int64_t aValue, const char* aName) { if (aValue < Limits::min()) @@ -1182,4 +1209,23 @@ struct GlobalDefinition return AScope; } }; + +template +inline auto GetDescriptor() +{ + auto rtti = CRTTISystem::Get(); + + if constexpr (std::is_class_v) + { + return reinterpret_cast*>(rtti->GetClass(GetTypeName())); + } + else if constexpr (std::is_enum_v) + { + return reinterpret_cast*>(rtti->GetEnum(GetTypeName())); + } + else + { + return rtti->GetType(GetTypeName()); + } +} } diff --git a/lib/Red/TypeInfo/Resolving.hpp b/lib/Red/TypeInfo/Resolving.hpp index 4deef13..91dc817 100644 --- a/lib/Red/TypeInfo/Resolving.hpp +++ b/lib/Red/TypeInfo/Resolving.hpp @@ -291,6 +291,21 @@ class TypeLocator return reinterpret_cast(s_type); } + static inline CEnum* GetEnum() + { + if (!s_resolved) + { + Resolve(); + } + + if (!s_type || s_type->GetType() != ERTTIType::Enum) + { + return nullptr; + } + + return reinterpret_cast(s_type); + } + static inline bool IsDefined() { if (!s_resolved) @@ -397,6 +412,32 @@ inline CClass* GetClass(CName aTypeName) return reinterpret_cast(type); } +template +inline CEnum* GetEnum() +{ + return TypeLocator::GetEnum(); +} + +template +inline CEnum* GetEnum() +{ + constexpr auto name = GetTypeName(); + + return TypeLocator::GetEnum(); +} + +inline CEnum* GetEnum(CName aTypeName) +{ + auto type = CRTTISystem::Get()->GetType(aTypeName); + + if (!type || type->GetType() != ERTTIType::Enum) + { + return nullptr; + } + + return reinterpret_cast(type); +} + template inline CName ResolveTypeName() {