24 lines
1.3 KiB
C++
24 lines
1.3 KiB
C++
|
#ifndef ARBUTILS_ASSERT_HPP
|
||
|
#define ARBUTILS_ASSERT_HPP
|
||
|
#include <sstream>
|
||
|
#include <stdexcept>
|
||
|
#include <string.h>
|
||
|
|
||
|
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
||
|
|
||
|
#ifndef NO_ASSERT
|
||
|
#define Assert(expr) \
|
||
|
{ \
|
||
|
if (!expr) { \
|
||
|
std::stringstream ss; \
|
||
|
ss << "ASSERTION FAILED: [" << __FILENAME__ << " (" << __LINE__ << ")] \""; \
|
||
|
ss << #expr << "\""; \
|
||
|
throw std::logic_error(ss.str()); \
|
||
|
} \
|
||
|
}
|
||
|
#else
|
||
|
// Assert is empty if NO_ASSERT is defined.
|
||
|
#define Assert(expr)
|
||
|
#endif
|
||
|
|
||
|
#endif
|