/*** Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: SysAssertions.hpp Date: 2021-7-14 Author: Reece ***/ //#pragma once <- AURORA_NO_ASSERTIONS may be redefined. do not cache #if !defined(AURORA_NO_ASSERTIONS) // defines SysAssert and SysAssertDbg #if defined(DEBUG) /// @private template static inline void SysAssertFileEx(const char *file, int fileno, const char *func, bool tru, T... args) { if (tru) { return; } Aurora::Console::Logging::WriteLinef( static_cast(Aurora::Console::Logging::ELogLevel::eError), Aurora::Console::EAnsiColor::eBoldRed, "Fatal", "Expression address: {} {}:{}", func, file, fileno); if constexpr (sizeof...(T) == 0) { SysPanic("That's all folks"); } else { SysPanic(args...); } } /** A simple assertion with an optional message */ #define SysAssert(tru, ...) \ do \ { \ SysAssertFileEx(__FILE__, __LINE__, __FUNCTION__, static_cast(tru), ## __VA_ARGS__); \ } while (0) /** A simple assertion with an optional message under debug targets */ #define SysAssertDbg SysAssert #else /// @private template static inline void SysAssertEx(bool tru, T... args) { if (tru) { return; } if constexpr (sizeof...(T) == 0) { SysPanic("That's all folks"); } else { SysPanic(args...); } } /** A simple assertion with an optional message */ #define SysAssert(tru, ...) \ do \ { \ SysAssertEx(static_cast(tru), ## __VA_ARGS__); \ } while (0) /** A simple assertion with an optional message under debug targets */ #define SysAssertDbg(tru, ...) do {} while (0) #endif // defines SysAssertExp and SysAssertDbgExp #if defined(DEBUG) /// @private template static inline void SysAssertFileExpEx(const char *file, int fileno, const char *func, const char *exp, bool tru, T... args) { if (tru) { return; } Aurora::Console::Logging::WriteLinef( static_cast(Aurora::Console::Logging::ELogLevel::eError), Aurora::Console::EAnsiColor::eBoldRed, "Fatal", "Expression address: {} {}:{}", func, file, fileno); Aurora::Console::Logging::WriteLinef( static_cast(Aurora::Console::Logging::ELogLevel::eError), Aurora::Console::EAnsiColor::eBoldRed, "Fatal", "Expression failed: {}", exp); if constexpr (sizeof...(T) == 0) { SysPanic("That's all folks"); } else { SysPanic(args...); } } /** A simple assertion with a debug expresison and optional message debugging */ #define SysAssertExp(tru, ...) \ do \ { \ SysAssertFileExpEx(__FILE__, __LINE__, __FUNCTION__, _AUKCON_STRINGIFY_X(tru), static_cast(tru), ## __VA_ARGS__); \ } while (0) /** A simple assertion with a debug expresison and optional message debugging under debug targets only */ #define SysAssertDbgExp SysAssertExp #else /// @private template static inline void SysAssertExpEx(const char *exp, bool tru, T... args) { if (tru) { return; } Aurora::Console::Logging::WriteLinef( static_cast(Aurora::Console::Logging::ELogLevel::eError), Aurora::Console::EAnsiColor::eBoldRed, "Fatal", "Expression failed: {}", exp); if constexpr (sizeof...(T) == 0) { SysPanic("That's all folks"); } else { SysPanic(args...); } } /** A simple assertion with a debug expresison and optional message debugging */ #define SysAssertExp(tru, ...) \ do \ { \ SysAssertExpEx(_AUKCON_STRINGIFY_X(tru), static_cast(tru), ## __VA_ARGS__); \ } while (0) /** A simple assertion with a debug expresison and optional message debugging under debug targets only */ #define SysAssertDbgExp(tru, ...) do {} while (0) #endif #endif