- assertions - distributions new helper methods worked on stairs worked on grid-walkers worked on navigation
61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
#ifndef ASSERTIONS_H
|
|
#define ASSERTIONS_H
|
|
|
|
#include "Exception.h"
|
|
|
|
/**
|
|
* this file provides assertion methods that may be enabled to trace
|
|
* coding errors efficiently during debug or disabled to speed up the
|
|
* code execution for the release build
|
|
*
|
|
* compile with -DWITH_ASSERTIONS
|
|
*/
|
|
namespace Assert {
|
|
|
|
|
|
static inline void doThrow(const char* err) {
|
|
#ifdef WITH_ASSERTIONS
|
|
std::string str = "in: ";
|
|
str += __PRETTY_FUNCTION__;
|
|
str += " error: ";
|
|
str += err;
|
|
throw Exception(err);
|
|
#endif
|
|
}
|
|
|
|
template <typename T> static inline void equal(const T v1, const T v2, const char* err) {
|
|
if (v1 != v2) {doThrow(err);}
|
|
}
|
|
|
|
template <typename T> static inline void isTrue(const T v, const char* err) {
|
|
if (!v) {doThrow(err);}
|
|
}
|
|
|
|
template <typename T> static inline void isFalse(const T v, const char* err) {
|
|
if (v) {doThrow(err);}
|
|
}
|
|
|
|
template <typename T> static inline void isNull(const T v, const char* err) {
|
|
if (v != nullptr) {doThrow(err);}
|
|
}
|
|
|
|
template <typename T> static inline void isNotNull(const T v, const char* err) {
|
|
if (v == nullptr) {doThrow(err);}
|
|
}
|
|
|
|
template <typename T> static inline void isNotNaN(const T v, const char* err) {
|
|
if (v != v) {doThrow(err);}
|
|
}
|
|
|
|
template <typename T> static inline void isNot0(const T v, const char* err) {
|
|
if (v == 0) {doThrow(err);}
|
|
}
|
|
|
|
template <typename T> static inline void isBetween(const T v, const T min, const T max, const char* err) {
|
|
if (v < min || v > max) {doThrow(err);}
|
|
}
|
|
|
|
}
|
|
|
|
#endif // ASSERTIONS_H
|