|
@ -19,6 +19,7 @@ |
|
|
#pragma once |
|
|
#pragma once |
|
|
|
|
|
|
|
|
#include <stdexcept> |
|
|
#include <stdexcept> |
|
|
|
|
|
#include <iostream> |
|
|
|
|
|
|
|
|
/** Macros */ |
|
|
/** Macros */ |
|
|
|
|
|
|
|
@ -27,9 +28,22 @@ |
|
|
#define STRINGIFY_HELPER(line) \ |
|
|
#define STRINGIFY_HELPER(line) \ |
|
|
STRINGIFY(line) |
|
|
STRINGIFY(line) |
|
|
|
|
|
|
|
|
|
|
|
#ifndef JESSILIB_ASSERT_MESSAGE |
|
|
|
|
|
#define JESSILIB_ASSERT_MESSAGE(expression) \ |
|
|
|
|
|
"Failed assertion: '" #expression "' at " __FILE__ ":" STRINGIFY_HELPER(__LINE__) |
|
|
|
|
|
#endif // JESSILIB_ASSERT_MESSAGE
|
|
|
|
|
|
|
|
|
// Returns a boolean expression indicating assertion success/failure
|
|
|
// Returns a boolean expression indicating assertion success/failure
|
|
|
|
|
|
#ifndef jessilib_assert |
|
|
#define jessilib_assert(expression) \ |
|
|
#define jessilib_assert(expression) \ |
|
|
(::jessilib::impl::_assert_helper( expression, "Failed assertion: '" #expression "' at " __FILE__ ":" STRINGIFY_HELPER(__LINE__) )) |
|
|
(::jessilib::impl::_assert_helper( expression, JESSILIB_ASSERT_MESSAGE(expression) )) |
|
|
|
|
|
#endif // jessilib_assert
|
|
|
|
|
|
|
|
|
|
|
|
// Similar to jessilib_assert, except exceptions are thrown only when NDEBUG is undefined
|
|
|
|
|
|
#ifndef jessilib_debug_assert |
|
|
|
|
|
#define jessilib_debug_assert(expression) \ |
|
|
|
|
|
(::jessilib::impl::_debug_assert_helper( expression, JESSILIB_ASSERT_MESSAGE(expression) )) |
|
|
|
|
|
#endif // jessilib_debug_assert
|
|
|
|
|
|
|
|
|
namespace jessilib { |
|
|
namespace jessilib { |
|
|
|
|
|
|
|
@ -44,25 +58,29 @@ namespace jessilib { |
|
|
namespace impl { |
|
|
namespace impl { |
|
|
|
|
|
|
|
|
/** Macro helpers */ |
|
|
/** Macro helpers */ |
|
|
inline bool _assert_helper(bool value, [[maybe_unused]] const char* message) { |
|
|
inline bool _assert_helper(bool value, const char* message) { |
|
|
#ifndef NDEBUG |
|
|
|
|
|
if (!value) { |
|
|
if (!value) { |
|
|
|
|
|
// TODO: wrap std::cerr
|
|
|
|
|
|
std::cerr << message << std::endl; |
|
|
|
|
|
|
|
|
throw assertion_failed{message}; |
|
|
throw assertion_failed{message}; |
|
|
} |
|
|
} |
|
|
#endif // NDEBUG
|
|
|
|
|
|
|
|
|
|
|
|
return value; |
|
|
return value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} // namespace impl
|
|
|
inline bool _debug_assert_helper(bool value, const char* message) { |
|
|
} // namespace jessilib
|
|
|
if (!value) { |
|
|
|
|
|
// TODO: wrap std::cerr
|
|
|
|
|
|
std::cerr << message << std::endl; |
|
|
|
|
|
|
|
|
// Provides for disabling of assertions; will likely produce warnings
|
|
|
#ifndef NDEBUG |
|
|
#ifdef DISABLE_ASSERTIONS |
|
|
throw assertion_failed{message}; |
|
|
|
|
|
#endif // NDEBUG
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Disable jessilib_assert
|
|
|
return value; |
|
|
#undef jessilib_assert |
|
|
} |
|
|
#define jessilib_assert(expression) \ |
|
|
|
|
|
(true) |
|
|
|
|
|
|
|
|
|
|
|
#endif // DISABLE_ASSERTIONS
|
|
|
} // namespace impl
|
|
|
|
|
|
} // namespace jessilib
|
|
|