NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
NW4RAssert.hpp
1
// clang-format off
2
3
/*******************************************************************************
4
* anti-header guard
5
*/
6
7
#ifdef __MWERKS__
8
# pragma notonce
9
#endif
10
11
/*******************************************************************************
12
* NW4RAssert/NW4RCheck base macros
13
*/
14
15
// <assert.h> behavior
16
#undef NW4RAssertMessage_FileLine
17
#undef NW4RCheckMessage_FileLine
18
19
#if defined(NW4R_ASSERT)
20
# define NW4RAssertMessage_FileLine(file_, line_, expr_, ...) ((void)((expr_) || (::nw4r::db::Panic (file_, line_, __VA_ARGS__), 0)))
21
# define NW4RCheckMessage_FileLine(file_, line_, expr_, ...) ((void)((expr_) || (::nw4r::db::Warning(file_, line_, __VA_ARGS__), 0)))
22
#else
23
# define NW4RAssertMessage_FileLine(file_, line_, expr_, ...) ((void)(0))
24
# define NW4RCheckMessage_FileLine(file_, line_, expr_, ...) ((void)(0))
25
#endif
// defined(NW4R_ASSERT)
26
27
/*******************************************************************************
28
* Derived macros
29
*/
30
31
/* Main asserts */
32
33
// NW4RAssert family
34
#define NW4RAssertMessage_File(file_, expr_, ...) NW4RAssertMessage_FileLine( file_ , __LINE__, expr_, __VA_ARGS__)
35
#define NW4RAssertMessage_Line(line_, expr_, ...) NW4RAssertMessage_FileLine(__FILE__, line_ , expr_, __VA_ARGS__)
36
#define NW4RAssertMessage(expr_, ...) NW4RAssertMessage_FileLine(__FILE__, __LINE__, expr_, __VA_ARGS__)
37
38
#define NW4RAssert_FileLine(file_, line_, expr_) NW4RAssertMessage_FileLine( file_ , line_ , expr_, "NW4R:Failed assertion " #expr_)
39
#define NW4RAssert_File(file_, expr_) NW4RAssertMessage_FileLine( file_ , __LINE__, expr_, "NW4R:Failed assertion " #expr_)
40
#define NW4RAssert_Line(line_, expr_) NW4RAssertMessage_FileLine(__FILE__, line_ , expr_, "NW4R:Failed assertion " #expr_)
41
#define NW4RAssert(expr_) NW4RAssertMessage_FileLine(__FILE__, __LINE__, expr_, "NW4R:Failed assertion " #expr_)
42
43
#define NW4RAssertHeader_FileLine(file_, line_, expr_) NW4RAssertMessage_FileLine( file_ , line_ , expr_, "Failed assertion " #expr_)
44
#define NW4RAssertHeader_File(file_, expr_) NW4RAssertMessage_FileLine( file_ , __LINE__, expr_, "Failed assertion " #expr_)
45
#define NW4RAssertHeader_Line(line_, expr_) NW4RAssertMessage_FileLine(__FILE__, line_ , expr_, "Failed assertion " #expr_)
46
#define NW4RAssertHeader(expr_) NW4RAssertMessage_FileLine(__FILE__, __LINE__, expr_, "Failed assertion " #expr_)
47
48
// NW4RPanic family
49
#define NW4RPanicMessage_FileLine(file_, line_, ...) NW4RAssertMessage_FileLine( file_ , line_ , false, __VA_ARGS__)
50
#define NW4RPanicMessage_File(file_, ...) NW4RAssertMessage_FileLine( file_ , __LINE__, false, __VA_ARGS__)
51
#define NW4RPanicMessage_Line(line_, ...) NW4RAssertMessage_FileLine(__FILE__, line_ , false, __VA_ARGS__)
52
#define NW4RPanicMessage(...) NW4RAssertMessage_FileLine(__FILE__, __LINE__, false, __VA_ARGS__)
53
54
#define NW4RPanic_FileLine(file_, line_) NW4RAssert_FileLine( file_ , line_ , false)
55
#define NW4RPanic_File(file_) NW4RAssert_FileLine( file_ , __LINE__, false)
56
#define NW4RPanic_Line(line_) NW4RAssert_FileLine(__FILE__, line_ , false)
57
#define NW4RPanic() NW4RAssert_FileLine(__FILE__, __LINE__, false)
58
59
// NW4RCheck family
60
#define NW4RCheckMessage_File(file_, expr_, ...) NW4RCheckMessage_FileLine( file_ , __LINE__, expr_, __VA_ARGS__)
61
#define NW4RCheckMessage_Line(line_, expr_, ...) NW4RCheckMessage_FileLine(__FILE__, line_ , expr_, __VA_ARGS__)
62
#define NW4RCheckMessage(expr_, ...) NW4RCheckMessage_FileLine(__FILE__, __LINE__, expr_, __VA_ARGS__)
63
64
#define NW4RCheck_FileLine(file_, line_, expr_) NW4RCheckMessage_FileLine( file_ , line_ , expr_, "NW4R:Failed check " #expr_)
65
#define NW4RCheck_File(file_, expr_) NW4RCheckMessage_FileLine( file_ , __LINE__, expr_, "NW4R:Failed check " #expr_)
66
#define NW4RCheck_Line(line_, expr_) NW4RCheckMessage_FileLine(__FILE__, line_ , expr_, "NW4R:Failed check " #expr_)
67
#define NW4RCheck(expr_) NW4RCheckMessage_FileLine(__FILE__, __LINE__, expr_, "NW4R:Failed check " #expr_)
68
69
#define NW4RCheckHeader_FileLine(file_, line_, expr_) NW4RCheckMessage_FileLine( file_ , line_ , expr_, "Failed check " #expr_)
70
#define NW4RCheckHeader_File(file_, expr_) NW4RCheckMessage_FileLine( file_ , __LINE__, expr_, "Failed check " #expr_)
71
#define NW4RCheckHeader_Line(line_, expr_) NW4RCheckMessage_FileLine(__FILE__, line_ , expr_, "Failed check " #expr_)
72
#define NW4RCheckHeader(expr_) NW4RCheckMessage_FileLine(__FILE__, __LINE__, expr_, "Failed check " #expr_)
73
74
// NW4RWarning family
75
#define NW4RWarningMessage_FileLine(file_, line_, ...) NW4RCheckMessage_FileLine( file_ , line_ , false, __VA_ARGS__)
76
#define NW4RWarningMessage_File(file_, ...) NW4RCheckMessage_FileLine( file_ , __LINE__, false, __VA_ARGS__)
77
#define NW4RWarningMessage_Line(line_, ...) NW4RCheckMessage_FileLine(__FILE__, line_ , false, __VA_ARGS__)
78
#define NW4RWarningMessage(...) NW4RCheckMessage_FileLine(__FILE__, __LINE__, false, __VA_ARGS__)
79
80
#define NW4RWarning_FileLine(file_, line_) NW4RCheck_FileLine( file_ , line_ , false)
81
#define NW4RWarning_File(file_) NW4RCheck_FileLine( file_ , __LINE__, false)
82
#define NW4RWarning_Line(line_) NW4RCheck_FileLine(__FILE__, line_ , false)
83
#define NW4RWarning() NW4RCheck_FileLine(__FILE__, __LINE__, false)
84
85
/* Extended asserts */
86
87
// PointerNonnull
88
#define NW4RAssertPointerNonnull_FileLine(file_, line_, ptr_) NW4RAssertMessage_FileLine( file_ , line_ , (ptr_) != 0, "NW4R:Pointer must not be NULL (" #ptr_ ")")
89
#define NW4RAssertPointerNonnull_File(file_, ptr_) NW4RAssertMessage_FileLine( file_ , __LINE__, (ptr_) != 0, "NW4R:Pointer must not be NULL (" #ptr_ ")")
90
#define NW4RAssertPointerNonnull_Line(line_, ptr_) NW4RAssertMessage_FileLine(__FILE__, line_ , (ptr_) != 0, "NW4R:Pointer must not be NULL (" #ptr_ ")")
91
#define NW4RAssertPointerNonnull(ptr_) NW4RAssertMessage_FileLine(__FILE__, __LINE__, (ptr_) != 0, "NW4R:Pointer must not be NULL (" #ptr_ ")")
92
93
#define NW4RAssertHeaderPointerNonnull_FileLine(file_, line_, ptr_) NW4RAssertMessage_FileLine( file_ , line_ , (ptr_) != 0, "Pointer must not be NULL (" #ptr_ ")")
94
#define NW4RAssertHeaderPointerNonnull_File(file_, ptr_) NW4RAssertMessage_FileLine( file_ , __LINE__, (ptr_) != 0, "Pointer must not be NULL (" #ptr_ ")")
95
#define NW4RAssertHeaderPointerNonnull_Line(line_, ptr_) NW4RAssertMessage_FileLine(__FILE__, line_ , (ptr_) != 0, "Pointer must not be NULL (" #ptr_ ")")
96
#define NW4RAssertHeaderPointerNonnull(ptr_) NW4RAssertMessage_FileLine(__FILE__, __LINE__, (ptr_) != 0, "Pointer must not be NULL (" #ptr_ ")")
97
98
// Aligned
99
#define NW4R_IS_ALIGNED_(x, align) (((unsigned long)(x) & ((align) - 1)) == 0)
// just redefine instead of pulling in <macros.h>
100
101
#define NW4RAssertAligned_FileLine(file_, line_, val_, align_) NW4RAssertMessage_FileLine( file_ , line_ , NW4R_IS_ALIGNED_(val_, align_), "NW4R:Alignment Error(0x%x)\n" #val_ " must be aligned to " #align_ " bytes boundary.", val_)
102
#define NW4RAssertAligned_File(file_, val_, align_) NW4RAssertMessage_FileLine( file_ , __LINE__, NW4R_IS_ALIGNED_(val_, align_), "NW4R:Alignment Error(0x%x)\n" #val_ " must be aligned to " #align_ " bytes boundary.", val_)
103
#define NW4RAssertAligned_Line(line_, val_, align_) NW4RAssertMessage_FileLine(__FILE__, line_ , NW4R_IS_ALIGNED_(val_, align_), "NW4R:Alignment Error(0x%x)\n" #val_ " must be aligned to " #align_ " bytes boundary.", val_)
104
#define NW4RAssertAligned(val_, align_) NW4RAssertMessage_FileLine(__FILE__, __LINE__, NW4R_IS_ALIGNED_(val_, align_), "NW4R:Alignment Error(0x%x)\n" #val_ " must be aligned to " #align_ " bytes boundary.", val_)
105
106
#define NW4RAssertHeaderAligned_FileLine(file_, line_, val_, align_) NW4RAssertMessage_FileLine( file_ , line_ , NW4R_IS_ALIGNED_(val_, align_), "Alignment Error(0x%x)\n" #val_ " must be aligned to " #align_ " bytes boundary.", val_)
107
#define NW4RAssertHeaderAligned_File(file_, val_, align_) NW4RAssertMessage_FileLine( file_ , __LINE__, NW4R_IS_ALIGNED_(val_, align_), "Alignment Error(0x%x)\n" #val_ " must be aligned to " #align_ " bytes boundary.", val_)
108
#define NW4RAssertHeaderAligned_Line(line_, val_, align_) NW4RAssertMessage_FileLine(__FILE__, line_ , NW4R_IS_ALIGNED_(val_, align_), "Alignment Error(0x%x)\n" #val_ " must be aligned to " #align_ " bytes boundary.", val_)
109
#define NW4RAssertHeaderAligned(val_, align_) NW4RAssertMessage_FileLine(__FILE__, __LINE__, NW4R_IS_ALIGNED_(val_, align_), "Alignment Error(0x%x)\n" #val_ " must be aligned to " #align_ " bytes boundary.", val_)
110
111
// ClampedLValue
112
#define NW4RAssertClampedLValue_FileLine(file_, line_, var_, minValue_, maxValue_) NW4RAssertMessage_FileLine( file_ , line_ , (var_) >= (minValue_) && (var_) < (maxValue_), "NW4R:" #var_ " is out of bounds(%d)\n%d <= " #var_ " < %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
113
#define NW4RAssertClampedLValue_File(file_, var_, minValue_, maxValue_) NW4RAssertMessage_FileLine( file_ , __LINE__, (var_) >= (minValue_) && (var_) < (maxValue_), "NW4R:" #var_ " is out of bounds(%d)\n%d <= " #var_ " < %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
114
#define NW4RAssertClampedLValue_Line(line_, var_, minValue_, maxValue_) NW4RAssertMessage_FileLine(__FILE__, line_ , (var_) >= (minValue_) && (var_) < (maxValue_), "NW4R:" #var_ " is out of bounds(%d)\n%d <= " #var_ " < %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
115
#define NW4RAssertClampedLValue(var_, minValue_, maxValue_) NW4RAssertMessage_FileLine(__FILE__, __LINE__, (var_) >= (minValue_) && (var_) < (maxValue_), "NW4R:" #var_ " is out of bounds(%d)\n%d <= " #var_ " < %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
116
117
#define NW4RAssertHeaderClampedLValue_FileLine(file_, line_, var_, minValue_, maxValue_) NW4RAssertMessage_FileLine( file_ , line_ , (var_) >= (minValue_) && (var_) < (maxValue_), #var_ " is out of bounds(%d)\n%d <= " #var_ " < %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
118
#define NW4RAssertHeaderClampedLValue_File(file_, var_, minValue_, maxValue_) NW4RAssertMessage_FileLine( file_ , __LINE__, (var_) >= (minValue_) && (var_) < (maxValue_), #var_ " is out of bounds(%d)\n%d <= " #var_ " < %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
119
#define NW4RAssertHeaderClampedLValue_Line(line_, var_, minValue_, maxValue_) NW4RAssertMessage_FileLine(__FILE__, line_ , (var_) >= (minValue_) && (var_) < (maxValue_), #var_ " is out of bounds(%d)\n%d <= " #var_ " < %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
120
#define NW4RAssertHeaderClampedLValue(var_, minValue_, maxValue_) NW4RAssertMessage_FileLine(__FILE__, __LINE__, (var_) >= (minValue_) && (var_) < (maxValue_), #var_ " is out of bounds(%d)\n%d <= " #var_ " < %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
121
122
// ClampedLRValue
123
#define NW4RAssertClampedLRValue_FileLine(file_, line_, var_, minValue_, maxValue_) NW4RAssertMessage_FileLine( file_ , line_ , (var_) >= (minValue_) && (var_) <= (maxValue_), "NW4R:" #var_ " is out of bounds(%d)\n%d <= " #var_ " <= %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
124
#define NW4RAssertClampedLRValue_File(file_, var_, minValue_, maxValue_) NW4RAssertMessage_FileLine( file_ , __LINE__, (var_) >= (minValue_) && (var_) <= (maxValue_), "NW4R:" #var_ " is out of bounds(%d)\n%d <= " #var_ " <= %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
125
#define NW4RAssertClampedLRValue_Line(line_, var_, minValue_, maxValue_) NW4RAssertMessage_FileLine(__FILE__, line_ , (var_) >= (minValue_) && (var_) <= (maxValue_), "NW4R:" #var_ " is out of bounds(%d)\n%d <= " #var_ " <= %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
126
#define NW4RAssertClampedLRValue(var_, minValue_, maxValue_) NW4RAssertMessage_FileLine(__FILE__, __LINE__, (var_) >= (minValue_) && (var_) <= (maxValue_), "NW4R:" #var_ " is out of bounds(%d)\n%d <= " #var_ " <= %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
127
128
#define NW4RAssertHeaderClampedLRValue_FileLine(file_, line_, var_, minValue_, maxValue_) NW4RAssertMessage_FileLine( file_ , line_ , (var_) >= (minValue_) && (var_) <= (maxValue_), #var_ " is out of bounds(%d)\n%d <= " #var_ " <= %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
129
#define NW4RAssertHeaderClampedLRValue_File(file_, var_, minValue_, maxValue_) NW4RAssertMessage_FileLine( file_ , __LINE__, (var_) >= (minValue_) && (var_) <= (maxValue_), #var_ " is out of bounds(%d)\n%d <= " #var_ " <= %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
130
#define NW4RAssertHeaderClampedLRValue_Line(line_, var_, minValue_, maxValue_) NW4RAssertMessage_FileLine(__FILE__, line_ , (var_) >= (minValue_) && (var_) <= (maxValue_), #var_ " is out of bounds(%d)\n%d <= " #var_ " <= %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
131
#define NW4RAssertHeaderClampedLRValue(var_, minValue_, maxValue_) NW4RAssertMessage_FileLine(__FILE__, __LINE__, (var_) >= (minValue_) && (var_) <= (maxValue_), #var_ " is out of bounds(%d)\n%d <= " #var_ " <= %d not satisfied.", (int)(var_), (int)(minValue_), (int)(maxValue_))
132
133
/*******************************************************************************
134
* Strings, for deadstripping
135
*/
136
137
/* Main asserts */
138
139
#define NW4RAssert_String(expr_) "NW4R:Failed assertion " #expr_
140
#define NW4RAssertHeader_String(expr_) "Failed assertion " #expr_
141
142
#define NW4RCheck_String(expr_) "NW4R:Failed check " #expr_
143
#define NW4RCheckHeader_String(expr_) "Failed check " #expr_
144
145
/* Extended asserts */
146
147
#define NW4RAssertPointerNonnull_String(ptr_) "NW4R:Pointer must not be NULL (" #ptr_ ")"
148
#define NW4RAssertHeaderPointerNonnull_String(ptr_) "Pointer must not be NULL (" #ptr_ ")"
149
150
#define NW4RAssertAligned_String(val_, align_) "NW4R:Alignment Error(0x%x)\n" #val_ " must be aligned to " #align_ " bytes boundary."
151
#define NW4RAssertHeaderAligned_String(val_, align_) "Alignment Error(0x%x)\n" #val_ " must be aligned to " #align_ " bytes boundary."
152
153
#define NW4RAssertClampedLValue_String(var_) "NW4R:" #var_ " is out of bounds(%d)\n%d <= " #var_ " < %d not satisfied."
154
#define NW4RAssertHeaderClampedLValue_String(var_) #var_ " is out of bounds(%d)\n%d <= " #var_ " < %d not satisfied."
155
156
#define NW4RAssertClampedLRValue_String(var_) "NW4R:" #var_ " is out of bounds(%d)\n%d <= " #var_ " <= %d not satisfied."
157
#define NW4RAssertHeaderClampedLRValue_String(var_) #var_ " is out of bounds(%d)\n%d <= " #var_ " <= %d not satisfied."
158
159
/*******************************************************************************
160
* Declarations
161
*/
162
163
namespace
nw4r {
namespace
db
164
{
165
__attribute__((weak))
extern
void
Panic(
char
const
*file,
int
line,
char
const
*msg, ...);
166
__attribute__((weak))
extern
void
Warning(
char
const
*file,
int
line,
char
const
*msg, ...);
167
}}
// namespace nw4r::db
168
169
// clang-format on
include
lib
nw4r
NW4RAssert.hpp
Made with ❤️ by
CLF78
and
RootCubed
. Logos by
Chasical
and
B1
. Website generated by
Doxygen
1.13.2