Thrill  0.1
core.hpp File Reference
#include <cstring>
#include <iomanip>
#include <sstream>
#include <stdexcept>
#include <string>
+ Include dependency graph for core.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  DieException
 Exception thrown by die_with_message() if. More...
 

Namespaces

 tlx
 

Macros

#define tlx_assert_equal(X, Y)   die_unequal(X, Y)
 
#define tlx_assert_unequal(X, Y)   die_equal(X, Y)
 
#define tlx_die(msg)
 Instead of std::terminate(), throw the output the message via an exception. More...
 
#define tlx_die_equal(X, Y)
 
#define tlx_die_if(X)
 
#define tlx_die_unequal(X, Y)
 
#define tlx_die_unequal_eps(X, Y, eps)
 
#define tlx_die_unequal_eps6(X, Y)   die_unequal_eps(X, Y, 1e-6)
 
#define tlx_die_unless(X)
 
#define tlx_die_unless_throws(code, exception_type)
 Define to check that [code] throws and exception of given type. More...
 
#define tlx_die_verbose_equal(X, Y, msg)
 
#define tlx_die_verbose_if(X, msg)
 
#define tlx_die_verbose_unequal(X, Y, msg)
 
#define tlx_die_verbose_unequal_eps(X, Y, eps, msg)
 
#define tlx_die_verbose_unequal_eps6(X, Y, msg)   die_verbose_unequal_eps(X, Y, 1e-6, msg)
 
#define tlx_die_verbose_unless(X, msg)
 
#define tlx_die_with_sstream(msg)
 Instead of std::terminate(), throw the output the message via an exception. More...
 

Functions

template<typename TypeA , typename TypeB >
bool die_equal_compare (TypeA a, TypeB b)
 helper method to compare two values in die_unequal() More...
 
template<>
bool die_equal_compare (const char *a, const char *b)
 
template<>
bool die_equal_compare (float a, float b)
 
template<>
bool die_equal_compare (double a, double b)
 
template<typename TypeA , typename TypeB >
bool die_equal_eps_compare (TypeA x, TypeB y, double eps)
 helper method to compare two values in die_unequal_eps() More...
 
template<typename Type >
Type die_unequal_eps_abs (const Type &t)
 simple replacement for std::abs More...
 
void die_with_message (const std::string &msg)
 die with message - either throw an exception or die via std::terminate() More...
 
void die_with_message (const char *msg, const char *file, size_t line)
 die with message - either throw an exception or die via std::terminate() More...
 
void die_with_message (const std::string &msg, const char *file, size_t line)
 die with message - either throw an exception or die via std::terminate() More...
 
bool set_die_with_exception (bool b)
 

Macro Definition Documentation

◆ tlx_assert_equal

#define tlx_assert_equal (   X,
 
)    die_unequal(X, Y)

Check that X == Y or die miserably, but output the values of X and Y for better debugging. Only active if NDEBUG is not defined.

Definition at line 146 of file core.hpp.

◆ tlx_assert_unequal

#define tlx_assert_unequal (   X,
 
)    die_equal(X, Y)

Die miserably if X == Y, but first output the values of X and Y for better debugging. Only active if NDEBUG is not defined.

Definition at line 234 of file core.hpp.

◆ tlx_die

#define tlx_die (   msg)
Value:
do { \
tlx_die_with_sstream("DIE: " << msg); \
} while (false)

Instead of std::terminate(), throw the output the message via an exception.

Definition at line 44 of file core.hpp.

Referenced by foxxll::print_library_version_mismatch().

◆ tlx_die_equal

#define tlx_die_equal (   X,
 
)
Value:
do { \
auto x__ = (X); /* NOLINT */ \
auto y__ = (Y); /* NOLINT */ \
if (::tlx::die_equal_compare(x__, y__)) \
tlx_die_with_sstream("DIE-EQUAL: " #X " == " #Y " : " \
"\"" << x__ << "\" == \"" << y__ << "\""); \
} while (false)
bool die_equal_compare(TypeA a, TypeB b)
helper method to compare two values in die_unequal()
Definition: core.hpp:108

Die miserably if X == Y, but first output the values of X and Y for better debugging.

Definition at line 220 of file core.hpp.

◆ tlx_die_if

#define tlx_die_if (   X)
Value:
do { \
if (X) { \
"DIE: Assertion \"" #X "\" succeeded!", __FILE__, __LINE__); \
} \
} while (false)
void die_with_message(const std::string &msg)
die with message - either throw an exception or die via std::terminate()
Definition: core.cpp:29

Check condition X and die miserably if true. Opposite of assert() except this is also active in Release mode.

Definition at line 75 of file core.hpp.

◆ tlx_die_unequal

#define tlx_die_unequal (   X,
 
)
Value:
do { \
auto x__ = (X); /* NOLINT */ \
auto y__ = (Y); /* NOLINT */ \
if (!::tlx::die_equal_compare(x__, y__)) \
tlx_die_with_sstream("DIE-UNEQUAL: " #X " != " #Y " : " \
"\"" << x__ << "\" != \"" << y__ << "\""); \
} while (false)
bool die_equal_compare(TypeA a, TypeB b)
helper method to compare two values in die_unequal()
Definition: core.hpp:108

Check that X == Y or die miserably, but output the values of X and Y for better debugging.

Definition at line 132 of file core.hpp.

Referenced by PerfectTreeCalculations< TreeBits >::self_verify().

◆ tlx_die_unequal_eps

#define tlx_die_unequal_eps (   X,
  Y,
  eps 
)
Value:
do { \
auto x__ = (X); /* NOLINT */ \
auto y__ = (Y); /* NOLINT */ \
if (!::tlx::die_equal_eps_compare(x__, y__, eps)) \
tlx_die("DIE-UNEQUAL-EPS: " #X " != " #Y " : " \
<< std::setprecision(18) \
<< "\"" << x__ << "\" != \"" << y__ << "\""); \
} while (false)
bool die_equal_eps_compare(TypeA x, TypeB y, double eps)
helper method to compare two values in die_unequal_eps()
Definition: core.hpp:173

Check that ABS(X - Y) <= eps or die miserably, but output the values of X and Y for better debugging.

Definition at line 180 of file core.hpp.

◆ tlx_die_unequal_eps6

#define tlx_die_unequal_eps6 (   X,
 
)    die_unequal_eps(X, Y, 1e-6)

Check that ABS(X - Y) <= 0.000001 or die miserably, but output the values of X and Y for better debugging.

Definition at line 206 of file core.hpp.

◆ tlx_die_unless

#define tlx_die_unless (   X)
Value:
do { \
if (!(X)) { \
"DIE: Assertion \"" #X "\" failed!", __FILE__, __LINE__); \
} \
} while (false)
void die_with_message(const std::string &msg)
die with message - either throw an exception or die via std::terminate()
Definition: core.cpp:29

Check condition X and die miserably if false. Same as assert() except this is also active in Release mode.

Definition at line 65 of file core.hpp.

Referenced by MultiTimer::print(), MultiTimer::start(), prefetch_pool< BlockType >::steal(), BTree< key_type, value_type, key_of_value, key_compare, traits, true, allocator_type >::verify(), BTree< key_type, value_type, key_of_value, key_compare, traits, true, allocator_type >::verify_leaflinks(), and BTree< key_type, value_type, key_of_value, key_compare, traits, true, allocator_type >::verify_node().

◆ tlx_die_unless_throws

#define tlx_die_unless_throws (   code,
  exception_type 
)
Value:
do { \
try { \
code; \
} \
catch (const exception_type&) { \
break; \
} \
"DIE-UNLESS-THROWS: " #code " - NO EXCEPTION " #exception_type, \
__FILE__, __LINE__); \
} while (false)
void die_with_message(const std::string &msg)
die with message - either throw an exception or die via std::terminate()
Definition: core.cpp:29

Define to check that [code] throws and exception of given type.

Definition at line 254 of file core.hpp.

◆ tlx_die_verbose_equal

