aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/include
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-11-07 16:21:15 +0100
committerGitHub <[email protected]>2023-11-07 16:21:15 +0100
commit176d38e185765d3684cfe4c7a8bba518a240c789 (patch)
treef71038c379d903fce31f52f65c6332d6e17363a5 /src/zencore/include
parentbump xmake CI version to 2.8.2 (#514) (diff)
downloadzen-176d38e185765d3684cfe4c7a8bba518a240c789.tar.xz
zen-176d38e185765d3684cfe4c7a8bba518a240c789.zip
factored out some compiler definitions etc into zenbase (#517)
this is a header-only library which mostly contains definitions to support different platforms and compilers. It is part of the zen codebase but is intended to be consumable separately to zenbase etc to support standalone transport plug-ins and similar.
Diffstat (limited to 'src/zencore/include')
-rw-r--r--src/zencore/include/zencore/atomic.h74
-rw-r--r--src/zencore/include/zencore/compactbinarybuilder.h2
-rw-r--r--src/zencore/include/zencore/compactbinaryvalidation.h2
-rw-r--r--src/zencore/include/zencore/guid.h1
-rw-r--r--src/zencore/include/zencore/intmath.h1
-rw-r--r--src/zencore/include/zencore/iobuffer.h2
-rw-r--r--src/zencore/include/zencore/refcount.h187
-rw-r--r--src/zencore/include/zencore/session.h1
-rw-r--r--src/zencore/include/zencore/sharedbuffer.h2
-rw-r--r--src/zencore/include/zencore/stats.h2
-rw-r--r--src/zencore/include/zencore/uid.h2
-rw-r--r--src/zencore/include/zencore/workthreadpool.h2
-rw-r--r--src/zencore/include/zencore/zencore.h336
13 files changed, 40 insertions, 574 deletions
diff --git a/src/zencore/include/zencore/atomic.h b/src/zencore/include/zencore/atomic.h
deleted file mode 100644
index bf549e21d..000000000
--- a/src/zencore/include/zencore/atomic.h
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright Epic Games, Inc. All Rights Reserved.
-
-#pragma once
-
-#include <zencore/zencore.h>
-
-#if ZEN_COMPILER_MSC
-# include <intrin.h>
-#else
-# include <atomic>
-#endif
-
-#include <cinttypes>
-
-namespace zen {
-
-inline uint32_t
-AtomicIncrement(volatile uint32_t& value)
-{
-#if ZEN_COMPILER_MSC
- return _InterlockedIncrement((long volatile*)&value);
-#else
- return ((std::atomic<uint32_t>*)(&value))->fetch_add(1, std::memory_order_seq_cst) + 1;
-#endif
-}
-inline uint32_t
-AtomicDecrement(volatile uint32_t& value)
-{
-#if ZEN_COMPILER_MSC
- return _InterlockedDecrement((long volatile*)&value);
-#else
- return ((std::atomic<uint32_t>*)(&value))->fetch_sub(1, std::memory_order_seq_cst) - 1;
-#endif
-}
-
-inline uint64_t
-AtomicIncrement(volatile uint64_t& value)
-{
-#if ZEN_COMPILER_MSC
- return _InterlockedIncrement64((__int64 volatile*)&value);
-#else
- return ((std::atomic<uint64_t>*)(&value))->fetch_add(1, std::memory_order_seq_cst) + 1;
-#endif
-}
-inline uint64_t
-AtomicDecrement(volatile uint64_t& value)
-{
-#if ZEN_COMPILER_MSC
- return _InterlockedDecrement64((__int64 volatile*)&value);
-#else
- return ((std::atomic<uint64_t>*)(&value))->fetch_sub(1, std::memory_order_seq_cst) - 1;
-#endif
-}
-
-inline uint32_t
-AtomicAdd(volatile uint32_t& value, uint32_t amount)
-{
-#if ZEN_COMPILER_MSC
- return _InterlockedExchangeAdd((long volatile*)&value, amount);
-#else
- return ((std::atomic<uint32_t>*)(&value))->fetch_add(amount, std::memory_order_seq_cst);
-#endif
-}
-inline uint64_t
-AtomicAdd(volatile uint64_t& value, uint64_t amount)
-{
-#if ZEN_COMPILER_MSC
- return _InterlockedExchangeAdd64((__int64 volatile*)&value, amount);
-#else
- return ((std::atomic<uint64_t>*)(&value))->fetch_add(amount, std::memory_order_seq_cst);
-#endif
-}
-
-} // namespace zen
diff --git a/src/zencore/include/zencore/compactbinarybuilder.h b/src/zencore/include/zencore/compactbinarybuilder.h
index e8d981fcb..9cb8f7193 100644
--- a/src/zencore/include/zencore/compactbinarybuilder.h
+++ b/src/zencore/include/zencore/compactbinarybuilder.h
@@ -6,10 +6,10 @@
#include <zencore/compactbinary.h>
+#include <zenbase/refcount.h>
#include <zencore/enumflags.h>
#include <zencore/iobuffer.h>
#include <zencore/iohash.h>
-#include <zencore/refcount.h>
#include <zencore/sha1.h>
#include <atomic>
diff --git a/src/zencore/include/zencore/compactbinaryvalidation.h b/src/zencore/include/zencore/compactbinaryvalidation.h
index 4f1bdbb37..b23c6d51d 100644
--- a/src/zencore/include/zencore/compactbinaryvalidation.h
+++ b/src/zencore/include/zencore/compactbinaryvalidation.h
@@ -4,11 +4,11 @@
#include <zencore/zencore.h>
+#include <zenbase/refcount.h>
#include <zencore/compactbinary.h>
#include <zencore/enumflags.h>
#include <zencore/iobuffer.h>
#include <zencore/iohash.h>
-#include <zencore/refcount.h>
#include <zencore/sha1.h>
#include <gsl/gsl-lite.hpp>
diff --git a/src/zencore/include/zencore/guid.h b/src/zencore/include/zencore/guid.h
index 13e1b5540..ee38aded0 100644
--- a/src/zencore/include/zencore/guid.h
+++ b/src/zencore/include/zencore/guid.h
@@ -6,6 +6,7 @@
#include <zencore/zencore.h>
#include <compare>
+#include <string_view>
namespace zen {
diff --git a/src/zencore/include/zencore/intmath.h b/src/zencore/include/zencore/intmath.h
index 0d87e1b78..2b59d6f4a 100644
--- a/src/zencore/include/zencore/intmath.h
+++ b/src/zencore/include/zencore/intmath.h
@@ -5,6 +5,7 @@
#include "zencore.h"
#include <stdint.h>
+#include <zenbase/concepts.h>
//////////////////////////////////////////////////////////////////////////
// UE Numeric constants
diff --git a/src/zencore/include/zencore/iobuffer.h b/src/zencore/include/zencore/iobuffer.h
index 0cbf093ca..7accce41c 100644
--- a/src/zencore/include/zencore/iobuffer.h
+++ b/src/zencore/include/zencore/iobuffer.h
@@ -3,9 +3,9 @@
#pragma once
#include <memory.h>
+#include <zenbase/refcount.h>
#include <zencore/memory.h>
#include <atomic>
-#include "refcount.h"
#include "zencore.h"
#include <filesystem>
diff --git a/src/zencore/include/zencore/refcount.h b/src/zencore/include/zencore/refcount.h
deleted file mode 100644
index 74a8f3ac0..000000000
--- a/src/zencore/include/zencore/refcount.h
+++ /dev/null
@@ -1,187 +0,0 @@
-// Copyright Epic Games, Inc. All Rights Reserved.
-#pragma once
-
-#include "atomic.h"
-#include "zencore.h"
-
-#include <compare>
-
-namespace zen {
-
-/**
- * Helper base class for reference counted objects using intrusive reference counts
- *
- * This class is pretty straightforward but does one thing which may be unexpected:
- *
- * - Instances on the stack are initialized with a reference count of one to ensure
- * nobody tries to accidentally delete it. (TODO: is this really useful?)
- */
-class RefCounted
-{
-public:
- RefCounted() = default;
- virtual ~RefCounted() = default;
-
- inline uint32_t AddRef() const { return AtomicIncrement(const_cast<RefCounted*>(this)->m_RefCount); }
- inline uint32_t Release() const
- {
- uint32_t refCount = AtomicDecrement(const_cast<RefCounted*>(this)->m_RefCount);
- if (refCount == 0)
- {
- delete this;
- }
- return refCount;
- }
-
- // Copying reference counted objects doesn't make a lot of sense generally, so let's prevent it
-
- RefCounted(const RefCounted&) = delete;
- RefCounted(RefCounted&&) = delete;
- RefCounted& operator=(const RefCounted&) = delete;
- RefCounted& operator=(RefCounted&&) = delete;
-
-protected:
- inline uint32_t RefCount() const { return m_RefCount; }
-
-private:
- uint32_t m_RefCount = 0;
-};
-
-/**
- * Smart pointer for classes derived from RefCounted
- */
-
-template<class T>
-class RefPtr
-{
-public:
- inline RefPtr() = default;
- inline RefPtr(const RefPtr& Rhs) : m_Ref(Rhs.m_Ref) { m_Ref && m_Ref->AddRef(); }
- inline RefPtr(T* Ptr) : m_Ref(Ptr) { m_Ref && m_Ref->AddRef(); }
- inline ~RefPtr() { m_Ref && m_Ref->Release(); }
-
- [[nodiscard]] inline bool IsNull() const { return m_Ref == nullptr; }
- inline explicit operator bool() const { return m_Ref != nullptr; }
- inline operator T*() const { return m_Ref; }
- inline T* operator->() const { return m_Ref; }
-
- inline std::strong_ordering operator<=>(const RefPtr& Rhs) const = default;
-
- inline RefPtr& operator=(T* Rhs)
- {
- Rhs && Rhs->AddRef();
- m_Ref && m_Ref->Release();
- m_Ref = Rhs;
- return *this;
- }
- inline RefPtr& operator=(const RefPtr& Rhs)
- {
- if (&Rhs != this)
- {
- Rhs && Rhs->AddRef();
- m_Ref && m_Ref->Release();
- m_Ref = Rhs.m_Ref;
- }
- return *this;
- }
- inline RefPtr& operator=(RefPtr&& Rhs) noexcept
- {
- if (&Rhs != this)
- {
- m_Ref && m_Ref->Release();
- m_Ref = Rhs.m_Ref;
- Rhs.m_Ref = nullptr;
- }
- return *this;
- }
- template<typename OtherType>
- inline RefPtr& operator=(RefPtr<OtherType>&& Rhs) noexcept
- {
- if ((RefPtr*)&Rhs != this)
- {
- m_Ref && m_Ref->Release();
- m_Ref = Rhs.m_Ref;
- Rhs.m_Ref = nullptr;
- }
- return *this;
- }
- inline RefPtr(RefPtr&& Rhs) noexcept : m_Ref(Rhs.m_Ref) { Rhs.m_Ref = nullptr; }
- template<typename OtherType>
- explicit inline RefPtr(RefPtr<OtherType>&& Rhs) noexcept : m_Ref(Rhs.m_Ref)
- {
- Rhs.m_Ref = nullptr;
- }
-
-private:
- T* m_Ref = nullptr;
- template<typename U>
- friend class RefPtr;
-};
-
-/**
- * Smart pointer for classes derived from RefCounted
- *
- * This variant does not decay to a raw pointer
- *
- */
-
-template<class T>
-class Ref
-{
-public:
- inline Ref() = default;
- inline Ref(const Ref& Rhs) : m_Ref(Rhs.m_Ref) { m_Ref && m_Ref->AddRef(); }
- inline explicit Ref(T* Ptr) : m_Ref(Ptr) { m_Ref && m_Ref->AddRef(); }
- inline ~Ref() { m_Ref && m_Ref->Release(); }
-
- template<typename DerivedType>
- requires DerivedFrom<DerivedType, T>
- inline Ref(const Ref<DerivedType>& Rhs) : Ref(Rhs.m_Ref) {}
-
- [[nodiscard]] inline bool IsNull() const { return m_Ref == nullptr; }
- inline explicit operator bool() const { return m_Ref != nullptr; }
- inline T* operator->() const { return m_Ref; }
- inline T& operator*() const { return *m_Ref; }
- inline T* Get() const { return m_Ref; }
-
- inline std::strong_ordering operator<=>(const Ref& Rhs) const = default;
-
- inline Ref& operator=(T* Rhs)
- {
- Rhs && Rhs->AddRef();
- m_Ref && m_Ref->Release();
- m_Ref = Rhs;
- return *this;
- }
- inline Ref& operator=(const Ref& Rhs)
- {
- if (&Rhs != this)
- {
- Rhs && Rhs->AddRef();
- m_Ref && m_Ref->Release();
- m_Ref = Rhs.m_Ref;
- }
- return *this;
- }
- inline Ref& operator=(Ref&& Rhs) noexcept
- {
- if (&Rhs != this)
- {
- m_Ref && m_Ref->Release();
- m_Ref = Rhs.m_Ref;
- Rhs.m_Ref = nullptr;
- }
- return *this;
- }
- inline Ref(Ref&& Rhs) noexcept : m_Ref(Rhs.m_Ref) { Rhs.m_Ref = nullptr; }
-
-private:
- T* m_Ref = nullptr;
-
- template<class U>
- friend class Ref;
-};
-
-void refcount_forcelink();
-
-} // namespace zen
diff --git a/src/zencore/include/zencore/session.h b/src/zencore/include/zencore/session.h
index dd90197bf..52289b7ef 100644
--- a/src/zencore/include/zencore/session.h
+++ b/src/zencore/include/zencore/session.h
@@ -3,6 +3,7 @@
#pragma once
#include <zencore/zencore.h>
+#include <string_view>
namespace zen {
diff --git a/src/zencore/include/zencore/sharedbuffer.h b/src/zencore/include/zencore/sharedbuffer.h
index 97c5a9d21..618bd2937 100644
--- a/src/zencore/include/zencore/sharedbuffer.h
+++ b/src/zencore/include/zencore/sharedbuffer.h
@@ -4,9 +4,9 @@
#include "zencore.h"
+#include <zenbase/refcount.h>
#include <zencore/iobuffer.h>
#include <zencore/memory.h>
-#include <zencore/refcount.h>
#include <memory.h>
diff --git a/src/zencore/include/zencore/stats.h b/src/zencore/include/zencore/stats.h
index e8e08f96a..7e745dc16 100644
--- a/src/zencore/include/zencore/stats.h
+++ b/src/zencore/include/zencore/stats.h
@@ -4,6 +4,8 @@
#include "zencore.h"
+#include <zenbase/concepts.h>
+
#include <atomic>
#include <random>
diff --git a/src/zencore/include/zencore/uid.h b/src/zencore/include/zencore/uid.h
index 557567473..3abec9d16 100644
--- a/src/zencore/include/zencore/uid.h
+++ b/src/zencore/include/zencore/uid.h
@@ -3,7 +3,9 @@
#pragma once
#include <zencore/zencore.h>
+
#include <compare>
+#include <string_view>
namespace zen {
diff --git a/src/zencore/include/zencore/workthreadpool.h b/src/zencore/include/zencore/workthreadpool.h
index c10c6ed12..62356495c 100644
--- a/src/zencore/include/zencore/workthreadpool.h
+++ b/src/zencore/include/zencore/workthreadpool.h
@@ -4,7 +4,7 @@
#include <zencore/zencore.h>
-#include <zencore/refcount.h>
+#include <zenbase/refcount.h>
#include <exception>
#include <functional>
diff --git a/src/zencore/include/zencore/zencore.h b/src/zencore/include/zencore/zencore.h
index 562376c95..e8c734ba9 100644
--- a/src/zencore/include/zencore/zencore.h
+++ b/src/zencore/include/zencore/zencore.h
@@ -2,243 +2,13 @@
#pragma once
-#include <cinttypes>
+#include <zenbase/zenbase.h>
#include <stdexcept>
-#include <string>
-#include <version>
#ifndef ZEN_WITH_TESTS
# define ZEN_WITH_TESTS 1
#endif
-//////////////////////////////////////////////////////////////////////////
-// Platform
-//
-
-#define ZEN_PLATFORM_WINDOWS 0
-#define ZEN_PLATFORM_LINUX 0
-#define ZEN_PLATFORM_MAC 0
-
-#ifdef _WIN32
-# undef ZEN_PLATFORM_WINDOWS
-# define ZEN_PLATFORM_WINDOWS 1
-# define ZEN_PLATFORM_NAME "Windows"
-#elif defined(__linux__)
-# undef ZEN_PLATFORM_LINUX
-# define ZEN_PLATFORM_LINUX 1
-# define ZEN_PLATFORM_NAME "Linux"
-#elif defined(__APPLE__)
-# undef ZEN_PLATFORM_MAC
-# define ZEN_PLATFORM_MAC 1
-# define ZEN_PLATFORM_NAME "MacOS"
-#endif
-
-#if ZEN_PLATFORM_WINDOWS
-# if !defined(NOMINMAX)
-# define NOMINMAX // stops Windows.h from defining 'min/max' macros
-# endif
-# if !defined(NOGDI)
-# define NOGDI
-# endif
-# if !defined(WIN32_LEAN_AND_MEAN)
-# define WIN32_LEAN_AND_MEAN // cut-down what Windows.h defines
-# endif
-#endif
-
-//////////////////////////////////////////////////////////////////////////
-// Compiler
-//
-
-#define ZEN_COMPILER_CLANG 0
-#define ZEN_COMPILER_MSC 0
-#define ZEN_COMPILER_GCC 0
-
-// Clang can define __GNUC__ and/or _MSC_VER so we check for Clang first
-#ifdef __clang__
-# undef ZEN_COMPILER_CLANG
-# define ZEN_COMPILER_CLANG 1
-#elif defined(_MSC_VER)
-# undef ZEN_COMPILER_MSC
-# define ZEN_COMPILER_MSC 1
-#elif defined(__GNUC__)
-# undef ZEN_COMPILER_GCC
-# define ZEN_COMPILER_GCC 1
-#else
-# error Unknown compiler
-#endif
-
-#if ZEN_COMPILER_MSC
-# pragma warning(disable : 4324) // warning C4324: '<type>': structure was padded due to alignment specifier
-# pragma warning(default : 4668) // warning C4668: 'symbol' is not defined as a preprocessor macro, replacing with '0' for 'directives'
-# pragma warning(default : 4100) // warning C4100: 'identifier' : unreferenced formal parameter
-# pragma warning( \
- disable : 4373) // '%$S': virtual function overrides '%$pS', previous versions of the compiler did not override when parameters
- // only differed by const/volatile qualifiers
- // https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4373
-#endif
-
-#ifndef ZEN_THIRD_PARTY_INCLUDES_START
-# if ZEN_COMPILER_MSC
-# define ZEN_THIRD_PARTY_INCLUDES_START \
- __pragma(warning(push)) __pragma(warning(disable : 4668)) /* C4668: use of undefined preprocessor macro */ \
- __pragma(warning(disable : 4305)) /* C4305: 'if': truncation from 'uint32' to 'bool' */ \
- __pragma(warning(disable : 4267)) /* C4267: '=': conversion from 'size_t' to 'US' */ \
- __pragma(warning(disable : 4127)) /* C4127: conditional expression is constant */ \
- __pragma(warning(disable : 4189)) /* C4189: local variable is initialized but not referenced */ \
- __pragma(warning(disable : 5105)) /* C5105: macro expansion producing 'defined' has undefined behavior */
-# elif ZEN_COMPILER_CLANG
-# define ZEN_THIRD_PARTY_INCLUDES_START \
- _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wundef\"") \
- _Pragma("clang diagnostic ignored \"-Wunused-parameter\"") _Pragma("clang diagnostic ignored \"-Wunused-variable\"")
-# elif ZEN_COMPILER_GCC
-# define ZEN_THIRD_PARTY_INCLUDES_START \
- _Pragma("GCC diagnostic push") /* NB. ignoring -Wundef doesn't work with GCC */ \
- _Pragma("GCC diagnostic ignored \"-Wunused-parameter\"") _Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
-# endif
-#endif
-
-#ifndef ZEN_THIRD_PARTY_INCLUDES_END
-# if ZEN_COMPILER_MSC
-# define ZEN_THIRD_PARTY_INCLUDES_END __pragma(warning(pop))
-# elif ZEN_COMPILER_CLANG
-# define ZEN_THIRD_PARTY_INCLUDES_END _Pragma("clang diagnostic pop")
-# elif ZEN_COMPILER_GCC
-# define ZEN_THIRD_PARTY_INCLUDES_END _Pragma("GCC diagnostic pop")
-# endif
-#endif
-
-#if ZEN_COMPILER_MSC
-# define ZEN_DEBUG_BREAK() \
- do \
- { \
- __debugbreak(); \
- } while (0)
-#else
-# define ZEN_DEBUG_BREAK() \
- do \
- { \
- __builtin_trap(); \
- } while (0)
-#endif
-
-//////////////////////////////////////////////////////////////////////////
-// C++20 support
-//
-
-// Clang
-#if ZEN_COMPILER_CLANG && __clang_major__ < 12
-# error clang-12 onwards is required for C++20 support
-#endif
-
-// GCC
-#if ZEN_COMPILER_GCC && __GNUC__ < 11
-# error GCC-11 onwards is required for C++20 support
-#endif
-
-// GNU libstdc++
-#if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 11
-# error GNU libstdc++-11 onwards is required for C++20 support
-#endif
-
-// LLVM libc++
-#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 12000
-# error LLVM libc++-12 onwards is required for C++20 support
-#endif
-
-// At the time of writing only ver >= 13 of LLVM's libc++ has an implementation
-// of std::integral. Some platforms like Ubuntu and Mac OS are still on 12.
-#if defined(__cpp_lib_concepts)
-# include <concepts>
-template<class T>
-concept Integral = std::integral<T>;
-template<class T>
-concept SignedIntegral = std::signed_integral<T>;
-template<class T>
-concept UnsignedIntegral = std::unsigned_integral<T>;
-template<class F, class... A>
-concept Invocable = std::invocable<F, A...>;
-template<class D, class B>
-concept DerivedFrom = std::derived_from<D, B>;
-#else
-template<class T>
-concept Integral = std::is_integral_v<T>;
-template<class T>
-concept SignedIntegral = Integral<T> && std::is_signed_v<T>;
-template<class T>
-concept UnsignedIntegral = Integral<T> && !std::is_signed_v<T>;
-template<class F, class... A>
-concept Invocable = requires(F&& f, A&&... a)
-{
- std::invoke(std::forward<F>(f), std::forward<A>(a)...);
-};
-template<class D, class B>
-concept DerivedFrom = std::is_base_of_v<B, D> && std::is_convertible_v<const volatile D*, const volatile B*>;
-#endif
-
-#if defined(__cpp_lib_ranges)
-template<typename T>
-concept ContiguousRange = std::ranges::contiguous_range<T>;
-#else
-template<typename T>
-concept ContiguousRange = true;
-#endif
-
-//////////////////////////////////////////////////////////////////////////
-// Architecture
-//
-
-#if defined(__amd64__) || defined(_M_X64)
-# define ZEN_ARCH_X64 1
-# define ZEN_ARCH_ARM64 0
-#elif defined(__arm64__) || defined(_M_ARM64)
-# define ZEN_ARCH_X64 0
-# define ZEN_ARCH_ARM64 1
-#else
-# error Unknown architecture
-#endif
-
-//////////////////////////////////////////////////////////////////////////
-// Build flavor
-//
-
-#ifdef NDEBUG
-# define ZEN_BUILD_DEBUG 0
-# define ZEN_BUILD_RELEASE 1
-# define ZEN_BUILD_NAME "release"
-#else
-# define ZEN_BUILD_DEBUG 1
-# define ZEN_BUILD_RELEASE 0
-# define ZEN_BUILD_NAME "debug"
-#endif
-
-//////////////////////////////////////////////////////////////////////////
-
-#define ZEN_PLATFORM_SUPPORTS_UNALIGNED_LOADS 1
-
-#if defined(__SIZEOF_WCHAR_T__) && __SIZEOF_WCHAR_T__ == 4
-# define ZEN_SIZEOF_WCHAR_T 4
-#else
-static_assert(sizeof(wchar_t) == 2, "wchar_t is expected to be two bytes in size");
-# define ZEN_SIZEOF_WCHAR_T 2
-#endif
-
-//////////////////////////////////////////////////////////////////////////
-// Assert
-//
-
-#if ZEN_PLATFORM_WINDOWS
-// Tells the compiler to put the decorated function in a certain section (aka. segment) of the executable.
-# define ZEN_CODE_SECTION(Name) __declspec(code_seg(Name))
-# define ZEN_DATA_SECTION(Name) __declspec(allocate(Name))
-# define ZEN_FORCENOINLINE __declspec(noinline) /* Force code to NOT be inline */
-# define LINE_TERMINATOR_ANSI "\r\n"
-#else
-# define ZEN_CODE_SECTION(Name)
-# define ZEN_DATA_SECTION(Name)
-# define ZEN_FORCENOINLINE
-# define LINE_TERMINATOR_ANSI "\n"
-#endif
-
#if ZEN_ARCH_ARM64
// On ARM we can't do this because the executable will require jumps larger
// than the branch instruction can handle. Clang will only generate
@@ -253,37 +23,36 @@ static_assert(sizeof(wchar_t) == 2, "wchar_t is expected to be two bytes in size
# define ZEN_DEBUG_SECTION ZEN_CODE_SECTION(".zcold")
#endif
-namespace zen
+namespace zen {
+class AssertException : public std::logic_error
{
- class AssertException : public std::logic_error
- {
- public:
- inline explicit AssertException(const char* Msg) : std::logic_error(Msg) {}
- };
+public:
+ inline explicit AssertException(const char* Msg) : std::logic_error(Msg) {}
+};
- struct AssertImpl
+struct AssertImpl
+{
+ static void ZEN_FORCENOINLINE ZEN_DEBUG_SECTION ExecAssert
+ [[noreturn]] (const char* Filename, int LineNumber, const char* FunctionName, const char* Msg)
{
- static void ZEN_FORCENOINLINE ZEN_DEBUG_SECTION ExecAssert
- [[noreturn]] (const char* Filename, int LineNumber, const char* FunctionName, const char* Msg)
- {
- CurrentAssertImpl->OnAssert(Filename, LineNumber, FunctionName, Msg);
- throw AssertException{Msg};
- }
-
- protected:
- virtual void ZEN_FORCENOINLINE ZEN_DEBUG_SECTION OnAssert(const char* Filename,
- int LineNumber,
- const char* FunctionName,
- const char* Msg)
- {
- (void(Filename));
- (void(LineNumber));
- (void(FunctionName));
- (void(Msg));
- }
- static AssertImpl DefaultAssertImpl;
- static AssertImpl* CurrentAssertImpl;
- };
+ CurrentAssertImpl->OnAssert(Filename, LineNumber, FunctionName, Msg);
+ throw AssertException{Msg};
+ }
+
+protected:
+ virtual void ZEN_FORCENOINLINE ZEN_DEBUG_SECTION OnAssert(const char* Filename,
+ int LineNumber,
+ const char* FunctionName,
+ const char* Msg)
+ {
+ (void(Filename));
+ (void(LineNumber));
+ (void(FunctionName));
+ (void(Msg));
+ }
+ static AssertImpl DefaultAssertImpl;
+ static AssertImpl* CurrentAssertImpl;
+};
} // namespace zen
@@ -309,31 +78,6 @@ namespace zen
//////////////////////////////////////////////////////////////////////////
-#ifdef __clang__
-template<typename T>
-auto ZenArrayCountHelper(T& t) -> typename std::enable_if<__is_array(T), char (&)[sizeof(t) / sizeof(t[0]) + 1]>::type;
-#else
-template<typename T, uint32_t N>
-char (&ZenArrayCountHelper(const T (&)[N]))[N + 1];
-#endif
-
-#define ZEN_ARRAY_COUNT(array) (sizeof(ZenArrayCountHelper(array)) - 1)
-
-//////////////////////////////////////////////////////////////////////////
-
-#if ZEN_COMPILER_MSC
-# define ZEN_NOINLINE __declspec(noinline)
-#else
-# define ZEN_NOINLINE __attribute__((noinline))
-#endif
-
-#if ZEN_PLATFORM_WINDOWS
-# define ZEN_EXE_SUFFIX_LITERAL ".exe"
-#else
-# define ZEN_EXE_SUFFIX_LITERAL ""
-#endif
-
-#define ZEN_UNUSED(...) ((void)__VA_ARGS__)
#define ZEN_NOT_IMPLEMENTED(...) ZEN_ASSERT(false, __VA_ARGS__)
#define ZENCORE_API // Placeholder to allow DLL configs in the future (maybe)
@@ -363,30 +107,6 @@ ZENCORE_API void zencore_forcelinktests();
//////////////////////////////////////////////////////////////////////////
-#if ZEN_COMPILER_MSC
-# define ZEN_DISABLE_OPTIMIZATION_ACTUAL __pragma(optimize("", off))
-# define ZEN_ENABLE_OPTIMIZATION_ACTUAL __pragma(optimize("", on))
-#elif ZEN_COMPILER_GCC
-# define ZEN_DISABLE_OPTIMIZATION_ACTUAL _Pragma("GCC push_options") _Pragma("GCC optimize (\"O0\")")
-# define ZEN_ENABLE_OPTIMIZATION_ACTUAL _Pragma("GCC pop_options")
-#elif ZEN_COMPILER_CLANG
-# define ZEN_DISABLE_OPTIMIZATION_ACTUAL _Pragma("clang optimize off")
-# define ZEN_ENABLE_OPTIMIZATION_ACTUAL _Pragma("clang optimize on")
-#endif
-
-// Set up optimization control macros, now that we have both the build settings and the platform macros
-#define ZEN_DISABLE_OPTIMIZATION ZEN_DISABLE_OPTIMIZATION_ACTUAL
-
-#if ZEN_BUILD_DEBUG
-# define ZEN_ENABLE_OPTIMIZATION ZEN_DISABLE_OPTIMIZATION_ACTUAL
-#else
-# define ZEN_ENABLE_OPTIMIZATION ZEN_ENABLE_OPTIMIZATION_ACTUAL
-#endif
-
-#define ZEN_ENABLE_OPTIMIZATION_ALWAYS ZEN_ENABLE_OPTIMIZATION_ACTUAL
-
-//////////////////////////////////////////////////////////////////////////
-
#ifndef ZEN_WITH_TRACE
# define ZEN_WITH_TRACE 0
#endif