调整结构 将 Core 的工作转到 Utility 上来

This commit is contained in:
_Redstone_c_ 2021-11-28 18:19:13 +08:00
parent 83be3aa142
commit 152ae5605d
17 changed files with 10 additions and 1025 deletions

View File

@ -1,7 +1,9 @@
cmake_minimum_required (VERSION 3.8)
# Main project
project ("Redcraft")
string(REGEX REPLACE ".*/(.*)" "\\1" CURRENT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR})
project (${CURRENT_FOLDER})
message (STATUS "Configuring project: " ${CURRENT_FOLDER})
# Reset the binary file directory
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Build")
@ -38,7 +40,6 @@ foreach (PROJECT_SUBDIRECTORY ${PROJECT_FOLDERS})
if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_SUBDIRECTORY}")
file (GLOB PROJECT_CMAKELISTS "${PROJECT_SUBDIRECTORY}/CMakeLists.txt")
if (NOT "${PROJECT_CMAKELISTS}" STREQUAL "")
message (STATUS "Add subdirectory: " ${PROJECT_SUBDIRECTORY})
add_subdirectory (${PROJECT_SUBDIRECTORY})
endif ()
endif ()

View File

@ -1,75 +0,0 @@
#include "HAL/Memory.h"
#include "Templates/Alignment.h"
#if PLATFORM_WINDOWS
#include <corecrt_malloc.h>
#endif
NS_REDCRAFT_BEGIN
NS_BEGIN(Memory)
void* Malloc(size_t Count, uint32 Alignment)
{
Alignment = Math::Max(Count >= 16 ? (uint32)16 : (uint32)8, Alignment);
void* Result = nullptr;
#if PLATFORM_WINDOWS
if (Count != 0) Result = _aligned_malloc(Count, Alignment);
#else
void* Ptr = SystemMalloc(Count + Alignment + sizeof(void*) + sizeof(size_t));
if (Ptr)
{
Result = Align((uint8*)Ptr + sizeof(void*) + sizeof(size_t), Alignment);
*((void**)((uint8*)Result - sizeof(void*))) = Ptr;
*((size_t*)((uint8*)Result - sizeof(void*) - sizeof(size_t))) = Count;
}
#endif
return Result;
}
void* Realloc(void* Ptr, size_t Count, uint32 Alignment)
{
Alignment = Math::Max(Count >= 16 ? (uint32)16 : (uint32)8, Alignment);
if (Ptr && Count)
{
#if PLATFORM_WINDOWS
return _aligned_realloc(Ptr, Count, Alignment);
#else
void* Result = Malloc(Count, Alignment);
size_t PtrSize = *((size_t*)((uint8*)Ptr - sizeof(void*) - sizeof(size_t)));
Memcpy(Result, Ptr, Math::Min(Count, PtrSize));
Free(Ptr);
return Result;
#endif
}
else if (Ptr == nullptr)
{
return Malloc(Count, Alignment);
}
else
{
Free(Ptr);
return nullptr;
}
}
void Free(void* Ptr)
{
#if PLATFORM_WINDOWS
_aligned_free(Ptr);
#else
SystemFree(*((void**)((uint8*)Ptr - sizeof(void*))));
#endif
}
size_t QuantizeSize(size_t Count, uint32 Alignment)
{
return Count;
}
NS_END(Memory)
NS_REDCRAFT_END

View File

@ -1,5 +0,0 @@
#pragma once
#include "CoreTypes.h"
#include "Templates/MemoryOps.h"
#include "Misc/AssertionMacros.h"

View File

@ -1,4 +0,0 @@
#pragma once
#include "HAL/Platform.h"
#include "Misc/CoreDefines.h"

View File

@ -1,43 +0,0 @@
#pragma once
#include "CoreTypes.h"
NS_REDCRAFT_BEGIN
NS_BEGIN(Memory)
constexpr uint32 DEFAULT_ALIGNMENT = 0;
constexpr uint32 MIN_ALIGNMENT = 8;
FORCEINLINE void* Memmove(void* Dest, const void* Src, size_t Count);
FORCEINLINE int32 Memcmp(const void* Buf1, const void* Buf2, size_t Count);
FORCEINLINE void Memset(void* Dest, uint8 ValueToSet, size_t Count);
FORCEINLINE void* Memzero(void* Dest, size_t Count);
FORCEINLINE void* Memcpy(void* Dest, const void* Src, size_t Count);
template<typename T>
static FORCEINLINE void Memset(T& Src, uint8 ValueToSet);
template<typename T>
static FORCEINLINE void Memzero(T& Src);
template<typename T>
static FORCEINLINE void Memcpy(T& Dest, const T& Src);
FORCEINLINE void* SystemMalloc(size_t Count);
FORCEINLINE void SystemFree(void* Ptr);
REDCRAFTCORE_API void* Malloc(size_t Count, uint32 Alignment = DEFAULT_ALIGNMENT);
REDCRAFTCORE_API void* Realloc(void* Ptr, size_t Count, uint32 Alignment = DEFAULT_ALIGNMENT);
REDCRAFTCORE_API void Free(void* Ptr);
REDCRAFTCORE_API size_t QuantizeSize(size_t Count, uint32 Alignment = DEFAULT_ALIGNMENT);
NS_END(Memory)
NS_REDCRAFT_END
#include "HAL/Memory.inl"
void* operator new(std::size_t Count) { return NS_REDCRAFT::Memory::Malloc(Count); };
void* operator new(std::size_t Count, std::align_val_t Alignment) { return NS_REDCRAFT::Memory::Malloc(Count, (NS_REDCRAFT::uint32)Alignment); };
void operator delete(void* Ptr) noexcept { NS_REDCRAFT::Memory::Free(Ptr); }
void operator delete(void* Ptr, std::align_val_t Alignment) noexcept { NS_REDCRAFT::Memory::Free(Ptr); }

