Thrill  0.1
die.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/die.hpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2018 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
11 #ifndef TLX_DIE_HEADER
12 #define TLX_DIE_HEADER
13 
14 #include <tlx/die/core.hpp>
15 
16 namespace tlx {
17 
18 /******************************************************************************/
19 // die macros
20 
21 //! Instead of std::terminate(), throw the output the message via an exception.
22 #define die(msg) \
23  tlx_die(msg)
24 
25 //! Check condition X and die miserably if false. Same as assert() except this
26 //! is also active in Release mode.
27 #define die_unless(X) \
28  tlx_die_unless(X)
29 
30 //! Check condition X and die miserably if true. Opposite of assert() except
31 //! this is also active in Release mode.
32 #define die_if(X) \
33  tlx_die_if(X)
34 
35 //! Check condition X and die miserably if false. Same as die_unless() except
36 //! the user additionally passes a message.
37 #define die_verbose_unless(X, msg) \
38  tlx_die_verbose_unless(X, msg)
39 
40 //! Check condition X and die miserably if false. Same as die_if() except the
41 //! the user additionally passes a message.
42 #define die_verbose_if(X, msg) \
43  tlx_die_verbose_if(X, msg)
44 
45 /******************************************************************************/
46 // die_unequal()
47 
48 //! Check that X == Y or die miserably, but output the values of X and Y for
49 //! better debugging.
50 #define die_unequal(X, Y) \
51  tlx_die_unequal(X, Y)
52 
53 //! Check that X == Y or die miserably, but output the values of X and Y for
54 //! better debugging. Only active if NDEBUG is not defined.
55 #define assert_equal(X, Y) \
56  tlx_assert_equal(X, Y)
57 
58 //! Check that X == Y or die miserably, but output the values of X and Y for
59 //! better debugging. Same as die_unequal() except the user additionally passes
60 //! a message.
61 #define die_verbose_unequal(X, Y, msg) \
62  tlx_die_verbose_unequal(X, Y, msg)
63 
64 /******************************************************************************/
65 // die_unequal_eps()
66 
67 //! Check that ABS(X - Y) <= eps or die miserably, but output the values of X
68 //! and Y for better debugging.
69 #define die_unequal_eps(X, Y, eps) \
70  tlx_die_unequal_eps(X, Y, eps)
71 
72 //! Check that ABS(X - Y) <= eps or die miserably, but output the values of X
73 //! and Y for better debugging. Same as die_unequal_eps() except the user
74 //! additionally passes a message.
75 #define die_verbose_unequal_eps(X, Y, eps, msg) \
76  tlx_die_verbose_unequal_eps(X, Y, eps, msg)
77 
78 //! Check that ABS(X - Y) <= 0.000001 or die miserably, but output the values of
79 //! X and Y for better debugging.
80 #define die_unequal_eps6(X, Y) \
81  tlx_die_unequal_eps6(X, Y)
82 
83 //! Check that ABS(X - Y) <= 0.000001 or die miserably, but output the values of
84 //! X and Y for better debugging. Same as die_unequal_eps6() except the user
85 //! additionally passes a message.
86 #define die_verbose_unequal_eps6(X, Y, msg) \
87  tlx_die_verbose_unequal_eps6(X, Y, msg)
88 
89 /******************************************************************************/
90 // die_equal()
91 
92 //! Die miserably if X == Y, but first output the values of X and Y for better
93 //! debugging.
94 #define die_equal(X, Y) \
95  tlx_die_equal(X, Y)
96 
97 //! Die miserably if X == Y, but first output the values of X and Y for better
98 //! debugging. Only active if NDEBUG is not defined.
99 #define assert_unequal(X, Y) \
100  tlx_assert_unequal(X, Y)
101 
102 //! Die miserably if X == Y, but first output the values of X and Y for better
103 //! debugging. Same as die_equal() except the user additionally passes a
104 //! message.
105 #define die_verbose_equal(X, Y, msg) \
106  tlx_die_verbose_equal(X, Y, msg)
107 
108 /******************************************************************************/
109 // die_unless_throws()
110 
111 //! Define to check that [code] throws and exception of given type
112 #define die_unless_throws(code, exception_type) \
113  tlx_die_unless_throws(code, exception_type)
114 
115 } // namespace tlx
116 
117 #endif // !TLX_DIE_HEADER
118 
119 /******************************************************************************/