diff --git a/Redcraft.Core/Source/Public/HAL/Platform.h b/Redcraft.Core/Source/Public/HAL/Platform.h index e2afd42..265cd7a 100644 --- a/Redcraft.Core/Source/Public/HAL/Platform.h +++ b/Redcraft.Core/Source/Public/HAL/Platform.h @@ -4,10 +4,12 @@ #include #include +#include NS_REDCRAFT_BEGIN // Function type macros. + #if PLATFORM_WINDOWS #define VARARGS __cdecl @@ -43,6 +45,7 @@ NS_REDCRAFT_BEGIN #endif // Alignment. + #if defined(__clang__) #define GCC_PACK(n) __attribute__((packed,aligned(n))) @@ -60,7 +63,8 @@ NS_REDCRAFT_BEGIN #endif -// DLL export and import definitions +// DLL export and import definitions. + #if PLATFORM_WINDOWS #define DLLEXPORT __declspec(dllexport) @@ -79,32 +83,41 @@ NS_REDCRAFT_BEGIN #endif // Unsigned base types. + typedef std::uint8_t uint8; typedef std::uint16_t uint16; typedef std::uint32_t uint32; typedef std::uint64_t uint64; // Signed base types. + typedef std::int8_t int8; typedef std::int16_t int16; typedef std::int32_t int32; typedef std::int64_t int64; // Character types. + typedef char ANSICHAR; typedef wchar_t WIDECHAR; typedef WIDECHAR TCHAR; -// Pointer types +// Pointer types. + typedef std::uintptr_t uintptr_t; typedef std::intptr_t intptr_t; typedef std::size_t size_t; typedef intptr_t ssize_t; -// Null types +// Null types. + typedef decltype(NULL) null_t; typedef std::nullptr_t nullptr_t; +// Alignment. + +typedef std::max_align_t max_align_t; + #if PLATFORM_LINUX #define PLATFORM_TCHAR_IS_CHAR16 1 #else @@ -112,6 +125,7 @@ typedef std::nullptr_t nullptr_t; #endif // Define the TEXT macro. + #if PLATFORM_TCHAR_IS_CHAR16 #define TEXT_PASTE(x) u ## x #else diff --git a/Redcraft.Core/Source/Public/Misc/CoreDefines.h b/Redcraft.Core/Source/Public/Misc/CoreDefines.h index 0c608ae..ee6dfd7 100644 --- a/Redcraft.Core/Source/Public/Misc/CoreDefines.h +++ b/Redcraft.Core/Source/Public/Misc/CoreDefines.h @@ -1,13 +1,20 @@ #pragma once -#define NS_REDCRAFT RFur -#define NS_REDCRAFT_BEGIN namespace NS_REDCRAFT { -#define NS_REDCRAFT_END } -#define NS_REDCRAFT_USING using namespace NS_REDCRAFT; +#define NS_BEGIN(Name) namespace Name { +#define NS_END(Name) } +#define NS_USING(Name) using namespace Name; -#define NS_STD_BEGIN namespace std { -#define NS_STD_END } -#define NS_STD_USING using namespace std; +#define NS_REDCRAFT RFur +#define NS_REDCRAFT_BEGIN NS_BEGIN(NS_REDCRAFT) +#define NS_REDCRAFT_END NS_END(NS_REDCRAFT) +#define NS_REDCRAFT_USING NS_USING(NS_REDCRAFT) + +#define NS_STD_BEGIN NS_BEGIN(std) +#define NS_STD_END NS_END(std) +#define NS_STD_USING NS_USING(std) + +#define NS_UNNAMED_BEGIN namespace { +#define NS_UNNAMED_END } NS_REDCRAFT_BEGIN diff --git a/Redcraft.Core/Source/Public/Templates/TypeTraits.h b/Redcraft.Core/Source/Public/Templates/TypeTraits.h new file mode 100644 index 0000000..f04bb39 --- /dev/null +++ b/Redcraft.Core/Source/Public/Templates/TypeTraits.h @@ -0,0 +1,150 @@ +#pragma once + +#include "CoreTypes.h" + +#include + +NS_REDCRAFT_BEGIN +NS_BEGIN(TypeTraits) + +// Primary type categories + +template struct TIsVoid { static constexpr bool Value = std::is_void_v; }; +template struct TIsNullPointer { static constexpr bool Value = std::is_null_pointer_v; }; +template struct TIsIntegral { static constexpr bool Value = std::is_integral_v; }; +template struct TIsFloatingPoint { static constexpr bool Value = std::is_floating_point_v; }; +template struct TIsArray { static constexpr bool Value = std::is_array_v; }; +template struct TIsEnum { static constexpr bool Value = std::is_enum_v; }; +template struct TIsUnion { static constexpr bool Value = std::is_union_v; }; +template struct TIsClass { static constexpr bool Value = std::is_class_v; }; +template struct TIsFunction { static constexpr bool Value = std::is_function_v; }; +template struct TIsPointer { static constexpr bool Value = std::is_pointer_v; }; +template struct TIsLValueReference { static constexpr bool Value = std::is_lvalue_reference_v; }; +template struct TIsRValueReference { static constexpr bool Value = std::is_rvalue_reference_v; }; +template struct TIsMemberObjectPointer { static constexpr bool Value = std::is_member_object_pointer_v; }; +template struct TIsMemberFunctionPointer { static constexpr bool Value = std::is_member_function_pointer_v; }; + +// Composite type categories + +template struct TIsFundamental { static constexpr bool Value = std::is_fundamental_v; }; +template struct TIsArithmetic { static constexpr bool Value = std::is_arithmetic_v; }; +template struct TIsScalar { static constexpr bool Value = std::is_scalar_v; }; +template struct TIsObject { static constexpr bool Value = std::is_object_v; }; +template struct TIsCompound { static constexpr bool Value = std::is_compound_v; }; +template struct TIsReference { static constexpr bool Value = std::is_reference_v; }; +template struct TIsMemberPointer { static constexpr bool Value = std::is_member_pointer_v; }; + +// Type properties + +template struct TIsConst { static constexpr bool Value = std::is_const_v; }; +template struct TIsVolatile { static constexpr bool Value = std::is_volatile_v; }; +template struct TIsTrivial { static constexpr bool Value = std::is_trivial_v; }; +template struct TIsTriviallyCopyable { static constexpr bool Value = std::is_trivially_copyable_v; }; +template struct TIsStandardLayout { static constexpr bool Value = std::is_standard_layout_v; }; +template struct THasUniqueObjectRepresentations { static constexpr bool Value = std::has_unique_object_representations_v; }; +template struct TIsEmpty { static constexpr bool Value = std::is_empty_v; }; +template struct TIsPolymorphic { static constexpr bool Value = std::is_polymorphic_v; }; +template struct TIsAbstract { static constexpr bool Value = std::is_abstract_v; }; +template struct TIsFinal { static constexpr bool Value = std::is_final_v; }; +template struct TIsAggregate { static constexpr bool Value = std::is_aggregate_v; }; +template struct TIsSigned { static constexpr bool Value = std::is_signed_v; }; +template struct TIsUnsigned { static constexpr bool Value = std::is_unsigned_v; }; +template struct TIsBoundedArray { static constexpr bool Value = std::is_bounded_array_v; }; +template struct TIsUnboundedArray { static constexpr bool Value = std::is_unbounded_array_v; }; + +// Supported operations + +template struct TIsConstructible { static constexpr bool Value = std::is_constructible_v; }; +template struct TIsTriviallyConstructible { static constexpr bool Value = std::is_trivially_constructible_v; }; +template struct TIsDefaultConstructible { static constexpr bool Value = std::is_default_constructible_v; }; +template struct TIsTriviallyDefaultConstructible { static constexpr bool Value = std::is_trivially_default_constructible_v; }; +template struct TIsCopyConstructible { static constexpr bool Value = std::is_copy_constructible_v; }; +template struct TIsTriviallyCopyConstructible { static constexpr bool Value = std::is_trivially_copy_constructible_v; }; +template struct TIsMoveConstructible { static constexpr bool Value = std::is_move_constructible_v; }; +template struct TIsTriviallyMoveConstructible { static constexpr bool Value = std::is_trivially_move_constructible_v; }; +template struct TIsAssignable { static constexpr bool Value = std::is_assignable_v; }; +template struct TIsTriviallyAssignable { static constexpr bool Value = std::is_trivially_assignable_v; }; +template struct TIsCopyAssignable { static constexpr bool Value = std::is_copy_assignable_v; }; +template struct TIsTriviallyCopyAssignable { static constexpr bool Value = std::is_trivially_copy_assignable_v; }; +template struct TIsMoveAssignable { static constexpr bool Value = std::is_move_assignable_v; }; +template struct TIsTriviallyMoveAssignable { static constexpr bool Value = std::is_trivially_move_assignable_v; }; +template struct TIsDestructible { static constexpr bool Value = std::is_destructible_v; }; +template struct TIsTriviallyDestructible { static constexpr bool Value = std::is_trivially_destructible_v; }; +template struct THasVirtualDestructor { static constexpr bool Value = std::has_virtual_destructor_v; }; +template struct TIsSwappableWith { static constexpr bool Value = std::is_swappable_with_v; }; +template struct TIsSwappable { static constexpr bool Value = std::is_swappable_v; }; + +// Property queries + +template struct TRank { static constexpr size_t Value = std::rank_v; }; +template struct TExtent { static constexpr size_t Value = std::extent_v; }; + +// Type relationships + +template struct TIsSame { static constexpr bool Value = std::is_same_v; }; +template struct TIsBaseOf { static constexpr bool Value = std::is_base_of_v; }; +template struct TIsConvertible { static constexpr bool Value = std::is_convertible_v; }; +template struct TIsLayoutCompatible { static constexpr bool Value = std::is_layout_compatible_v; }; +template struct TIsInvocable { static constexpr bool Value = std::is_invocable_v; }; +template struct TIsInvocableResult { static constexpr bool Value = std::is_invocable_r_v; }; + +// Const-volatility specifiers + +template struct TRemoveCV { typedef typename std::remove_cv_t Type; }; +template struct TRemoveConst { typedef typename std::remove_const Type; }; +template struct TRemoveVolatile { typedef typename std::remove_volatile Type; }; +template struct TAddCV { typedef typename std::add_cv Type; }; +template struct TAddConst { typedef typename std::add_const Type; }; +template struct TAddVolatile { typedef typename std::add_volatile Type; }; + +// References + +template struct TRemoveReference { typedef typename std::remove_reference_t Type; }; +template struct TAddLValueReference { typedef typename std::add_lvalue_reference_t Type; }; +template struct TAddRValueReference { typedef typename std::add_rvalue_reference_t Type; }; + +// Pointers + +template struct TRemovePointer { typedef typename std::remove_pointer_t Type; }; +template struct TAddPointer { typedef typename std::add_pointer_t Type; }; + +// Sign modifiers + +template struct TMakeSigned { typedef typename std::make_signed_t Type; }; +template struct TMakeUnsigned { typedef typename std::make_unsigned_t Type; }; + +// Arrays + +template struct TRemoveExtent { typedef typename std::remove_extent_t Type; }; +template struct TRemoveAllExtents { typedef typename std::remove_all_extents_t Type; }; + +// Miscellaneous transformations + +template struct TAlignedStorage { typedef typename std::aligned_storage_t Type; }; +template struct TAlignedUnion { typedef typename std::aligned_union_t Type; }; +template struct TDecay { typedef typename std::decay_t Type; }; +template struct TRemoveCVRef { typedef typename std::remove_cvref_t Type; }; +template struct TConditional { typedef typename std::conditional_t Type; }; +template struct TCommonType { typedef typename std::common_type_t Type; }; +template struct TUnderlyingType { typedef typename std::underlying_type_t Type; }; +template struct TInvokeResult { typedef typename std::invoke_result_t Type; }; + +// Operations on traits + +template struct TConstant { static constexpr T Value = InValue; }; +template struct TBoolConstant : TConstant { }; + +template struct TAnd; +template struct TAnd, RHS...> { static constexpr bool Value = TAnd::Value; }; +template struct TAnd, RHS...> { static constexpr bool Value = false; }; +template <> struct TAnd<> { static constexpr bool Value = true; }; + +template struct TOr; +template struct TOr, RHS...> { static constexpr bool Value = true; }; +template struct TOr, RHS...> { static constexpr bool Value = TOr::Value; }; +template <> struct TOr<> { static constexpr bool Value = false; }; + +template struct TNot { static constexpr bool Value = !Type::Value; }; + +NS_END(TypeTraits) +NS_REDCRAFT_END