View File

@ -1,67 +0,0 @@
#include "Math/MathUtility.h"
#include "Templates/TypeTraits.h"
#include <cstring>
#include <cstdlib>
NS_REDCRAFT_BEGIN
NS_BEGIN(Memory)
FORCEINLINE void* Memmove(void* Dest, const void* Src, size_t Count)
{
return std::memmove(Dest, Src, Count);
}
FORCEINLINE int32 Memcmp(const void* Buf1, const void* Buf2, size_t Count)
{
return std::memcmp(Buf1, Buf2, Count);
}
FORCEINLINE void Memset(void* Dest, uint8 ValueToSet, size_t Count)
{
std::memset(Dest, ValueToSet, Count);
}
FORCEINLINE void* Memzero(void* Dest, size_t Count)
{
return std::memset(Dest, 0, Count);
}
FORCEINLINE void* Memcpy(void* Dest, const void* Src, size_t Count)
{
return std::memcpy(Dest, Src, Count);
}
template<typename T>
static FORCEINLINE void Memset(T& Src, uint8 ValueToSet)
{
static_assert(!TypeTraits::TIsPointer<T>::Value, "For pointers use the three parameters function");
Memset(&Src, ValueToSet, sizeof(T));
}
template<typename T>
static FORCEINLINE void Memzero(T& Src)
{
static_assert(!TypeTraits::TIsPointer<T>::Value, "For pointers use the two parameters function");
Memzero(&Src, sizeof(T));
}
template<typename T>
static FORCEINLINE void Memcpy(T& Dest, const T& Src)
{
static_assert(!TypeTraits::TIsPointer<T>::Value, "For pointers use the three parameters function");
Memcpy(&Dest, &Src, sizeof(T));
}
FORCEINLINE void* SystemMalloc(size_t Count)
{
return std::malloc(Count);
}
FORCEINLINE void SystemFree(void* Ptr)
{
std::free(Ptr);
}
NS_END(Memory)
NS_REDCRAFT_END

View File

@ -1,183 +0,0 @@
#pragma once
#include "Misc/CoreDefines.h"
#include <new>
#include <cstdint>
#include <cstdlib>
#include <cstddef>
NS_REDCRAFT_BEGIN
// Build information macro.
#ifndef PLATFORM_NAME
#define PLATFORM_NAME Unknown
#endif
#ifndef PLATFORM_WINDOWS
#define PLATFORM_WINDOWS 0
#endif
#ifndef PLATFORM_LINUX
#define PLATFORM_LINUX 0
#endif
#ifndef PLATFORM_UNKNOWN
#define PLATFORM_UNKNOWN 0
#endif
#ifndef BUILD_TYPE
#define BUILD_TYPE Unknown
#endif
#ifndef BUILD_DEBUG
#define BUILD_DEBUG 0
#endif
#ifndef BUILD_RELEASE
#define BUILD_RELEASE 0
#endif
#ifndef BUILD_UNKNOWN
#define BUILD_UNKNOWN 0
#endif
// Function type macros.
#if PLATFORM_WINDOWS
#define VARARGS __cdecl
#define CDECL __cdecl
#define STDCALL __stdcall
#define FORCEINLINE __forceinline
#define FORCENOINLINE __declspec(noinline)
#define RESTRICT __restrict
#elif PLATFORM_LINUX
#define VARARGS
#define CDECL
#define STDCALL
#define FORCENOINLINE __attribute__((noinline))
#define RESTRICT __restrict
#if BUILD_DEBUG
#define FORCEINLINE inline
#else
#define FORCEINLINE inline __attribute__ ((always_inline))
#endif
#else
#define VARARGS
#define CDECL
#define STDCALL
#define FORCEINLINE
#define FORCENOINLINE
#define RESTRICT __restrict
#endif
// Alignment.
#if PLATFORM_WINDOWS
#if defined(__clang__)
#define GCC_PACK(n) __attribute__((packed,aligned(n)))
#define GCC_ALIGN(n) __attribute__((aligned(n)))
#if defined(_MSC_VER)
#define MS_ALIGN(n) __declspec(align(n))
#endif
#else
#define GCC_PACK(n)
#define GCC_ALIGN(n)
#define MS_ALIGN(n) __declspec(align(n))
#endif
#elif PLATFORM_LINUX
#define GCC_PACK(n) __attribute__((packed,aligned(n)))
#define GCC_ALIGN(n) __attribute__((aligned(n)))
#define MS_ALIGN(n)
#else
#define GCC_PACK(n)
#define GCC_ALIGN(n)
#define MS_ALIGN(n)
#endif
// DLL export and import definitions.
#if PLATFORM_WINDOWS
#define DLLEXPORT __declspec(dllexport)
#define DLLIMPORT __declspec(dllimport)
#elif PLATFORM_LINUX
#define DLLEXPORT __attribute__((visibility("default")))
#define DLLIMPORT __attribute__((visibility("default")))
#else
#define DLLEXPORT
#define DLLIMPORT
#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.
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.
typedef decltype(NULL) null_t;
typedef std::nullptr_t nullptr_t;
#if PLATFORM_LINUX
#define PLATFORM_TCHAR_IS_CHAR16 1
#else
#define PLATFORM_TCHAR_IS_CHAR16 0
#endif
// Define the TEXT macro.
#if PLATFORM_TCHAR_IS_CHAR16
#define TEXT_PASTE(x) u ## x
#else
#define TEXT_PASTE(x) L ## x
#endif
#define TEXT(x) TEXT_PASTE(x)
NS_REDCRAFT_END

