feat(miscellaneous): add FTypeInfo and the corresponding testing
This commit is contained in:
51
Redcraft.Utility/Source/Public/Miscellaneous/TypeInfo.h
Normal file
51
Redcraft.Utility/Source/Public/Miscellaneous/TypeInfo.h
Normal file
@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "Miscellaneous/Compare.h"
|
||||
#include "Miscellaneous/Placeholders.h"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
NAMESPACE_MODULE_BEGIN(Utility)
|
||||
|
||||
struct FTypeInfo
|
||||
{
|
||||
constexpr FTypeInfo() : FTypeInfo(typeid(void)) { }
|
||||
|
||||
constexpr FTypeInfo(FInvalid) : FTypeInfo() { }
|
||||
|
||||
constexpr FTypeInfo(const std::type_info& InTypeInfo) : Ptr(&InTypeInfo) { }
|
||||
|
||||
size_t GetTypeHash() const { return Ptr->hash_code(); }
|
||||
|
||||
const char* GetName() const { return Ptr->name(); }
|
||||
|
||||
private:
|
||||
|
||||
const std::type_info* Ptr;
|
||||
|
||||
friend bool operator==(FTypeInfo LHS, FTypeInfo RHS) { return *LHS.Ptr == *RHS.Ptr; }
|
||||
|
||||
friend bool operator<(FTypeInfo LHS, FTypeInfo RHS) { return LHS.Ptr->before(*RHS.Ptr); }
|
||||
|
||||
friend bool operator<=(FTypeInfo LHS, FTypeInfo RHS) { return LHS == RHS || LHS.Ptr->before(*RHS.Ptr); }
|
||||
|
||||
friend bool operator>=(FTypeInfo LHS, FTypeInfo RHS) { return LHS == RHS || !LHS.Ptr->before(*RHS.Ptr); }
|
||||
|
||||
friend bool operator>(FTypeInfo LHS, FTypeInfo RHS) { return !LHS.Ptr->before(*RHS.Ptr); }
|
||||
|
||||
friend strong_ordering operator<=>(FTypeInfo LHS, FTypeInfo RHS)
|
||||
{
|
||||
if (LHS == RHS) return strong_ordering::equal;
|
||||
return LHS < RHS ? strong_ordering::less : strong_ordering::greater;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#define Typeid(...) (FTypeInfo(typeid(__VA_ARGS__)))
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
NAMESPACE_REDCRAFT_END
|
@ -9,6 +9,7 @@ NAMESPACE_MODULE_BEGIN(Utility)
|
||||
REDCRAFTUTILITY_API void TestMiscellaneous();
|
||||
REDCRAFTUTILITY_API void TestAssertionMacros();
|
||||
REDCRAFTUTILITY_API void TestCompare();
|
||||
REDCRAFTUTILITY_API void TestTypeInfo();
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
|
Reference in New Issue
Block a user