style(miscellaneous): rename the Misc directory to Miscellaneous
This commit is contained in:
@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "Miscellaneous/PreprocessorHelpers.h"
|
||||
|
||||
#undef NDEBUG
|
||||
#include <cassert>
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
NAMESPACE_MODULE_BEGIN(Utility)
|
||||
|
||||
NAMESPACE_PRIVATE_BEGIN
|
||||
|
||||
class FRecursionScopeMarker
|
||||
{
|
||||
public:
|
||||
|
||||
FRecursionScopeMarker(uint8& InCounter) : Counter(InCounter) { ++Counter; }
|
||||
~FRecursionScopeMarker() { --Counter; }
|
||||
|
||||
private:
|
||||
|
||||
uint8& Counter;
|
||||
|
||||
};
|
||||
|
||||
#define RS_CHECK_IMPL(InExpr) assert(InExpr)
|
||||
#define RS_CHECK_F_IMPL(InExpr, InFormat, ...) assert(InExpr)
|
||||
|
||||
NAMESPACE_PRIVATE_END
|
||||
|
||||
#define always_check(InExpr) RS_CHECK_IMPL(InExpr)
|
||||
#define always_checkf(InExpr, InFormat, ...) RS_CHECK_F_IMPL(InExpr, InFormat, ##__VA_ARGS__)
|
||||
#define always_check_no_entry() always_checkf(false, "Enclosing block should never be called.")
|
||||
#define always_check_no_reentry() { static bool PREPROCESSOR_JOIN(bBeenHere, __LINE__) = false; always_checkf(!PREPROCESSOR_JOIN(bBeenHere, __LINE__), "Enclosing block was called more than once."); PREPROCESSOR_JOIN(bBeenHere, __LINE__) = true; }
|
||||
#define always_check_no_recursion() static uint8 PREPROCESSOR_JOIN(RecursionCounter, __LINE__) = 0; always_checkf(PREPROCESSOR_JOIN(RecursionCounter, __LINE__) == 0, "Enclosing block was entered recursively."); const NAMESPACE_PRIVATE::FRecursionScopeMarker PREPROCESSOR_JOIN(ScopeMarker, __LINE__)(PREPROCESSOR_JOIN(RecursionCounter, __LINE__))
|
||||
#define always_unimplemented() always_checkf(false, "Unimplemented function called.")
|
||||
|
||||
#if BUILD_DEBUG
|
||||
|
||||
# define check(InExpr) always_check(InExpr)
|
||||
# define checkf(InExpr, InFormat, ...) always_checkf(InExpr, InFormat, ##__VA_ARGS__)
|
||||
# define check_no_entry() always_check_no_entry()
|
||||
# define check_no_reentry() always_check_no_reentry()
|
||||
# define check_no_recursion() always_check_no_recursion()
|
||||
# define verify(InExpr) always_check(InExpr)
|
||||
# define verifyf(InExpr, InFormat, ...) always_checkf(InExpr, InFormat, ##__VA_ARGS__)
|
||||
# define unimplemented() always_unimplemented()
|
||||
|
||||
#else
|
||||
|
||||
# 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
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
NAMESPACE_REDCRAFT_END
|
50
Redcraft.Utility/Source/Public/Miscellaneous/CoreDefines.h
Normal file
50
Redcraft.Utility/Source/Public/Miscellaneous/CoreDefines.h
Normal file
@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
// Define the normal namespace
|
||||
#define NAMESPACE_BEGIN(Name) namespace Name {
|
||||
#define NAMESPACE_END(Name) }
|
||||
#define NAMESPACE_USING(Name) using namespace Name;
|
||||
|
||||
// Define the inline namespace
|
||||
#define NAMESPACE_INLINE_BEGIN(Name) inline NAMESPACE_BEGIN(Name)
|
||||
#define NAMESPACE_INLINE_END(Name) NAMESPACE_END(Name)
|
||||
|
||||
// Define the module namespace
|
||||
#define NAMESPACE_MODULE_BEGIN(Name) NAMESPACE_INLINE_BEGIN(Name)
|
||||
#define NAMESPACE_MODULE_END(Name) NAMESPACE_INLINE_END(Name)
|
||||
|
||||
// Define the redcraft master namespace
|
||||
#define NAMESPACE_REDCRAFT RFur
|
||||
#define NAMESPACE_REDCRAFT_BEGIN NAMESPACE_BEGIN(NAMESPACE_REDCRAFT)
|
||||
#define NAMESPACE_REDCRAFT_END NAMESPACE_END(NAMESPACE_REDCRAFT)
|
||||
#define NAMESPACE_REDCRAFT_USING NAMESPACE_USING(NAMESPACE_REDCRAFT)
|
||||
|
||||
// Define the private namespace - Used to hide the realization of something
|
||||
#define NAMESPACE_PRIVATE Private
|
||||
#define NAMESPACE_PRIVATE_BEGIN NAMESPACE_BEGIN(NAMESPACE_PRIVATE)
|
||||
#define NAMESPACE_PRIVATE_END NAMESPACE_END(NAMESPACE_PRIVATE)
|
||||
|
||||
// Define the STD namespace
|
||||
#define NAMESPACE_STD std
|
||||
#define NAMESPACE_STD_BEGIN NAMESPACE_BEGIN(NAMESPACE_STD)
|
||||
#define NAMESPACE_STD_END NAMESPACE_END(NAMESPACE_STD)
|
||||
#define NAMESPACE_STD_USING NAMESPACE_USING(NAMESPACE_STD)
|
||||
|
||||
// Define the unnamed namespace
|
||||
#define NAMESPACE_UNNAMED_BEGIN namespace {
|
||||
#define NAMESPACE_UNNAMED_END }
|
||||
#define NAMESPACE_INLINE_UNNAMED_BEGIN inline namespace {
|
||||
#define NAMESPACE_INLINE_UNNAMED_END }
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
NAMESPACE_MODULE_BEGIN(Utility)
|
||||
|
||||
enum { INDEX_NONE = -1 };
|
||||
enum { UNICODE_BOM = 0xfeff };
|
||||
|
||||
enum EForceInit { ForceInit };
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
NAMESPACE_REDCRAFT_END
|
170
Redcraft.Utility/Source/Public/Miscellaneous/Platform.h
Normal file
170
Redcraft.Utility/Source/Public/Miscellaneous/Platform.h
Normal file
@ -0,0 +1,170 @@
|
||||
#pragma once
|
||||
|
||||
#include "Miscellaneous/CoreDefines.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
NAMESPACE_MODULE_BEGIN(Utility)
|
||||
|
||||
// Build information macro.
|
||||
|
||||
#ifndef PLATFORM_NAME
|
||||
# error "PLATFORM_NAME must be defined"
|
||||
#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
|
||||
# error "BUILD_TYPE must be defined"
|
||||
#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
|
||||
|
||||
// Whether the CPU is x86/x64 (i.e. both 32 and 64-bit variants)
|
||||
|
||||
#ifndef PLATFORM_CPU_X86_FAMILY
|
||||
# if (defined(_M_IX86) || defined(__i386__) || defined(_M_X64) || defined(__amd64__) || defined(__x86_64__))
|
||||
# define PLATFORM_CPU_X86_FAMILY 1
|
||||
# else
|
||||
# define PLATFORM_CPU_X86_FAMILY 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Whether the CPU is AArch32/AArch64 (i.e. both 32 and 64-bit variants)
|
||||
|
||||
#ifndef PLATFORM_CPU_ARM_FAMILY
|
||||
# if (defined(__arm__) || defined(_M_ARM) || defined(__aarch64__) || defined(_M_ARM64))
|
||||
# define PLATFORM_CPU_ARM_FAMILY 1
|
||||
# else
|
||||
# define PLATFORM_CPU_ARM_FAMILY 0
|
||||
# endif
|
||||
#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
|
||||
|
||||
// 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 NAMESPACE_STD::uint8_t uint8;
|
||||
typedef NAMESPACE_STD::uint16_t uint16;
|
||||
typedef NAMESPACE_STD::uint32_t uint32;
|
||||
typedef NAMESPACE_STD::uint64_t uint64;
|
||||
|
||||
// Signed base types.
|
||||
|
||||
typedef NAMESPACE_STD::int8_t int8;
|
||||
typedef NAMESPACE_STD::int16_t int16;
|
||||
typedef NAMESPACE_STD::int32_t int32;
|
||||
typedef NAMESPACE_STD::int64_t int64;
|
||||
|
||||
// Character types.
|
||||
|
||||
typedef char ANSICHAR;
|
||||
typedef wchar_t WIDECHAR;
|
||||
typedef WIDECHAR TCHAR;
|
||||
|
||||
// Pointer types.
|
||||
|
||||
typedef NAMESPACE_STD::uintptr_t uintptr_t;
|
||||
typedef NAMESPACE_STD::intptr_t intptr_t;
|
||||
typedef NAMESPACE_STD::size_t size_t;
|
||||
typedef intptr_t ssize_t;
|
||||
|
||||
// Null types.
|
||||
|
||||
typedef decltype(NULL) null_t;
|
||||
typedef NAMESPACE_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)
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
NAMESPACE_REDCRAFT_END
|
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
// Turns an preprocessor token into a real string
|
||||
#define PREPROCESSOR_TO_STRING(X) PREPROCESSOR_TO_STRING_INNER(X)
|
||||
#define PREPROCESSOR_TO_STRING_INNER(X) #X
|
||||
|
||||
// Concatenates two preprocessor tokens, performing macro expansion on them first
|
||||
#define PREPROCESSOR_JOIN(X, Y) PREPROCESSOR_JOIN_INNER(X, Y)
|
||||
#define PREPROCESSOR_JOIN_INNER(X, Y) X##Y
|
||||
|
||||
// Concatenates the first two preprocessor tokens of a variadic list, after performing macro expansion on them
|
||||
#define PREPROCESSOR_JOIN_FIRST(X, ...) PREPROCESSOR_JOIN_FIRST_INNER(X, __VA_ARGS__)
|
||||
#define PREPROCESSOR_JOIN_FIRST_INNER(X, ...) X##__VA_ARGS__
|
||||
|
||||
// Expands to the second argument or the third argument if the first argument is 1 or 0 respectively
|
||||
#define PREPROCESSOR_IF(Condition, X, Y) PREPROCESSOR_JOIN(PREPROCESSOR_IF_INNER_, Condition)(X, Y)
|
||||
#define PREPROCESSOR_IF_INNER_1(X, Y) X
|
||||
#define PREPROCESSOR_IF_INNER_0(X, Y) Y
|
||||
|
||||
// Expands to the parameter list of the macro - used for when you need to pass a comma-separated identifier to another macro as a single parameter
|
||||
#define PREPROCESSOR_COMMA_SEPARATED(First, Second, ...) First, Second, ##__VA_ARGS__
|
||||
|
||||
// Expands to nothing - used as a placeholder
|
||||
#define PREPROCESSOR_NOTHING
|
||||
|
||||
// Removes a single layer of parentheses from a macro argument if they are present - used to allow
|
||||
// brackets to be optionally added when the argument contains commas, e.g.:
|
||||
//
|
||||
// #define DEFINE_VARIABLE(Type, Name) PREPROCESSOR_REMOVE_OPTIONAL_PARENS(Type) Name;
|
||||
//
|
||||
// DEFINE_VARIABLE(int, IntVar) // expands to: int IntVar;
|
||||
// DEFINE_VARIABLE((TPair<int, float>), PairVar) // expands to: TPair<int, float> PairVar;
|
||||
#define PREPROCESSOR_REMOVE_OPTIONAL_PARENS(...) PREPROCESSOR_JOIN_FIRST(PREPROCESSOR_REMOVE_OPTIONAL_PARENS_IMPL,PREPROCESSOR_REMOVE_OPTIONAL_PARENS_IMPL __VA_ARGS__)
|
||||
#define PREPROCESSOR_REMOVE_OPTIONAL_PARENS_IMPL(...) PREPROCESSOR_REMOVE_OPTIONAL_PARENS_IMPL __VA_ARGS__
|
||||
#define PREPROCESSOR_REMOVE_OPTIONAL_PARENS_IMPLPREPROCESSOR_REMOVE_OPTIONAL_PARENS_IMPL
|
||||
|
||||
// Creates a string that can be used to include a header in the form "Platform/Header.h", like "Windows/Platform.h"
|
||||
#define COMPILED_PLATFORM_HEADER(Suffix) PREPROCESSOR_TO_STRING(PREPROCESSOR_JOIN(PLATFORM_HEADER_NAME/, Suffix))
|
Reference in New Issue
Block a user