View File

@ -1,33 +0,0 @@
#pragma once
#include "CoreTypes.h"
NS_REDCRAFT_BEGIN
NS_BEGIN(Math)
template <typename T>
static constexpr FORCEINLINE T Abs(const T A)
{
return (A >= (T)0) ? A : -A;
}
template <typename T>
static constexpr FORCEINLINE T Sign(const T A)
{
return (A > (T)0) ? (T)1 : ((A < (T)0) ? (T)-1 : (T)0);
}
template <typename T>
static constexpr FORCEINLINE T Max(const T A, const T B)
{
return (A >= B) ? A : B;
}
template <typename T>
static constexpr FORCEINLINE T Min(const T A, const T B)
{
return (A <= B) ? A : B;
}
NS_END(Math)
NS_REDCRAFT_END

View File

@ -1,52 +0,0 @@
#pragma once
#include "CoreTypes.h"
#include <cassert>
NS_REDCRAFT_BEGIN
NS_PRIVATE_BEGIN
class FRecursionScopeMarker
{
public:
FRecursionScopeMarker(uint8& InCounter) : Counter(InCounter) { ++Counter; }
~FRecursionScopeMarker() { --Counter; }
private:
uint8& Counter;
};
NS_PRIVATE_END
#if BUILD_DEBUG
#define check_code(InCode) do { InCode; } while (false)
#define check(InExpr) assert(InExpr)
#define checkf(InExpr, InFormat, ...) assert(InExpr)
#define check_no_entry() checkf(false, "Enclosing block should never be called.")
#define check_no_reentry() { static bool bBeenHere##__LINE__ = false; checkf(!bBeenHere##__LINE__, "Enclosing block was called more than once."); bBeenHere##__LINE__ = true; }
#define check_no_recursion() static uint8 RecursionCounter##__LINE__ = 0; checkf(RecursionCounter##__LINE__ == 0, "Enclosing block was entered recursively."); const NS_PRIVATE::FRecursionScopeMarker ScopeMarker##__LINE__(RecursionCounter##__LINE__)
#define verify(InExpr) assert(InExpr)
#define verifyf(InExpr, InFormat, ...) assert(InExpr)
#define unimplemented() check(false, "Unimplemented function called.")
#else
#define check_code(...)
#define check(InExpr)
#define checkf(InExpr, InFormat, ...)
#define check_no_entry()
#define check_no_reentry()
#define check_no_recursion()
#define verify(InExpr) { if(InExpr) { } }
#define verifyf(InExpr, InFormat, ...) { if(InExpr) { } }
#define unimplemented()
#endif
NS_REDCRAFT_END

View File

@ -1,30 +0,0 @@
#pragma once
#define NS_BEGIN(Name) namespace Name {
#define NS_END(Name) }
#define NS_USING(Name) using namespace Name;
#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_PRIVATE Private
#define NS_PRIVATE_BEGIN NS_BEGIN(NS_PRIVATE)
#define NS_PRIVATE_END NS_END(NS_PRIVATE)
#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
enum { INDEX_NONE = -1 };
enum { UNICODE_BOM = 0xfeff };
enum EForceInit { ForceInit };
NS_REDCRAFT_END

View File

@ -1,44 +0,0 @@
#pragma once
#pragma once
#include "CoreTypes.h"
#include "Templates/TypeTraits.h"
NS_REDCRAFT_BEGIN
NS_BEGIN(Memory)
template <typename T>
FORCEINLINE constexpr T Align(T Val, uint64 Alignment)
{
static_assert(TypeTraits::TIsIntegral<T>::Value || TypeTraits::TIsPointer<T>::Value, "Align expects an integer or pointer type");
return (T)(((uint64)Val + Alignment - 1) & ~(Alignment - 1));
}
template <typename T>
FORCEINLINE constexpr T AlignDown(T Val, uint64 Alignment)
{
static_assert(TypeTraits::TIsIntegral<T>::Value || TypeTraits::TIsPointer<T>::Value, "AlignDown expects an integer or pointer type");
return (T)(((uint64)Val) & ~(Alignment - 1));
}
template <typename T>
FORCEINLINE constexpr bool IsAligned(T Val, uint64 Alignment)
{
static_assert(TypeTraits::TIsIntegral<T>::Value || TypeTraits::TIsPointer<T>::Value, "IsAligned expects an integer or pointer type");
return !((uint64)Val & (Alignment - 1));
}
template <typename T>
FORCEINLINE constexpr T AlignArbitrary(T Val, uint64 Alignment)
{
static_assert(TypeTraits::TIsIntegral<T>::Value || TypeTraits::TIsPointer<T>::Value, "AlignArbitrary expects an integer or pointer type");
return (T)((((uint64)Val + Alignment - 1) / Alignment) * Alignment);
}
NS_END(Memory)
NS_REDCRAFT_END

View File

@ -1,35 +0,0 @@
#pragma once
#include "CoreTypes.h"
NS_REDCRAFT_BEGIN
NS_BEGIN(Memory)
template <typename ElementType, typename SizeType>
FORCEINLINE void DefaultConstructItems(void* Address, SizeType Count = 1);
template <typename ElementType, typename SizeType>
FORCEINLINE void DestructItems(ElementType* Element, SizeType Count = 1);
template <typename DestinationElementType, typename SourceElementType, typename SizeType>
FORCEINLINE void ConstructItems(void* Dest, const SourceElementType* Source, SizeType Count = 1);
template <typename ElementType, typename SizeType>
FORCEINLINE void CopyAssignItems(ElementType* Dest, const ElementType* Source, SizeType Count = 1);
template <typename DestinationElementType, typename SourceElementType, typename SizeType>
FORCEINLINE void RelocateConstructItems(void* Dest, const SourceElementType* Source, SizeType Count = 1);
template <typename ElementType, typename SizeType>
FORCEINLINE void MoveConstructItems(void* Dest, const ElementType* Source, SizeType Count = 1);
template <typename ElementType, typename SizeType>
FORCEINLINE void MoveAssignItems(ElementType* Dest, const ElementType* Source, SizeType Count = 1);
template <typename ElementType, typename SizeType>
FORCEINLINE bool CompareItems(const ElementType* A, const ElementType* B, SizeType Count = 1);
NS_END(Memory)
NS_REDCRAFT_END
#include "Templates/MemoryOps.inl"

View File

@ -1,186 +0,0 @@
#include "HAL/Memory.h"
#include "Templates/TypeTraits.h"
#include "MemoryOps.h"
NS_REDCRAFT_BEGIN
NS_BEGIN(Memory)
NS_PRIVATE_BEGIN
template <typename DestinationElementType, typename SourceElementType>
struct TCanBitwiseRelocate
{
enum
{
Value =
TypeTraits::TOr<
TypeTraits::TIsSame<DestinationElementType, SourceElementType>,
TypeTraits::TAnd<
TypeTraits::TIsBitwiseConstructible<DestinationElementType, SourceElementType>,
TypeTraits::TIsTriviallyDestructible<SourceElementType>
>
>::Value
};
};
NS_PRIVATE_END
template<typename ElementType, typename SizeType>
FORCEINLINE void DefaultConstructItems(void* Address, SizeType Count)
{
if constexpr (TypeTraits::TIsZeroConstructType<ElementType>::Value)
{
Memory::Memset(Address, 0, sizeof(ElementType) * Count);
}
else
{
ElementType* Element = (ElementType*)Address;
while (Count)
{
new (Element) ElementType;
++Element;
--Count;
}
}
}
template<typename ElementType, typename SizeType>
FORCEINLINE void DestructItems(ElementType* Element, SizeType Count)
{
if constexpr (!TypeTraits::TIsTriviallyDestructible<ElementType>::Value)
{
while (Count)
{
typedef ElementType DestructItemsElementTypeTypedef;
Element->DestructItemsElementTypeTypedef::~DestructItemsElementTypeTypedef();
++Element;
--Count;
}
}
}
template<typename DestinationElementType, typename SourceElementType, typename SizeType>
FORCEINLINE void ConstructItems(void* Dest, const SourceElementType* Source, SizeType Count)
{
if constexpr (TypeTraits::TIsBitwiseConstructible<DestinationElementType, SourceElementType>::Value)
{
Memory::Memcpy(Dest, Source, sizeof(SourceElementType) * Count);
}
else
{
while (Count)
{
new (Dest) DestinationElementType(*Source);
++(DestinationElementType*&)Dest;
++Source;
--Count;
}
}
}
template<typename ElementType, typename SizeType>
FORCEINLINE void CopyAssignItems(ElementType* Dest, const ElementType* Source, SizeType Count)
{
if constexpr (TypeTraits::TIsTriviallyCopyAssignable<ElementType>::Value)
{
Memory::Memcpy(Dest, Source, sizeof(ElementType) * Count);
}
else
{
while (Count)
{
*Dest = *Source;
++Dest;
++Source;
--Count;
}
}
}
template<typename DestinationElementType, typename SourceElementType, typename SizeType>
FORCEINLINE void RelocateConstructItems(void* Dest, const SourceElementType* Source, SizeType Count)
{
if constexpr (NS_PRIVATE::TCanBitwiseRelocate<DestinationElementType, SourceElementType>::Value)
{
Memory::Memmove(Dest, Source, sizeof(SourceElementType) * Count);
}
else
{
while (Count)
{
typedef SourceElementType RelocateConstructItemsElementTypeTypedef;
new (Dest) DestinationElementType(*Source);
++(DestinationElementType*&)Dest;
(Source++)->RelocateConstructItemsElementTypeTypedef::~RelocateConstructItemsElementTypeTypedef();
--Count;
}
}
}
template<typename ElementType, typename SizeType>
FORCEINLINE void MoveConstructItems(void* Dest, const ElementType* Source, SizeType Count)
{
if constexpr (TypeTraits::TIsTriviallyCopyConstructible<ElementType>::Value)
{
Memory::Memmove(Dest, Source, sizeof(ElementType) * Count);
}
else
{
while (Count)
{
new (Dest) ElementType((ElementType&&)*Source);
++(ElementType*&)Dest;
++Source;
--Count;
}
}
}
template<typename ElementType, typename SizeType>
FORCEINLINE void MoveAssignItems(ElementType* Dest, const ElementType* Source, SizeType Count)
{
if constexpr (TypeTraits::TIsTriviallyCopyAssignable<ElementType>::Value)
{
Memory::Memmove(Dest, Source, sizeof(ElementType) * Count);
}
else
{
while (Count)
{
*Dest = (ElementType&&)*Source;
++Dest;
++Source;
--Count;
}
}
}
template<typename ElementType, typename SizeType>
FORCEINLINE bool CompareItems(const ElementType* A, const ElementType* B, SizeType Count)
{
if constexpr (TypeTraits::TCanBitwiseCompare<ElementType>::Value)
{
return !Memory::Memcmp(A, B, sizeof(ElementType) * Count);
}
else
{
while (Count)
{
if (!(*A == *B))
{
return false;
}
++A;
++B;
--Count;
}
return true;
}
}
NS_END(Memory)
NS_REDCRAFT_END

View File

