tlx
Loading...
Searching...
No Matches
core.hpp File Reference
#include <cstring>
#include <iomanip>
#include <sstream>
#include <stdexcept>
#include <string>

Go to the source code of this file.

Classes

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

Namespaces

namespace  tlx

Macros

#define tlx_die_with_sstream(msg)
 Instead of std::terminate(), throw the output the message via an exception.
#define tlx_die(msg)
 Instead of std::terminate(), throw the output the message via an exception.
#define tlx_die_unless(X)
 Check condition X and die miserably if false.
#define tlx_die_if(X)
 Check condition X and die miserably if true.
#define tlx_die_verbose_unless(X, msg)
 Check condition X and die miserably if false.
#define tlx_die_verbose_if(X, msg)
 Check condition X and die miserably if false.
#define tlx_die_unequal(X, Y)
 Check that X == Y or die miserably, but output the values of X and Y for better debugging.
#define tlx_assert_equal(X, Y)
 Check that X == Y or die miserably, but output the values of X and Y for better debugging.
#define tlx_die_verbose_unequal(X, Y, msg)
 Check that X == Y or die miserably, but output the values of X and Y for better debugging.
#define tlx_die_unequal_eps(X, Y, eps)
 Check that ABS(X - Y) <= eps or die miserably, but output the values of X and Y for better debugging.
#define tlx_die_verbose_unequal_eps(X, Y, eps, msg)
 Check that ABS(X - Y) <= eps or die miserably, but output the values of X and Y for better debugging.
#define tlx_die_unequal_eps6(X, Y)
 Check that ABS(X - Y) <= 0.000001 or die miserably, but output the values of X and Y for better debugging.
#define tlx_die_verbose_unequal_eps6(X, Y, msg)
 Check that ABS(X - Y) <= 0.000001 or die miserably, but output the values of X and Y for better debugging.
#define tlx_die_equal(X, Y)
 Die miserably if X == Y, but first output the values of X and Y for better debugging.
#define tlx_assert_unequal(X, Y)
 Die miserably if X == Y, but first output the values of X and Y for better debugging.
#define tlx_die_verbose_equal(X, Y, msg)
 Die miserably if X == Y, but first output the values of X and Y for better debugging.
#define tlx_die_unless_throws(code, exception_type)
 Define to check that [code] throws and exception of given type.

Functions

void die_with_message (const std::string &msg)
 die with message - either throw an exception or die via std::terminate()
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()
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()
bool set_die_with_exception (bool b)
 Switch between dying via std::terminate() and throwing an exception.
template<typename TypeA, typename TypeB>
bool die_equal_compare (TypeA a, TypeB b)
 helper method to compare two values in die_unequal()
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 Type>
Type die_unequal_eps_abs (const Type &t)
 simple replacement for std::abs
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()

Macro Definition Documentation

◆ tlx_assert_equal

#define tlx_assert_equal ( 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 147 of file core.hpp.

◆ tlx_assert_unequal

#define tlx_assert_unequal ( 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 239 of file core.hpp.

◆ tlx_die

#define tlx_die ( msg)

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

Definition at line 44 of file core.hpp.

◆ tlx_die_equal

#define tlx_die_equal ( X,
Y )

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

Definition at line 224 of file core.hpp.

◆ tlx_die_if

#define tlx_die_if ( X)

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,
Y )

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.

◆ tlx_die_unequal_eps

#define tlx_die_unequal_eps ( X,
Y,
eps )

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

Definition at line 182 of file core.hpp.

◆ tlx_die_unequal_eps6

#define tlx_die_unequal_eps6 ( X,
Y )

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

Definition at line 210 of file core.hpp.

◆ tlx_die_unless

#define tlx_die_unless ( X)

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.

◆ tlx_die_unless_throws

#define tlx_die_unless_throws ( code,
exception_type )

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

Definition at line 260 of file core.hpp.

◆ tlx_die_verbose_equal

#define tlx_die_verbose_equal ( X,
Y,
msg )

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 245 of file core.hpp.

◆ tlx_die_verbose_if

#define tlx_die_verbose_if ( X,
msg )

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 )

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 153 of file core.hpp.

◆ tlx_die_verbose_unequal_eps

#define tlx_die_verbose_unequal_eps ( X,
Y,
eps,
msg )

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 196 of file core.hpp.

◆ tlx_die_verbose_unequal_eps6

#define tlx_die_verbose_unequal_eps6 ( X,
Y,
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 216 of file core.hpp.

◆ tlx_die_verbose_unless

#define tlx_die_verbose_unless ( X,
msg )

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)

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

Definition at line 35 of file core.hpp.