11 #ifndef TLX_DIE_CORE_HEADER 12 #define TLX_DIE_CORE_HEADER 35 #define tlx_die_with_sstream(msg) \ 37 std::ostringstream oss__; \ 38 oss__ << msg << " @ " << __FILE__ << ':' << __LINE__; \ 39 ::tlx::die_with_message(oss__.str()); \ 44 #define tlx_die(msg) \ 46 tlx_die_with_sstream("DIE: " << msg); \ 65 #define tlx_die_unless(X) \ 68 ::tlx::die_with_message( \ 69 "DIE: Assertion \"" #X "\" failed!", __FILE__, __LINE__); \ 75 #define tlx_die_if(X) \ 78 ::tlx::die_with_message( \ 79 "DIE: Assertion \"" #X "\" succeeded!", __FILE__, __LINE__); \ 85 #define tlx_die_verbose_unless(X, msg) \ 88 tlx_die_with_sstream( \ 89 "DIE: Assertion \"" #X "\" failed!\n" << msg << '\n'); \ 95 #define tlx_die_verbose_if(X, msg) \ 98 tlx_die_with_sstream( \ 99 "DIE: Assertion \"" #X "\" succeeded!\n" << msg << '\n'); \ 107 template <
typename TypeA,
typename TypeB>
115 return std::strcmp(a, b) == 0;
121 return a != a ? b != b : a == b;
127 return a != a ? b != b : a == b;
132 #define tlx_die_unequal(X, Y) \ 136 if (!::tlx::die_equal_compare(x__, y__)) \ 137 tlx_die_with_sstream("DIE-UNEQUAL: " #X " != " #Y " : " \ 138 "\"" << x__ << "\" != \"" << y__ << "\""); \ 144 #define tlx_assert_equal(X, Y) 146 #define tlx_assert_equal(X, Y) die_unequal(X, Y) 152 #define tlx_die_verbose_unequal(X, Y, msg) \ 156 if (!::tlx::die_equal_compare(x__, y__)) \ 157 tlx_die_with_sstream("DIE-UNEQUAL: " #X " != " #Y " : " \ 158 "\"" << x__ << "\" != \"" << y__ << "\"\n" << \ 166 template <
typename Type>
168 return t < 0 ? -t : t;
172 template <
typename TypeA,
typename TypeB>
180 #define tlx_die_unequal_eps(X, Y, eps) \ 184 if (!::tlx::die_equal_eps_compare(x__, y__, eps)) \ 185 tlx_die("DIE-UNEQUAL-EPS: " #X " != " #Y " : " \ 186 << std::setprecision(18) \ 187 << "\"" << x__ << "\" != \"" << y__ << "\""); \ 193 #define tlx_die_verbose_unequal_eps(X, Y, eps, msg) \ 197 if (!::tlx::die_equal_eps_compare(x__, y__, eps)) \ 198 tlx_die("DIE-UNEQUAL-EPS: " #X " != " #Y " : " \ 199 << std::setprecision(18) \ 200 << "\"" << x__ << "\" != \"" << y__ << "\"\n" << \ 206 #define tlx_die_unequal_eps6(X, Y) \ 207 die_unequal_eps(X, Y, 1e-6) 212 #define tlx_die_verbose_unequal_eps6(X, Y, msg) \ 213 die_verbose_unequal_eps(X, Y, 1e-6, msg) 220 #define tlx_die_equal(X, Y) \ 224 if (::tlx::die_equal_compare(x__, y__)) \ 225 tlx_die_with_sstream("DIE-EQUAL: " #X " == " #Y " : " \ 226 "\"" << x__ << "\" == \"" << y__ << "\""); \ 232 #define tlx_assert_unequal(X, Y) 234 #define tlx_assert_unequal(X, Y) die_equal(X, Y) 240 #define tlx_die_verbose_equal(X, Y, msg) \ 244 if (::tlx::die_equal_compare(x__, y__)) \ 245 tlx_die_with_sstream("DIE-EQUAL: " #X " == " #Y " : " \ 246 "\"" << x__ << "\" == \"" << y__ << "\"\n" << \ 254 #define tlx_die_unless_throws(code, exception_type) \ 259 catch (const exception_type&) { \ 262 ::tlx::die_with_message( \ 263 "DIE-UNLESS-THROWS: " #code " - NO EXCEPTION " #exception_type, \ 264 __FILE__, __LINE__); \ 269 #endif // !TLX_DIE_CORE_HEADER Type die_unequal_eps_abs(const Type &t)
simple replacement for std::abs
bool set_die_with_exception(bool b)
bool die_equal_compare(TypeA a, TypeB b)
helper method to compare two values in die_unequal()
DieException(const std::string &message)
bool die_equal_eps_compare(TypeA x, TypeB y, double eps)
helper method to compare two values in die_unequal_eps()
void die_with_message(const std::string &msg)
die with message - either throw an exception or die via std::terminate()
Exception thrown by die_with_message() if.
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking