diff --git a/CMakeLists.txt b/CMakeLists.txt index d3a445d..bce40d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 () diff --git a/Redcraft.Core/Source/Private/HAL/Memory.cpp b/Redcraft.Core/Source/Private/HAL/Memory.cpp deleted file mode 100644 index 45b73c3..0000000 --- a/Redcraft.Core/Source/Private/HAL/Memory.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "HAL/Memory.h" - -#include "Templates/Alignment.h" - -#if PLATFORM_WINDOWS -#include -#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 diff --git a/Redcraft.Core/Source/Public/CoreMinimal.h b/Redcraft.Core/Source/Public/CoreMinimal.h deleted file mode 100644 index ca2f663..0000000 --- a/Redcraft.Core/Source/Public/CoreMinimal.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include "CoreTypes.h" -#include "Templates/MemoryOps.h" -#include "Misc/AssertionMacros.h" diff --git a/Redcraft.Core/Source/Public/CoreTypes.h b/Redcraft.Core/Source/Public/CoreTypes.h deleted file mode 100644 index 362211b..0000000 --- a/Redcraft.Core/Source/Public/CoreTypes.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -#include "HAL/Platform.h" -#include "Misc/CoreDefines.h" diff --git a/Redcraft.Core/Source/Public/HAL/Memory.h b/Redcraft.Core/Source/Public/HAL/Memory.h deleted file mode 100644 index 0a6f002..0000000 --- a/Redcraft.Core/Source/Public/HAL/Memory.h +++ /dev/null @@ -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 -static FORCEINLINE void Memset(T& Src, uint8 ValueToSet); - -template -static FORCEINLINE void Memzero(T& Src); - -template -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); } diff --git a/Redcraft.Core/Source/Public/HAL/Memory.inl b/Redcraft.Core/Source/Public/HAL/Memory.inl deleted file mode 100644 index 3dcd101..0000000 --- a/Redcraft.Core/Source/Public/HAL/Memory.inl +++ /dev/null @@ -1,67 +0,0 @@ -#include "Math/MathUtility.h" -#include "Templates/TypeTraits.h" - -#include -#include - -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 -static FORCEINLINE void Memset(T& Src, uint8 ValueToSet) -{ - static_assert(!TypeTraits::TIsPointer::Value, "For pointers use the three parameters function"); - Memset(&Src, ValueToSet, sizeof(T)); -} - -template -static FORCEINLINE void Memzero(T& Src) -{ - static_assert(!TypeTraits::TIsPointer::Value, "For pointers use the two parameters function"); - Memzero(&Src, sizeof(T)); -} - -template -static FORCEINLINE void Memcpy(T& Dest, const T& Src) -{ - static_assert(!TypeTraits::TIsPointer::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 diff --git a/Redcraft.Core/Source/Public/HAL/Platform.h b/Redcraft.Core/Source/Public/HAL/Platform.h deleted file mode 100644 index 18fcb1a..0000000 --- a/Redcraft.Core/Source/Public/HAL/Platform.h +++ /dev/null @@ -1,183 +0,0 @@ -#pragma once - -#include "Misc/CoreDefines.h" - -#include -#include -#include -#include - -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 diff --git a/Redcraft.Core/Source/Public/Math/MathUtility.h b/Redcraft.Core/Source/Public/Math/MathUtility.h deleted file mode 100644 index 19d11cb..0000000 --- a/Redcraft.Core/Source/Public/Math/MathUtility.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "CoreTypes.h" - -NS_REDCRAFT_BEGIN -NS_BEGIN(Math) - -template -static constexpr FORCEINLINE T Abs(const T A) -{ - return (A >= (T)0) ? A : -A; -} - -template -static constexpr FORCEINLINE T Sign(const T A) -{ - return (A > (T)0) ? (T)1 : ((A < (T)0) ? (T)-1 : (T)0); -} - -template -static constexpr FORCEINLINE T Max(const T A, const T B) -{ - return (A >= B) ? A : B; -} - -template -static constexpr FORCEINLINE T Min(const T A, const T B) -{ - return (A <= B) ? A : B; -} - -NS_END(Math) -NS_REDCRAFT_END diff --git a/Redcraft.Core/Source/Public/Misc/AssertionMacros.h b/Redcraft.Core/Source/Public/Misc/AssertionMacros.h deleted file mode 100644 index 8c4fe1e..0000000 --- a/Redcraft.Core/Source/Public/Misc/AssertionMacros.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include "CoreTypes.h" - -#include - -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 diff --git a/Redcraft.Core/Source/Public/Misc/CoreDefines.h b/Redcraft.Core/Source/Public/Misc/CoreDefines.h deleted file mode 100644 index 341931b..0000000 --- a/Redcraft.Core/Source/Public/Misc/CoreDefines.h +++ /dev/null @@ -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 diff --git a/Redcraft.Core/Source/Public/Templates/Alignment.h b/Redcraft.Core/Source/Public/Templates/Alignment.h deleted file mode 100644 index 1f7645e..0000000 --- a/Redcraft.Core/Source/Public/Templates/Alignment.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#pragma once - -#include "CoreTypes.h" -#include "Templates/TypeTraits.h" - -NS_REDCRAFT_BEGIN -NS_BEGIN(Memory) - -template -FORCEINLINE constexpr T Align(T Val, uint64 Alignment) -{ - static_assert(TypeTraits::TIsIntegral::Value || TypeTraits::TIsPointer::Value, "Align expects an integer or pointer type"); - - return (T)(((uint64)Val + Alignment - 1) & ~(Alignment - 1)); -} - -template -FORCEINLINE constexpr T AlignDown(T Val, uint64 Alignment) -{ - static_assert(TypeTraits::TIsIntegral::Value || TypeTraits::TIsPointer::Value, "AlignDown expects an integer or pointer type"); - - return (T)(((uint64)Val) & ~(Alignment - 1)); -} - -template -FORCEINLINE constexpr bool IsAligned(T Val, uint64 Alignment) -{ - static_assert(TypeTraits::TIsIntegral::Value || TypeTraits::TIsPointer::Value, "IsAligned expects an integer or pointer type"); - - return !((uint64)Val & (Alignment - 1)); -} - -template -FORCEINLINE constexpr T AlignArbitrary(T Val, uint64 Alignment) -{ - static_assert(TypeTraits::TIsIntegral::Value || TypeTraits::TIsPointer::Value, "AlignArbitrary expects an integer or pointer type"); - - return (T)((((uint64)Val + Alignment - 1) / Alignment) * Alignment); -} - -NS_END(Memory) -NS_REDCRAFT_END diff --git a/Redcraft.Core/Source/Public/Templates/MemoryOps.h b/Redcraft.Core/Source/Public/Templates/MemoryOps.h deleted file mode 100644 index a0ad064..0000000 --- a/Redcraft.Core/Source/Public/Templates/MemoryOps.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "CoreTypes.h" - -NS_REDCRAFT_BEGIN -NS_BEGIN(Memory) - -template -FORCEINLINE void DefaultConstructItems(void* Address, SizeType Count = 1); - -template -FORCEINLINE void DestructItems(ElementType* Element, SizeType Count = 1); - -template -FORCEINLINE void ConstructItems(void* Dest, const SourceElementType* Source, SizeType Count = 1); - -template -FORCEINLINE void CopyAssignItems(ElementType* Dest, const ElementType* Source, SizeType Count = 1); - -template -FORCEINLINE void RelocateConstructItems(void* Dest, const SourceElementType* Source, SizeType Count = 1); - -template -FORCEINLINE void MoveConstructItems(void* Dest, const ElementType* Source, SizeType Count = 1); - -template -FORCEINLINE void MoveAssignItems(ElementType* Dest, const ElementType* Source, SizeType Count = 1); - -template -FORCEINLINE bool CompareItems(const ElementType* A, const ElementType* B, SizeType Count = 1); - -NS_END(Memory) -NS_REDCRAFT_END - -#include "Templates/MemoryOps.inl" diff --git a/Redcraft.Core/Source/Public/Templates/MemoryOps.inl b/Redcraft.Core/Source/Public/Templates/MemoryOps.inl deleted file mode 100644 index b7df516..0000000 --- a/Redcraft.Core/Source/Public/Templates/MemoryOps.inl +++ /dev/null @@ -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 -struct TCanBitwiseRelocate -{ - enum - { - Value = - TypeTraits::TOr< - TypeTraits::TIsSame, - TypeTraits::TAnd< - TypeTraits::TIsBitwiseConstructible, - TypeTraits::TIsTriviallyDestructible - > - >::Value - }; -}; - -NS_PRIVATE_END - -template -FORCEINLINE void DefaultConstructItems(void* Address, SizeType Count) -{ - if constexpr (TypeTraits::TIsZeroConstructType::Value) - { - Memory::Memset(Address, 0, sizeof(ElementType) * Count); - } - else - { - ElementType* Element = (ElementType*)Address; - while (Count) - { - new (Element) ElementType; - ++Element; - --Count; - } - } -} - -template -FORCEINLINE void DestructItems(ElementType* Element, SizeType Count) -{ - if constexpr (!TypeTraits::TIsTriviallyDestructible::Value) - { - while (Count) - { - typedef ElementType DestructItemsElementTypeTypedef; - - Element->DestructItemsElementTypeTypedef::~DestructItemsElementTypeTypedef(); - ++Element; - --Count; - } - } -} - -template -FORCEINLINE void ConstructItems(void* Dest, const SourceElementType* Source, SizeType Count) -{ - if constexpr (TypeTraits::TIsBitwiseConstructible::Value) - { - Memory::Memcpy(Dest, Source, sizeof(SourceElementType) * Count); - } - else - { - while (Count) - { - new (Dest) DestinationElementType(*Source); - ++(DestinationElementType*&)Dest; - ++Source; - --Count; - } - } -} - -template -FORCEINLINE void CopyAssignItems(ElementType* Dest, const ElementType* Source, SizeType Count) -{ - if constexpr (TypeTraits::TIsTriviallyCopyAssignable::Value) - { - Memory::Memcpy(Dest, Source, sizeof(ElementType) * Count); - } - else - { - while (Count) - { - *Dest = *Source; - ++Dest; - ++Source; - --Count; - } - } -} - -template -FORCEINLINE void RelocateConstructItems(void* Dest, const SourceElementType* Source, SizeType Count) -{ - if constexpr (NS_PRIVATE::TCanBitwiseRelocate::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 -FORCEINLINE void MoveConstructItems(void* Dest, const ElementType* Source, SizeType Count) -{ - if constexpr (TypeTraits::TIsTriviallyCopyConstructible::Value) - { - Memory::Memmove(Dest, Source, sizeof(ElementType) * Count); - } - else - { - while (Count) - { - new (Dest) ElementType((ElementType&&)*Source); - ++(ElementType*&)Dest; - ++Source; - --Count; - } - } -} - -template -FORCEINLINE void MoveAssignItems(ElementType* Dest, const ElementType* Source, SizeType Count) -{ - if constexpr (TypeTraits::TIsTriviallyCopyAssignable::Value) - { - Memory::Memmove(Dest, Source, sizeof(ElementType) * Count); - } - else - { - while (Count) - { - *Dest = (ElementType&&)*Source; - ++Dest; - ++Source; - --Count; - } - } -} - -template -FORCEINLINE bool CompareItems(const ElementType* A, const ElementType* B, SizeType Count) -{ - if constexpr (TypeTraits::TCanBitwiseCompare::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 diff --git a/Redcraft.Core/Source/Public/Templates/TypeTraits.h b/Redcraft.Core/Source/Public/Templates/TypeTraits.h deleted file mode 100644 index 89e2429..0000000 --- a/Redcraft.Core/Source/Public/Templates/TypeTraits.h +++ /dev/null @@ -1,202 +0,0 @@ -#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 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 { static constexpr bool Value = LHS::Value && TAnd::Value; }; -template <> struct TAnd<> { static constexpr bool Value = true; }; - -template struct TOr; -template struct TOr { static constexpr bool Value = LHS::Value || TOr::Value; }; -template <> struct TOr<> { static constexpr bool Value = false; }; - -template struct TNot { static constexpr bool Value = !Type::Value; }; - -// Non-STD feature. - -template -struct TIsZeroConstructType -{ - static constexpr bool Value = TOr, TIsArithmetic, TIsPointer>::Value; -}; - -template -struct TCanBitwiseCompare -{ - static constexpr bool Value = TOr, TIsArithmetic, TIsPointer>::Value; -}; - -template -struct TIsBitwiseConstructible -{ - static_assert( - !TIsReference::Value && - !TIsReference::Value, - "TIsBitwiseConstructible is not designed to accept reference types"); - - static_assert( - TIsSame::Type>::Value && - TIsSame::Type>::Value, - "TIsBitwiseConstructible is not designed to accept qualified types"); - - static constexpr bool Value = false; -}; - -template -struct TIsBitwiseConstructible -{ - static constexpr bool Value = TIsTriviallyCopyConstructible::Value; -}; - -template -struct TIsBitwiseConstructible : TIsBitwiseConstructible -{ }; - -template -struct TIsBitwiseConstructible -{ - 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 { static constexpr bool Value = true; }; -template <> struct TIsBitwiseConstructible< int16, uint16> { static constexpr bool Value = true; }; -template <> struct TIsBitwiseConstructible { static constexpr bool Value = true; }; -template <> struct TIsBitwiseConstructible< int32, uint32> { static constexpr bool Value = true; }; -template <> struct TIsBitwiseConstructible { static constexpr bool Value = true; }; -template <> struct TIsBitwiseConstructible< int64, uint64> { static constexpr bool Value = true; }; - -NS_END(TypeTraits) -NS_REDCRAFT_END diff --git a/Redcraft.Debug/Source/Main.cpp b/Redcraft.Debug/Source/Main.cpp deleted file mode 100644 index 0a3fdf3..0000000 --- a/Redcraft.Debug/Source/Main.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "CoreMinimal.h" -#include "HAL/Memory.h" - -#include -#include -#include - -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(A, 2); - Memory::DestructItems(A, 2); - Memory::ConstructItems(A, C, 2); - Memory::CopyAssignItems(B, A, 2); - Memory::RelocateConstructItems(A, C, 2); - Memory::MoveConstructItems(B, A, 2); - Memory::MoveAssignItems(B, A, 2); - cout << (Memory::CompareItems(A, B, 2) ? "True" : "False") << endl; - - Memory::DefaultConstructItems(C, 2); - Memory::DestructItems(C, 2); - Memory::ConstructItems(C, D, 2); - Memory::CopyAssignItems(D, C, 2); - Memory::RelocateConstructItems(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; -} diff --git a/Redcraft.Debug/CMakeLists.txt b/Redcraft.Utility.Test/CMakeLists.txt similarity index 78% rename from Redcraft.Debug/CMakeLists.txt rename to Redcraft.Utility.Test/CMakeLists.txt index 4611768..45671e9 100644 --- a/Redcraft.Debug/CMakeLists.txt +++ b/Redcraft.Utility.Test/CMakeLists.txt @@ -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) diff --git a/Redcraft.Core/CMakeLists.txt b/Redcraft.Utility/CMakeLists.txt similarity index 76% rename from Redcraft.Core/CMakeLists.txt rename to Redcraft.Utility/CMakeLists.txt index d50e3cc..23edd6e 100644 --- a/Redcraft.Core/CMakeLists.txt +++ b/Redcraft.Utility/CMakeLists.txt @@ -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)