Skip to content

Commit

Permalink
Style changes; Minor debug flag detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Epixu committed Aug 30, 2023
1 parent 327e805 commit 6cc7b08
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 28 deletions.
27 changes: 15 additions & 12 deletions source/Core/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/// Safe mode enables assumption checks all over the code
/// High overhead, usually enabled only when testing in debug builds
#if defined(LANGULUS_ENABLE_SAFE_MODE) || defined(LANGULUS_ENABLE_ASSERTION_LEVEL)
#if defined(LANGULUS_ENABLE_SAFE_MODE) or defined(LANGULUS_ENABLE_ASSERTION_LEVEL)
#ifdef LANGULUS_ENABLE_ASSERTION_LEVEL
#define LANGULUS_SAFE() LANGULUS_ENABLE_ASSERTION_LEVEL
#else
Expand Down Expand Up @@ -63,7 +63,10 @@
#endif

/// Detect debug builds
#if defined(DEBUG) || !defined(NDEBUG) || defined(_DEBUG) || defined(CB_DEBUG) || defined(QT_QML_DEBUG) || defined(LANGULUS_ENABLE_DEBUGGING)
#if defined(LANGULUS_ENABLE_DEBUGGING) or defined(DEBUG) \
or defined(_DEBUG) \
or defined(CB_DEBUG) \
or defined(QT_QML_DEBUG)
#define LANGULUS_DEBUG() 1
#define DEBUGGERY(a) a
#else
Expand Down Expand Up @@ -114,21 +117,21 @@

/// Shamelessly stolen from boost and extended to my liking
/// Dumps the current function name
#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) || defined(__ghs__)
#if defined(__GNUC__) or (defined(__MWERKS__) and (__MWERKS__ >= 0x3000)) or (defined(__ICC) and (__ICC >= 600)) or defined(__ghs__)
#define LANGULUS_FUNCTION() __PRETTY_FUNCTION__
#elif defined(__clang__)
#define LANGULUS_FUNCTION() __PRETTY_FUNCTION__
#elif defined(__DMC__) && (__DMC__ >= 0x810)
#elif defined(__DMC__) and (__DMC__ >= 0x810)
#define LANGULUS_FUNCTION() __PRETTY_FUNCTION__
#elif defined(__FUNCSIG__) || defined(_MSC_VER)
#elif defined(__FUNCSIG__) or defined(_MSC_VER)
#define LANGULUS_FUNCTION() __FUNCSIG__
#elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500))
#elif (defined(__INTEL_COMPILER) and (__INTEL_COMPILER >= 600)) or (defined(__IBMCPP__) and (__IBMCPP__ >= 500))
#define LANGULUS_FUNCTION() __FUNCTION__
#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
#elif defined(__BORLANDC__) and (__BORLANDC__ >= 0x550)
#define LANGULUS_FUNCTION() __FUNC__
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
#elif defined(__STDC_VERSION__) and (__STDC_VERSION__ >= 199901)
#define LANGULUS_FUNCTION() __func__
#elif defined(__cplusplus) && (__cplusplus >= 201103)
#elif defined(__cplusplus) and (__cplusplus >= 201103)
#define LANGULUS_FUNCTION() __func__
#else
#error Not implemented
Expand All @@ -145,7 +148,7 @@

#define LANGULUS_OS(a) LANGULUS_OS_##a()

#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(_WIN32) or defined(__CYGWIN__)
#define LANGULUS_OS_WINDOWS() 1
#else
#define LANGULUS_OS_WINDOWS() 0
Expand Down Expand Up @@ -183,7 +186,7 @@

/// Shared object export/import attributes
#ifdef LANGULUS_BUILD_SHARED_LIBRARIES
#if LANGULUS_COMPILER(GCC) || LANGULUS_COMPILER(CLANG)
#if LANGULUS_COMPILER(GCC) or LANGULUS_COMPILER(CLANG)
#if LANGULUS_OS(WINDOWS)
#define LANGULUS_EXPORT() __attribute__ ((dllexport))
#define LANGULUS_IMPORT() __attribute__ ((dllimport))
Expand All @@ -193,7 +196,7 @@
#else
#error Not implemented
#endif
#elif LANGULUS_COMPILER(MSVC) || LANGULUS_COMPILER(MINGW)
#elif LANGULUS_COMPILER(MSVC) or LANGULUS_COMPILER(MINGW)
#define LANGULUS_EXPORT() __declspec(dllexport)
#define LANGULUS_IMPORT() __declspec(dllimport)
#else
Expand Down
69 changes: 53 additions & 16 deletions source/Core/Utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,26 @@ namespace Langulus
/// Similar to std::isalpha, but constexpr
NOD() LANGULUS(INLINED)
constexpr Letter IsAlpha(const Letter a) noexcept {
return (a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z');
return (a >= 'a' and a <= 'z')
or (a >= 'A' and a <= 'Z');
}

/// Similar to std::isspace, but constexpr
NOD() LANGULUS(INLINED)
constexpr Letter IsSpace(const Letter a) noexcept {
return a == ' ' || a == '\t' || a == '\n' || a == '\r' || a == '\f' || a == '\v';
return a == ' '
or a == '\t'
or a == '\n'
or a == '\r'
or a == '\f'
or a == '\v';
}

/// Similar to std::isdigit, but constexpr
NOD() LANGULUS(INLINED)
constexpr Letter IsDigit(const Letter a) noexcept {
return a >= '0' && a <= '9';
return a >= '0'
and a <= '9';
}

/// Forward lvalue as either lvalue or rvalue
Expand All @@ -40,7 +47,7 @@ namespace Langulus
template<class T>
NOD() LANGULUS(INLINED)
constexpr T&& Forward(Deref<T>&& a) noexcept {
static_assert(!::std::is_lvalue_reference_v<T>, "Bad forward call");
static_assert(not ::std::is_lvalue_reference_v<T>, "Bad forward call");
return static_cast<T&&>(a);
}

Expand Down Expand Up @@ -291,11 +298,15 @@ namespace Langulus
template<class TO, class FROM>
LANGULUS(INLINED)
void CopyMemory(TO* to, const FROM* from) noexcept {
static_assert(CT::Void<TO> || CT::Sparse<TO> || CT::POD<TO> || ::std::is_trivial_v<TO>,
static_assert(CT::Void<TO>
or CT::Sparse<TO>
or CT::POD<TO>
or ::std::is_trivial_v<TO>,
"TO must be either pointer, reflected as POD, or trivial. "
"(you can suppress this error by casting pointer to void*)");

static_assert(CT::Void<TO> || (CT::Same<TO, FROM> && CT::Sparse<TO> == CT::Sparse<FROM>),
static_assert(CT::Void<TO>
or(CT::Same<TO, FROM> and CT::Sparse<TO> == CT::Sparse<FROM>),
"TO and FROM must be the exact same types"
"(you can suppress this error by casting pointer to void*)");

Expand All @@ -319,11 +330,15 @@ namespace Langulus
template<class TO, class FROM>
LANGULUS(INLINED)
void CopyMemory(TO* to, const FROM* from, const Count& count) noexcept {
static_assert(CT::Void<TO> || CT::Sparse<TO> || CT::POD<TO> || ::std::is_trivial_v<TO>,
static_assert(CT::Void<TO>
or CT::Sparse<TO>
or CT::POD<TO>
or ::std::is_trivial_v<TO>,
"TO must be either pointer, reflected as POD, or trivial. "
"(you can suppress this error by casting pointer to void*)");

static_assert(CT::Void<TO> || (CT::Same<TO, FROM> && CT::Sparse<TO> == CT::Sparse<FROM>),
static_assert(CT::Void<TO>
or(CT::Same<TO, FROM> and CT::Sparse<TO> == CT::Sparse<FROM>),
"TO and FROM must be the exact same types"
"(you can suppress this error by casting pointer to void*)");

Expand All @@ -350,11 +365,18 @@ namespace Langulus
template<int FILLER, class TO>
LANGULUS(INLINED)
void FillMemory(TO* to) noexcept {
static_assert(CT::Void<TO> || CT::Sparse<TO> || CT::POD<TO> || ::std::is_trivial_v<TO>,
static_assert(CT::Void<TO>
or CT::Sparse<TO>
or CT::POD<TO>
or ::std::is_trivial_v<TO>,
"TO must be either pointer, reflected as POD, or trivial. "
"(you can suppress this error by casting to void*)");

static_assert(FILLER || CT::Nullifiable<TO> || CT::Void<TO> || CT::Sparse<TO> || CT::Fundamental<TO>,
static_assert(FILLER
or CT::Nullifiable<TO>
or CT::Void<TO>
or CT::Sparse<TO>
or CT::Fundamental<TO>,
"Filling with zeroes requires the type to be reflected as nullifiable, "
"or be a pointer/fundamental (you can suppress this error by casting to void*)");

Expand All @@ -373,11 +395,18 @@ namespace Langulus
template<int FILLER, class TO>
LANGULUS(INLINED)
void FillMemory(TO* to, const Count& count) noexcept {
static_assert(CT::Void<TO> || CT::Sparse<TO> || CT::POD<TO> || ::std::is_trivial_v<TO>,
static_assert(CT::Void<TO>
or CT::Sparse<TO>
or CT::POD<TO>
or ::std::is_trivial_v<TO>,
"TO must be either pointer, reflected as POD, or trivial. "
"(you can suppress this error by casting to void*)");

static_assert(FILLER || CT::Nullifiable<TO> || CT::Void<TO> || CT::Sparse<TO> || CT::Fundamental<TO>,
static_assert(FILLER
or CT::Nullifiable<TO>
or CT::Void<TO>
or CT::Sparse<TO>
or CT::Fundamental<TO>,
"Filling with zeroes requires the type to be reflected as nullifiable, "
"or be a pointer/fundamental (you can suppress this error by casting to void*)");

Expand Down Expand Up @@ -415,11 +444,15 @@ namespace Langulus
template<class TO, class FROM>
LANGULUS(INLINED)
void MoveMemory(TO* to, const FROM* from) noexcept {
static_assert(CT::Void<TO> || CT::Sparse<TO> || CT::POD<TO> || ::std::is_trivial_v<TO>,
static_assert(CT::Void<TO>
or CT::Sparse<TO>
or CT::POD<TO>
or ::std::is_trivial_v<TO>,
"TO must be either pointer, reflected as POD, or trivial. "
"(You can suppress this error by casting pointer to void*)");

static_assert(CT::Void<TO> || (CT::Same<TO, FROM> && CT::Sparse<TO> == CT::Sparse<FROM>),
static_assert(CT::Void<TO>
or(CT::Same<TO, FROM> and CT::Sparse<TO> == CT::Sparse<FROM>),
"TO and FROM must be the exact same types"
"(you can suppress this error by casting pointer to void*)");

Expand Down Expand Up @@ -447,11 +480,15 @@ namespace Langulus
template<class TO, class FROM>
LANGULUS(INLINED)
void MoveMemory(TO* to, const FROM* from, const Count& count) noexcept {
static_assert(CT::Void<TO> || CT::Sparse<TO> || CT::POD<TO> || ::std::is_trivial_v<TO>,
static_assert(CT::Void<TO>
or CT::Sparse<TO>
or CT::POD<TO>
or ::std::is_trivial_v<TO>,
"TO must be either pointer, reflected as POD, or trivial. "
"(You can suppress this error by casting pointer to void*)");

static_assert(CT::Void<TO> || (CT::Same<TO, FROM> && CT::Sparse<TO> == CT::Sparse<FROM>),
static_assert(CT::Void<TO>
or(CT::Same<TO, FROM> and CT::Sparse<TO> == CT::Sparse<FROM>),
"TO and FROM must be the exact same types"
"(you can suppress this error by casting pointer to void*)");

Expand Down

0 comments on commit 6cc7b08

Please sign in to comment.