Skip to content

Commit

Permalink
Update shared lib
Browse files Browse the repository at this point in the history
  • Loading branch information
psiberx committed Aug 4, 2023
1 parent e358126 commit a34758b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/Core/Raw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,13 @@ class OffsetPtr
static constexpr uintptr_t offset = A;
static constexpr bool indirect = std::is_pointer_v<T>;

constexpr OffsetPtr(uintptr_t aBase)
: addr(aBase + offset)
{
}

constexpr OffsetPtr(void* aBase)
: base(reinterpret_cast<uintptr_t>(aBase))
: addr(reinterpret_cast<uintptr_t>(aBase) + offset)
{
}

Expand Down Expand Up @@ -229,7 +234,7 @@ class OffsetPtr

[[nodiscard]] inline uintptr_t GetAddress() const noexcept
{
return base + offset;
return addr;
}

inline static Type* Get(void* aBase)
Expand All @@ -242,6 +247,6 @@ class OffsetPtr
return OffsetPtr(aBase);
}

uintptr_t base;
uintptr_t addr;
};
}
46 changes: 46 additions & 0 deletions lib/Red/TypeInfo/Definition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -1182,4 +1209,23 @@ struct GlobalDefinition
return AScope;
}
};

template<typename T>
inline auto GetDescriptor()
{
auto rtti = CRTTISystem::Get();

if constexpr (std::is_class_v<T>)
{
return reinterpret_cast<ClassDescriptor<T>*>(rtti->GetClass(GetTypeName<T>()));
}
else if constexpr (std::is_enum_v<T>)
{
return reinterpret_cast<EnumDescriptor<T>*>(rtti->GetEnum(GetTypeName<T>()));
}
else
{
return rtti->GetType(GetTypeName<T>());
}
}
}
41 changes: 41 additions & 0 deletions lib/Red/TypeInfo/Resolving.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,21 @@ class TypeLocator
return reinterpret_cast<CRTTIArrayType*>(s_type);
}

static inline CEnum* GetEnum()
{
if (!s_resolved)
{
Resolve();
}

if (!s_type || s_type->GetType() != ERTTIType::Enum)
{
return nullptr;
}

return reinterpret_cast<CEnum*>(s_type);
}

static inline bool IsDefined()
{
if (!s_resolved)
Expand Down Expand Up @@ -397,6 +412,32 @@ inline CClass* GetClass(CName aTypeName)
return reinterpret_cast<CClass*>(type);
}

template<CName AType>
inline CEnum* GetEnum()
{
return TypeLocator<AType>::GetEnum();
}

template<typename TType>
inline CEnum* GetEnum()
{
constexpr auto name = GetTypeName<TType>();

return TypeLocator<name>::GetEnum();
}

inline CEnum* GetEnum(CName aTypeName)
{
auto type = CRTTISystem::Get()->GetType(aTypeName);

if (!type || type->GetType() != ERTTIType::Enum)
{
return nullptr;
}

return reinterpret_cast<CEnum*>(type);
}

template<typename T>
inline CName ResolveTypeName()
{
Expand Down

0 comments on commit a34758b

Please sign in to comment.