5#ifndef IV_SRC_CORE_ASSERT_HPP_
6#define IV_SRC_CORE_ASSERT_HPP_
20void assertionFailure(
const char *exprString,
const char *assertionMade,
const char *func,
const char *file,
int line);
36template<
typename... T>
59void assertionMessage(
const char *message,
const char *func,
const char *file,
int line);
68#define ASSERT_FUNCTION_ __extension__ __PRETTY_FUNCTION__
70#define ASSERT_FUNCTION_ __func__
77#define IV_ARG_CHECK(expr, msg, ...) \
81 iv::assert::throwInvalidArgument(msg, ASSERT_FUNCTION_, __FILE__); \
88#define IV_STATE_CHECK(expr) \
92 iv::assert::throwInvalidState(#expr, ASSERT_FUNCTION_, __FILE__); \
98#define IV_ASSERT(expr, assertion_made, ...) \
102 iv::assert::assertionFailure(#expr, assertion_made, ASSERT_FUNCTION_, __FILE__, __LINE__); \
108#define IV_ASSERT_NOMSG(expr, ...) \
112 iv::assert::assertionFailure(#expr, "", ASSERT_FUNCTION_, __FILE__, __LINE__); \
118#define IV_ASSERT_IMPLICATION(expr1, expr2, msg, ...) \
121 if ((expr1) && not(expr2)) \
122 iv::assert::assertionFailure(#expr1 " implies " #expr2, msg, ASSERT_FUNCTION_, __FILE__, __LINE__); \
128#define IV_ASSERT_NULL_POINTER(ptr) \
131 if ((ptr) == nullptr) \
132 iv::assert::assertionFailure(#ptr " is null", "", ASSERT_FUNCTION_, __FILE__, __LINE__); \
141#define IV_UNUSED iv::assert::ignoreParams
146#define IV_ASSERT_UNREACHABLE() iv::assert::assertUnreachable(__FILE__, __LINE__)
152#define IV_ASSERT_MSG(msg, ...) \
155 iv::assert::assertionMessage(msg, ASSERT_FUNCTION_, __FILE__, __LINE__); \
158static_assert(
sizeof(std::size_t) == 8 ||
sizeof(std::size_t) == 4,
"This platform has an unexpected size for size_t");
164void throwMissingCase(
const char *message,
const char *func,
const char *file);
166#define IV_MISSING_CASE_CHECK(msg, ...) \
169 throwMissingCase(#msg, __func__, __FILE__); \
175#define IV_ASSERT_EQUAL(expr1, expr2, assertion_made) \
178 if ((expr1) != (expr2)) \
179 iv::assert::assertionFailure(#expr1 " == " #expr2, assertion_made, __func__, __FILE__, __LINE__); \
void throwMissingCase(const char *message, const char *func, const char *file)
Definition assert.cpp:149
void assertionFailure(const char *exprString, const char *assertionMade, const char *func, const char *file, int line)
Definition assert.cpp:17
void assertionMessage(const char *message, const char *func, const char *file, int line)
Definition assert.cpp:87
void throwInvalidState(const char *expr, const char *func, const char *file)
Definition assert.cpp:61
void debugInfo(std::string_view message)
Definition assert.cpp:123
void debugMessage(std::string_view message)
Definition assert.cpp:131
void ignoreParams(T &&...args)
Definition assert.hpp:37
void debugError(std::string_view message)
Definition assert.cpp:139
void assertUnreachable(const char *file, int line)
Definition assert.cpp:69
void throwInvalidArgument(const char *message, const char *func, const char *file)
Definition assert.cpp:53
constexpr bool always_false
Definition assert.hpp:14
void ignoreParam(T &&)
Definition assert.hpp:32