@ -1,202 +0,0 @@
#pragma once
#include "CoreTypes.h"
#include <type_traits>
NS_REDCRAFT_BEGIN
NS_BEGIN(TypeTraits)
// Primary type categories.
template <typename T> struct TIsVoid { static constexpr bool Value = std::is_void_v<T>; };
template <typename T> struct TIsNullPointer { static constexpr bool Value = std::is_null_pointer_v<T>; };
template <typename T> struct TIsIntegral { static constexpr bool Value = std::is_integral_v<T>; };
template <typename T> struct TIsFloatingPoint { static constexpr bool Value = std::is_floating_point_v<T>; };
template <typename T> struct TIsArray { static constexpr bool Value = std::is_array_v<T>; };
template <typename T> struct TIsEnum { static constexpr bool Value = std::is_enum_v<T>; };
template <typename T> struct TIsUnion { static constexpr bool Value = std::is_union_v<T>; };
template <typename T> struct TIsClass { static constexpr bool Value = std::is_class_v<T>; };
template <typename T> struct TIsFunction { static constexpr bool Value = std::is_function_v<T>; };
template <typename T> struct TIsPointer { static constexpr bool Value = std::is_pointer_v<T>; };
template <typename T> struct TIsLValueReference { static constexpr bool Value = std::is_lvalue_reference_v<T>; };
template <typename T> struct TIsRValueReference { static constexpr bool Value = std::is_rvalue_reference_v<T>; };
template <typename T> struct TIsMemberObjectPointer { static constexpr bool Value = std::is_member_object_pointer_v<T>; };
template <typename T> struct TIsMemberFunctionPointer { static constexpr bool Value = std::is_member_function_pointer_v<T>; };
// Composite type categories.
template <typename T> struct TIsFundamental { static constexpr bool Value = std::is_fundamental_v<T>; };
template <typename T> struct TIsArithmetic { static constexpr bool Value = std::is_arithmetic_v<T>; };
template <typename T> struct TIsScalar { static constexpr bool Value = std::is_scalar_v<T>; };
template <typename T> struct TIsObject { static constexpr bool Value = std::is_object_v<T>; };
template <typename T> struct TIsCompound { static constexpr bool Value = std::is_compound_v<T>; };
template <typename T> struct TIsReference { static constexpr bool Value = std::is_reference_v<T>; };
template <typename T> struct TIsMemberPointer { static constexpr bool Value = std::is_member_pointer_v<T>; };
// Type properties.
template <typename T> struct TIsConst { static constexpr bool Value = std::is_const_v<T>; };
template <typename T> struct TIsVolatile { static constexpr bool Value = std::is_volatile_v<T>; };
template <typename T> struct TIsTrivial { static constexpr bool Value = std::is_trivial_v<T>; };
template <typename T> struct TIsTriviallyCopyable { static constexpr bool Value = std::is_trivially_copyable_v<T>; };
template <typename T> struct TIsStandardLayout { static constexpr bool Value = std::is_standard_layout_v<T>; };
template <typename T> struct THasUniqueObjectRepresentations { static constexpr bool Value = std::has_unique_object_representations_v<T>; };
template <typename T> struct TIsEmpty { static constexpr bool Value = std::is_empty_v<T>; };
template <typename T> struct TIsPolymorphic { static constexpr bool Value = std::is_polymorphic_v<T>; };
template <typename T> struct TIsAbstract { static constexpr bool Value = std::is_abstract_v<T>; };
template <typename T> struct TIsFinal { static constexpr bool Value = std::is_final_v<T>; };
template <typename T> struct TIsAggregate { static constexpr bool Value = std::is_aggregate_v<T>; };
template <typename T> struct TIsSigned { static constexpr bool Value = std::is_signed_v<T>; };
template <typename T> struct TIsUnsigned { static constexpr bool Value = std::is_unsigned_v<T>; };
template <typename T> struct TIsBoundedArray { static constexpr bool Value = std::is_bounded_array_v<T>; };
template <typename T> struct TIsUnboundedArray { static constexpr bool Value = std::is_unbounded_array_v<T>; };
// Supported operations.
template <typename T> struct TIsConstructible { static constexpr bool Value = std::is_constructible_v<T>; };
template <typename T> struct TIsTriviallyConstructible { static constexpr bool Value = std::is_trivially_constructible_v<T>; };
template <typename T> struct TIsDefaultConstructible { static constexpr bool Value = std::is_default_constructible_v<T>; };
template <typename T> struct TIsTriviallyDefaultConstructible { static constexpr bool Value = std::is_trivially_default_constructible_v<T>; };
template <typename T> struct TIsCopyConstructible { static constexpr bool Value = std::is_copy_constructible_v<T>; };
template <typename T> struct TIsTriviallyCopyConstructible { static constexpr bool Value = std::is_trivially_copy_constructible_v<T>; };
template <typename T> struct TIsMoveConstructible { static constexpr bool Value = std::is_move_constructible_v<T>; };
template <typename T> struct TIsTriviallyMoveConstructible { static constexpr bool Value = std::is_trivially_move_constructible_v<T>; };
template <typename T> struct TIsAssignable { static constexpr bool Value = std::is_assignable_v<T>; };
template <typename T> struct TIsTriviallyAssignable { static constexpr bool Value = std::is_trivially_assignable_v<T>; };
template <typename T> struct TIsCopyAssignable { static constexpr bool Value = std::is_copy_assignable_v<T>; };
template <typename T> struct TIsTriviallyCopyAssignable { static constexpr bool Value = std::is_trivially_copy_assignable_v<T>; };
template <typename T> struct TIsMoveAssignable { static constexpr bool Value = std::is_move_assignable_v<T>; };
template <typename T> struct TIsTriviallyMoveAssignable { static constexpr bool Value = std::is_trivially_move_assignable_v<T>; };
template <typename T> struct TIsDestructible { static constexpr bool Value = std::is_destructible_v<T>; };
template <typename T> struct TIsTriviallyDestructible { static constexpr bool Value = std::is_trivially_destructible_v<T>; };
template <typename T> struct THasVirtualDestructor { static constexpr bool Value = std::has_virtual_destructor_v<T>; };
template <typename T> struct TIsSwappableWith { static constexpr bool Value = std::is_swappable_with_v<T>; };
template <typename T> struct TIsSwappable { static constexpr bool Value = std::is_swappable_v<T>; };
// Property queries.
template <typename T> struct TRank { static constexpr size_t Value = std::rank_v<T>; };
template <typename T, size_t N = 0> struct TExtent { static constexpr size_t Value = std::extent_v<T, N>; };
// Type relationships.
template <typename T, typename U> struct TIsSame { static constexpr bool Value = std::is_same_v<T, U>; };
template <typename T, typename U> struct TIsBaseOf { static constexpr bool Value = std::is_base_of_v<T, U>; };
template <typename T, typename U> struct TIsConvertible { static constexpr bool Value = std::is_convertible_v<T, U>; };
template <typename Func, typename... ArgTypes> struct TIsInvocable { static constexpr bool Value = std::is_invocable_v<Func, ArgTypes...>; };
template <typename Result, typename Func, typename... ArgTypes> struct TIsInvocableResult { static constexpr bool Value = std::is_invocable_r_v<Result, Func, ArgTypes...>; };
// Const-volatility specifiers.
template <typename T> struct TRemoveCV { typedef typename std::remove_cv_t<T> Type; };
template <typename T> struct TRemoveConst { typedef typename std::remove_const<T> Type; };
template <typename T> struct TRemoveVolatile { typedef typename std::remove_volatile<T> Type; };
template <typename T> struct TAddCV { typedef typename std::add_cv<T> Type; };
template <typename T> struct TAddConst { typedef typename std::add_const<T> Type; };
template <typename T> struct TAddVolatile { typedef typename std::add_volatile<T> Type; };
// References.
template <typename T> struct TRemoveReference { typedef typename std::remove_reference_t<T> Type; };
template <typename T> struct TAddLValueReference { typedef typename std::add_lvalue_reference_t<T> Type; };
template <typename T> struct TAddRValueReference { typedef typename std::add_rvalue_reference_t<T> Type; };
// Pointers.
template <typename T> struct TRemovePointer { typedef typename std::remove_pointer_t<T> Type; };
template <typename T> struct TAddPointer { typedef typename std::add_pointer_t<T> Type; };
// Sign modifiers.
template <typename T> struct TMakeSigned { typedef typename std::make_signed_t<T> Type; };
template <typename T> struct TMakeUnsigned { typedef typename std::make_unsigned_t<T> Type; };
// Arrays.
template <typename T> struct TRemoveExtent { typedef typename std::remove_extent_t<T> Type; };
template <typename T> struct TRemoveAllExtents { typedef typename std::remove_all_extents_t<T> Type; };
// Miscellaneous transformations.
template <size_t Len, size_t Alignment> struct TAlignedStorage { typedef typename std::aligned_storage_t<Len, Alignment> Type; };
template <size_t Len, typename... Types> struct TAlignedUnion { typedef typename std::aligned_union_t<Len, Types...> Type; };
template <typename T> struct TDecay { typedef typename std::decay_t<T> Type; };
template <typename T> struct TRemoveCVRef { typedef typename std::remove_cvref_t<T> Type; };
template <bool B, typename T, typename F> struct TConditional { typedef typename std::conditional_t<B, T, F> Type; };
template <typename... T> struct TCommonType { typedef typename std::common_type_t<T...> Type; };
template <typename T> struct TUnderlyingType { typedef typename std::underlying_type_t<T> Type; };
template <typename Func, typename... ArgTypes> struct TInvokeResult { typedef typename std::invoke_result_t<Func, ArgTypes...> Type; };
// Operations on traits.
template <typename T, T InValue> struct TConstant { static constexpr T Value = InValue; };
template <bool InValue> struct TBoolConstant : TConstant<bool, InValue> { };
template <typename... Types> struct TAnd;
template <typename LHS, typename... RHS> struct TAnd<LHS, RHS...> { static constexpr bool Value = LHS::Value && TAnd<RHS...>::Value; };
template <> struct TAnd<> { static constexpr bool Value = true; };
template <typename... Types> struct TOr;
template <typename LHS, typename... RHS> struct TOr<LHS, RHS...> { static constexpr bool Value = LHS::Value || TOr<RHS...>::Value; };
template <> struct TOr<> { static constexpr bool Value = false; };
template <typename Type> struct TNot { static constexpr bool Value = !Type::Value; };
// Non-STD feature.
template <typename T>
struct TIsZeroConstructType
{
static constexpr bool Value = TOr<TIsEnum<T>, TIsArithmetic<T>, TIsPointer<T>>::Value;
};
template<typename T>
struct TCanBitwiseCompare
{
static constexpr bool Value = TOr<TIsEnum<T>, TIsArithmetic<T>, TIsPointer<T>>::Value;
};
template <typename T, typename U>
struct TIsBitwiseConstructible
{
static_assert(
!TIsReference<T>::Value &&
!TIsReference<U>::Value,
"TIsBitwiseConstructible is not designed to accept reference types");
static_assert(
TIsSame<T, typename TRemoveCV<T>::Type>::Value &&
TIsSame<U, typename TRemoveCV<U>::Type>::Value,
"TIsBitwiseConstructible is not designed to accept qualified types");
static constexpr bool Value = false;
};
template <typename T>
struct TIsBitwiseConstructible<T, T>
{
static constexpr bool Value = TIsTriviallyCopyConstructible<T>::Value;
};
template <typename T, typename U>
struct TIsBitwiseConstructible<const T, U> : TIsBitwiseConstructible<T, U>
{ };
template <typename T>
struct TIsBitwiseConstructible<const T*, T*>
{
static constexpr bool Value = true;
};
template <> struct TIsBitwiseConstructible< uint8, int8> { static constexpr bool Value = true; };
template <> struct TIsBitwiseConstructible< int8, uint8> { static constexpr bool Value = true; };
template <> struct TIsBitwiseConstructible<uint16, int16> { static constexpr bool Value = true; };
template <> struct TIsBitwiseConstructible< int16, uint16> { static constexpr bool Value = true; };
template <> struct TIsBitwiseConstructible<uint32, int32> { static constexpr bool Value = true; };
template <> struct TIsBitwiseConstructible< int32, uint32> { static constexpr bool Value = true; };
template <> struct TIsBitwiseConstructible<uint64, int64> { static constexpr bool Value = true; };
template <> struct TIsBitwiseConstructible< int64, uint64> { static constexpr bool Value = true; };
NS_END(TypeTraits)
NS_REDCRAFT_END

