OGLplus
(0.59.0)
a C++ wrapper for rendering APIs
eagine
assert.hpp
Go to the documentation of this file.
1
#ifndef EAGINE_ASSERT_HPP
9
#define EAGINE_ASSERT_HPP
10
11
#include "
branch_predict.hpp
"
12
#include "config/basic.hpp"
13
#include "
diagnostic.hpp
"
14
#include "
maybe_unused.hpp
"
15
#include <cassert>
16
17
#ifndef EAGINE_CHECK_LIMIT_CAST
18
#if EAGINE_LOW_PROFILE
19
#define EAGINE_CHECK_LIMIT_CAST 0
20
#else
21
#define EAGINE_CHECK_LIMIT_CAST 1
22
#endif
23
#endif
24
25
#if EAGINE_USE_STACKTRACE
26
#include <iostream>
27
28
#ifdef __clang__
29
EAGINE_DIAG_PUSH()
30
EAGINE_DIAG_OFF(shadow)
31
#endif
32
33
#if EAGINE_USE_BACKTRACE
34
#define BOOST_STACKTRACE_USE_BACKTRACE 1
35
#endif
36
37
#define BOOST_ENABLE_ASSERT_DEBUG_HANDLER 1
38
39
#include <boost/assert.hpp>
40
#include <boost/stacktrace/stacktrace.hpp>
41
42
// clang-format off
43
44
namespace
boost {
45
//------------------------------------------------------------------------------
46
inline
void
assertion_failed(
47
const
char
* expression,
48
const
char
*
function
,
49
const
char
* filepath,
50
long
linenumber) {
51
std::cerr
52
<<
filepath
<<
':'
<< linenumber
53
<<
": assertion '"
54
<< expression
55
<<
"' failed in function `"
56
<<
function
57
<<
"`\n"
58
<<
"Backtrace:\n"
59
<< ::boost::stacktrace::stacktrace()
60
<< std::endl;
61
std::abort();
62
}
63
//------------------------------------------------------------------------------
64
inline
void
assertion_failed_msg(
65
const
char
* expression,
66
const
char
* message,
67
const
char
*
function
,
68
const
char
* filepath,
69
long
linenumber) {
70
std::cerr
71
<<
filepath
<<
':'
<< linenumber
72
<<
": assertion '"
73
<< expression
74
<<
"' failed in function `"
75
<<
function
76
<<
"`: "
77
<< (
message
?
message
:
"<...>"
)
78
<<
'\n'
79
<<
"Backtrace:\n"
80
<< ::boost::stacktrace::stacktrace()
81
<< std::endl;
82
std::abort();
83
}
84
//------------------------------------------------------------------------------
85
}
// namespace boost
86
87
#define EAGINE_ASSERT(EXPR) \
88
BOOST_ASSERT(EXPR) // NOLINT(hicpp-no-array-decay)
89
// clang-format on
90
91
#ifdef __clang__
92
EAGINE_DIAG_POP()
93
#endif
94
95
#else // EAGINE_USE_STACKTRACE
96
97
// clang-format off
98
#define EAGINE_ASSERT(EXPR) \
99
assert(EXPR) // NOLINT(cert-dcl03-c,hicpp-static-assert,hicpp-no-array-decay)
100
// clang-format on
101
102
#endif
103
104
#if EAGINE_CHECK_LIMIT_CAST
105
#define EAGINE_CONSTEXPR_ASSERT(UNUSED, RESULT) \
106
(EAGINE_MAYBE_UNUSED(UNUSED), RESULT)
107
#else
108
#define EAGINE_CONSTEXPR_ASSERT(CHECK, RESULT) \
109
((EAGINE_LIKELY(CHECK) ? void(0) \
110
: [] { EAGINE_ASSERT(!bool(#CHECK)); }()), \
111
RESULT)
112
#endif
113
114
#define EAGINE_ABORT(MSG) EAGINE_ASSERT(!bool(MSG))
115
#define EAGINE_UNREACHABLE(MSG) EAGINE_ABORT(MSG)
116
117
#endif // EAGINE_ASSERT_HPP
diagnostic.hpp
maybe_unused.hpp
branch_predict.hpp
eagine::msgbus::connection_protocol::message
@ message
Message protocol.
eagine::msgbus::connection_addr_kind::filepath
@ filepath
Filesystem path.
Copyright © 2015-2021
Matúš Chochlík
.
<
chochlik -at -gmail.com
>
Documentation generated on Tue Apr 13 2021 by
Doxygen
(version 1.8.17).