#define tlx_die_verbose_equal (   X,
  Y,
  msg 
)
Value:
do { \
auto x__ = (X); /* NOLINT */ \
auto y__ = (Y); /* NOLINT */ \
if (::tlx::die_equal_compare(x__, y__)) \
tlx_die_with_sstream("DIE-EQUAL: " #X " == " #Y " : " \
"\"" << x__ << "\" == \"" << y__ << "\"\n" << \
msg << '\n'); \
} while (false)
bool die_equal_compare(TypeA a, TypeB b)
helper method to compare two values in die_unequal()
Definition: core.hpp:108

Die miserably if X == Y, but first output the values of X and Y for better debugging. Same as tlx_die_equal() except the user additionally passes a message.

Definition at line 240 of file core.hpp.

◆ tlx_die_verbose_if

#define tlx_die_verbose_if (   X,
  msg 
)
Value:
do { \
if ((X)) { \
tlx_die_with_sstream( \
"DIE: Assertion \"" #X "\" succeeded!\n" << msg << '\n'); \
} \
} while (false)

Check condition X and die miserably if false. Same as tlx_die_if() except the user additionally passes a message.

Definition at line 95 of file core.hpp.

◆ tlx_die_verbose_unequal

#define tlx_die_verbose_unequal (   X,
  Y,
  msg 
)
Value:
do { \
auto x__ = (X); /* NOLINT */ \
auto y__ = (Y); /* NOLINT */ \
if (!::tlx::die_equal_compare(x__, y__)) \
tlx_die_with_sstream("DIE-UNEQUAL: " #X " != " #Y " : " \
"\"" << x__ << "\" != \"" << y__ << "\"\n" << \
msg << '\n'); \
} while (false)
bool die_equal_compare(TypeA a, TypeB b)
helper method to compare two values in die_unequal()
Definition: core.hpp:108

Check that X == Y or die miserably, but output the values of X and Y for better debugging. Same as tlx_die_unequal() except the user additionally pass a message.

Definition at line 152 of file core.hpp.

◆ tlx_die_verbose_unequal_eps

#define tlx_die_verbose_unequal_eps (   X,
  Y,
  eps,
  msg 
)
Value:
do { \
auto x__ = (X); /* NOLINT */ \
auto y__ = (Y); /* NOLINT */ \
if (!::tlx::die_equal_eps_compare(x__, y__, eps)) \
tlx_die("DIE-UNEQUAL-EPS: " #X " != " #Y " : " \
<< std::setprecision(18) \
<< "\"" << x__ << "\" != \"" << y__ << "\"\n" << \
msg << '\n'); \
} while (false)
bool die_equal_eps_compare(TypeA x, TypeB y, double eps)
helper method to compare two values in die_unequal_eps()
Definition: core.hpp:173

Check that ABS(X - Y) <= eps or die miserably, but output the values of X and Y for better debugging. Same as tlx_die_unequal_eps() except the user additionally passes a message.

Definition at line 193 of file core.hpp.

◆ tlx_die_verbose_unequal_eps6

#define tlx_die_verbose_unequal_eps6 (   X,
  Y,
  msg 
)    die_verbose_unequal_eps(X, Y, 1e-6, msg)

Check that ABS(X - Y) <= 0.000001 or die miserably, but output the values of X and Y for better debugging. Same as tlx_die_unequal_eps6() except the user additionally passes a message.

Definition at line 212 of file core.hpp.

◆ tlx_die_verbose_unless

#define tlx_die_verbose_unless (   X,
  msg 
)
Value:
do { \
if (!(X)) { \
tlx_die_with_sstream( \
"DIE: Assertion \"" #X "\" failed!\n" << msg << '\n'); \
} \
} while (false)

Check condition X and die miserably if false. Same as tlx_die_unless() except the user additionally passes a message.

Definition at line 85 of file core.hpp.

◆ tlx_die_with_sstream

#define tlx_die_with_sstream (   msg)
Value:
do { \
std::ostringstream oss__; \
oss__ << msg << " @ " << __FILE__ << ':' << __LINE__; \
::tlx::die_with_message(oss__.str()); \
std::terminate(); /* tell compiler this never returns */ \
} while (false)
void die_with_message(const std::string &msg)
die with message - either throw an exception or die via std::terminate()
Definition: core.cpp:29

Instead of std::terminate(), throw the output the message via an exception.

Definition at line 35 of file core.hpp.