View File

@ -1,59 +0,0 @@
#include "CoreMinimal.h"
#include "HAL/Memory.h"
#include <iostream>
#include <cassert>
#include <new>
NS_STD_USING
NS_REDCRAFT_USING
struct FTest
{
FTest() { cout << "FTest()" << endl; }
~FTest() { cout << "~FTest()" << endl; }
FTest(int32) { cout << "FTest(int32)" << endl; }
FTest(const FTest&) { cout << "FTest(const FTest&)" << endl; }
FTest(FTest&&) { cout << "FTest(FTest&&)" << endl; }
FTest& operator =(const FTest&) { cout << "FTest& operator =(const FTest&)" << endl; return *this; }
FTest& operator =(FTest&&) { cout << "FTest& operator =(FTest&&)" << endl; return *this; }
friend bool operator ==(const FTest&, const FTest&) { cout << "bool operator ==(const FTest&, const FTest&)" << endl; return true; }
};
int main()
{
FTest* A = new FTest[2];
FTest* B = new FTest[2];
int32* C = new int32[2];
int32* D = new int32[2];
cout << " --- " << endl;
Memory::DefaultConstructItems<FTest>(A, 2);
Memory::DestructItems<FTest>(A, 2);
Memory::ConstructItems<FTest>(A, C, 2);
Memory::CopyAssignItems(B, A, 2);
Memory::RelocateConstructItems<FTest>(A, C, 2);
Memory::MoveConstructItems(B, A, 2);
Memory::MoveAssignItems(B, A, 2);
cout << (Memory::CompareItems(A, B, 2) ? "True" : "False") << endl;
Memory::DefaultConstructItems<int32>(C, 2);
Memory::DestructItems<int32>(C, 2);
Memory::ConstructItems<int32>(C, D, 2);
Memory::CopyAssignItems(D, C, 2);
Memory::RelocateConstructItems<int32>(D, C, 2);
Memory::MoveConstructItems(D, C, 2);
Memory::MoveAssignItems(D, C, 2);
cout << (Memory::CompareItems(C, D, 2) ? "True" : "False") << endl;
cout << " --- " << endl;
delete[] A;
delete[] B;
delete[] C;
delete[] D;
cout << "Done!" << endl;
return 0;
}

