20 typedef bool (*
Handler)(
const std::string& message);
30 const std::string message;
36 virtual const char*
what() const noexcept
override {
37 return message.c_str();
53 template <
typename T0,
typename... TArgs>
54 static void stringify(std::stringstream& ss, T0&& t0, TArgs&&... rest) {
56 if (
sizeof...(TArgs) > 0) {
59 stringify(ss, std::forward<TArgs>(rest)...);
64 template <
typename... TArgs>
65 static void fire(
const char* message,
71 stringify(ss, std::forward<TArgs>(args)...);
72 fireParams(message, file, func, line, ss.str().c_str());
79 const char* params =
"");
81 static void todo(
const char* message,
const char* func,
const int line);
84 #define TODO(x) Assert::todo(x, __FUNCTION__, __LINE__);
87 #define SPH_ASSERT(x, ...) \
89 Assert::fire(#x, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
91 #define CONSTEXPR_SPH_ASSERT(x) assert(x)
92 #define SPH_ASSERT_UNEVAL(x, ...) SPH_ASSERT(x, ##__VA_ARGS__)
94 #define SPH_ASSERT(x, ...) MARK_USED(x)
95 #define CONSTEXPR_SPH_ASSERT(x) MARK_USED(x)
96 #define SPH_ASSERT_UNEVAL(x, ...)
100 #define NOT_IMPLEMENTED \
101 SPH_ASSERT(false, "not implemented"); \
102 throw Assert::Exception(std::string("Functionality not implemented in function ") + __PRETTY_FUNCTION__);
107 SPH_ASSERT(false, "stop"); \
108 throw std::exception();
112 template <
typename TDerived,
typename TBase>
114 static_assert(std::is_pointer<TDerived>::value,
"Must be a pointer type");
115 SPH_ASSERT(!value ||
dynamic_cast<TDerived
>(value) !=
nullptr, value);
116 return static_cast<TDerived
>(value);
119 #define SPH_STR(x) SPH_XSTR(x)
120 #define SPH_XSTR(x) #x
INLINE TDerived assert_cast(TBase *value)
#define SPH_ASSERT(x,...)
Global parameters of the code.
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
Exception(const std::string &message)
virtual const char * what() const noexcept override
ScopedAssertExceptionEnabler()
~ScopedAssertExceptionEnabler()
bool(* Handler)(const std::string &message)
static void fireParams(const char *message, const char *file, const char *func, const int line, const char *params="")
static void fire(const char *message, const char *file, const char *func, const int line, TArgs &&... args)
static void stringify(std::stringstream &UNUSED(ss))
static bool throwAssertException
If true, assert throws an exception.
static Handler handler
Custom assert handler.
static void todo(const char *message, const char *func, const int line)
static void stringify(std::stringstream &ss, T0 &&t0, TArgs &&... rest)