2020-03-22 10:14:47 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
|
|
|
|
|
|
|
#ifndef NO_ASSERT
|
|
|
|
#define Assert(expr) \
|
2020-03-22 11:20:39 +00:00
|
|
|
if (!(expr)) { \
|
|
|
|
std::stringstream ss; \
|
|
|
|
ss << "ASSERTION FAILED: [" << __FILENAME__ << " (" << __LINE__ << ")] \""; \
|
|
|
|
ss << #expr << "\""; \
|
|
|
|
throw std::logic_error(ss.str()); \
|
2020-03-22 11:02:02 +00:00
|
|
|
}
|
2020-04-28 14:55:00 +00:00
|
|
|
#define AssertForEach(iterator, assertion) \
|
|
|
|
{ \
|
|
|
|
for (auto item : iterator) \
|
|
|
|
Assert(assertion) \
|
|
|
|
}
|
2020-03-22 10:14:47 +00:00
|
|
|
#else
|
|
|
|
// Assert is empty if NO_ASSERT is defined.
|
2020-03-22 11:20:39 +00:00
|
|
|
#define Assert(expr) ;
|
2020-04-22 10:44:50 +00:00
|
|
|
#define AssertForEach(iterator, assertion) ;
|
2020-03-22 10:14:47 +00:00
|
|
|
#endif
|
|
|
|
|
2020-03-26 20:55:00 +00:00
|
|
|
#define AssertNotNull(value) Assert(value != nullptr)
|
2020-04-22 10:44:50 +00:00
|
|
|
#define AssertAllNotNull(iterator) AssertForEach(iterator, item != nullptr)
|