View File

@ -1,7 +1,8 @@
cmake_minimum_required (VERSION 3.8)
# Set module name.
set (MODULE_NAME "Redcraft.Debug")
string(REGEX REPLACE ".*/(.*)" "\\1" MODULE_NAME ${CMAKE_CURRENT_SOURCE_DIR})
message (STATUS "Configuring module: " ${MODULE_NAME})
# Add target.
file (GLOB_RECURSE MODULE_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Source/*")
@ -19,4 +20,4 @@ target_compile_definitions (${MODULE_NAME} PRIVATE "${MODULE_API}=DLLEXPORT")
target_compile_definitions (${MODULE_NAME} INTERFACE "${MODULE_API}=DLLIMPORT")
# Add project dependencies
target_link_libraries (${MODULE_NAME} PRIVATE Redcraft.Core)
target_link_libraries (${MODULE_NAME} PRIVATE Redcraft.Utility)

View File

@ -1,7 +1,8 @@
cmake_minimum_required (VERSION 3.8)
cmake_minimum_required (VERSION 3.8)
# Set module name.
set (MODULE_NAME "Redcraft.Core")
string(REGEX REPLACE ".*/(.*)" "\\1" MODULE_NAME ${CMAKE_CURRENT_SOURCE_DIR})
message (STATUS "Configuring module: " ${MODULE_NAME})
# Add target.
file (GLOB_RECURSE MODULE_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Source/*")
@ -20,4 +21,4 @@ target_compile_definitions (${MODULE_NAME} PRIVATE "${MODULE_API}=DLLEXPORT")
target_compile_definitions (${MODULE_NAME} INTERFACE "${MODULE_API}=DLLIMPORT")
# Add project dependencies
#target_link_libraries (${MODULE_NAME} PRIVATE Redcraft.Core)
#target_link_libraries (${MODULE_NAME} PRIVATE Redcraft.Utility)