ATLAS Offline Software
Loading...
Searching...
No Matches
Assert.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#ifndef ROOT_CORE_UTILS__ASSERT_H
8#define ROOT_CORE_UTILS__ASSERT_H
9
11
17
23
30
31
38
39
40
41
42
43//protect
45
46namespace RCU
47{
48 namespace Check
49 {
70 const int typeNum = invariant + 1;
71 extern const char * const typeLiteral [typeNum];
72 extern const bool typeAbort [typeNum];
73
74
84 void fail (const char *package, const char *file, unsigned line,
85 Type type, const char *error);
86
87
93 typedef void (*TestInvariantFunction) (const void *object);
94 template<class T> void
95 testInvariantVoid (const void *object)
96 {
97 static_cast<const T *>(object)->testInvariant ();
98 }
99
100
101
103 {
107
109 const void *object);
111
112 private:
114 const void *m_object;
115 };
116
117
118
121 template<class T> inline TestInvariant invariant_tester (T *object)
122 {
123 return TestInvariant (testInvariantVoid<T>, object);
124 }
125 }
126}
127
128
129
130
131
132#ifndef ROOTCORE_PACKAGE
133#define ROOTCORE_PACKAGE 0
134#endif
135
139#define RCU_CHECK(type,condition,message) \
140 (condition) ? (void) 0 : ::RCU::Check::fail (ROOTCORE_PACKAGE, __FILE__, __LINE__, ::RCU::Check::type, message)
141
143#define RCU_CHECK_JOIN2(a,b) RCU_CHECK_JOIN2_HIDDEN(a,b)
144#define RCU_CHECK_JOIN2_HIDDEN(a,b) a ## b
145
146
147
148#define RCU_REQUIRE_SOFT(x) \
149 RCU_CHECK (require_soft, x, #x)
150#define RCU_REQUIRE2_SOFT(x,y) \
151 RCU_CHECK (require_soft, x, y)
152#define RCU_REQUIRE0_SOFT(y) \
153 RCU_CHECK (require_soft, 0, y)
154
155#define RCU_PROVIDE_SOFT(x) \
156 RCU_CHECK (provide_soft, x, #x)
157#define RCU_PROVIDE2_SOFT(x,y) \
158 RCU_CHECK (provide_soft, x, y)
159#define RCU_PROVIDE0_SOFT(y) \
160 RCU_CHECK (provide_soft, 0, y)
161
162#define RCU_ASSERT_SOFT(x) \
163 RCU_CHECK (assert_soft, x, #x)
164#define RCU_ASSERT2_SOFT(x,y) \
165 RCU_CHECK (assert_soft, x, y)
166#define RCU_ASSERT0_SOFT(y) \
167 RCU_CHECK (assert_soft, 0, y)
168
169
170
171#define RCU_REQUIRE_NOIMP(x) \
172 RCU_CHECK (require_noimp, x, #x)
173#define RCU_REQUIRE2_NOIMP(x,y) \
174 RCU_CHECK (require_noimp, x, y)
175#define RCU_REQUIRE0_NOIMP(y) \
176 RCU_CHECK (require_noimp, 0, y)
177
178#define RCU_PROVIDE_NOIMP(x) \
179 RCU_CHECK (provide_noimp, x, #x)
180#define RCU_PROVIDE2_NOIMP(x,y) \
181 RCU_CHECK (provide_noimp, x, y)
182#define RCU_PROVIDE0_NOIMP(y) \
183 RCU_CHECK (provide_noimp, 0, y)
184
185#define RCU_ASSERT_NOIMP(x) \
186 RCU_CHECK (assert_noimp, x, #x)
187#define RCU_ASSERT2_NOIMP(x,y) \
188 RCU_CHECK (assert_noimp, x, y)
189#define RCU_ASSERT0_NOIMP(y) \
190 RCU_CHECK (assert_noimp, 0, y)
191
192
193
194#ifndef NDEBUG
195
196#define RCU_INVARIANT(x) \
197 RCU_CHECK (invariant, x, #x)
198#define RCU_INVARIANT2(x,y) \
199 RCU_CHECK (invariant, x, y)
200#define RCU_INVARIANT0(y) \
201 RCU_CHECK (invariant, 0, y)
202
203#define RCU_REQUIRE(x) \
204 RCU_CHECK (require_hard, x, #x)
205#define RCU_REQUIRE2(x,y) \
206 RCU_CHECK (require_hard, x, y)
207#define RCU_REQUIRE0(y) \
208 RCU_CHECK (require_hard, 0, y)
209
210#define RCU_PROVIDE(x) \
211 RCU_CHECK (provide_hard, x, #x)
212#define RCU_PROVIDE2(x,y) \
213 RCU_CHECK (provide_hard, x, y)
214#define RCU_PROVIDE0(y) \
215 RCU_CHECK (provide_hard, 0, y)
216
217#define RCU_ASSERT(x) \
218 RCU_CHECK (assert_hard, x, #x)
219#define RCU_ASSERT2(x,y) \
220 RCU_CHECK (assert_hard, x, y)
221#define RCU_ASSERT0(y) \
222 RCU_CHECK (assert_hard, 0, y)
223
224#define RCU_READ_INVARIANT(x) \
225 (x)->testInvariant ()
226#define RCU_CHANGE_INVARIANT(x) \
227 ::RCU::Check::TestInvariant RCU_CHECK_JOIN2 (invariant, __LINE__) = ::RCU::Check::invariant_tester (x);
228#define RCU_NEW_INVARIANT(x) \
229 (x)->testInvariant ()
230#define RCU_DESTROY_INVARIANT(x) \
231 (x)->testInvariant ()
232
233
234
235#else
236
237#define RCU_INVARIANT(x) \
238 (void) 0
239#define RCU_INVARIANT2(x,y) \
240 (void) 0
241#define RCU_INVARIANT0(y) \
242 (void) 0
243#define RCU_REQUIRE(x) \
244 (void) 0
245#define RCU_REQUIRE2(x,y) \
246 (void) 0
247#define RCU_REQUIRE0(y) \
248 (void) 0
249#define RCU_PROVIDE(x) \
250 (void) 0
251#define RCU_PROVIDE2(x,y) \
252 (void) 0
253#define RCU_PROVIDE0(y) \
254 (void) 0
255#define RCU_ASSERT(x) \
256 (void) 0
257#define RCU_ASSERT2(x,y) \
258 (void) 0
259#define RCU_ASSERT0(y) \
260 (void) 0
261#define RCU_READ_INVARIANT(x) \
262 (void) 0
263#define RCU_CHANGE_INVARIANT(x) \
264 (void) 0
265#define RCU_NEW_INVARIANT(x) \
266 (void) 0
267#define RCU_DESTROY_INVARIANT(x) \
268 (void) 0
269
270#endif
271
272
273
274
275
276#ifdef RCU_DEBUG_SLOW
277
278#define RCU_REQUIRE_SLOW(x) \
279 RCU_REQUIRE(x)
280#define RCU_REQUIRE2_SLOW(x,y) \
281 RCU_REQUIRE2(x,y)
282#define RCU_PROVIDE_SLOW(x) \
283 RCU_PROVIDE(x)
284#define RCU_PROVIDE2_SLOW(x,y) \
285 RCU_PROVIDE2(x,y)
286#define RCU_ASSERT_SLOW(x) \
287 RCU_ASSERT(x)
288#define RCU_ASSERT2_SLOW(x,y) \
289 RCU_ASSERT2(x,y)
290#define RCU_READ_INVARIANT_SLOW(x) \
291 RCU_READ_INVARIANT (x)
292#define RCU_CHANGE_INVARIANT_SLOW(x) \
293 RCU_CHANGE_INVARIANT (x)
294#define RCU_NEW_INVARIANT_SLOW(x) \
295 RCU_NEW_INVARIANT (x)
296#define RCU_DESTROY_INVARIANT_SLOW(x) \
297 RCU_DESTROY_INVARIANT (x)
298
299#else
300
301#define RCU_REQUIRE_SLOW(x) \
302 (void) 0
303#define RCU_REQUIRE2_SLOW(x,y) \
304 (void) 0
305#define RCU_PROVIDE_SLOW(x) \
306 (void) 0
307#define RCU_PROVIDE2_SLOW(x,y) \
308 (void) 0
309#define RCU_ASSERT_SLOW(x) \
310 (void) 0
311#define RCU_ASSERT2_SLOW(x,y) \
312 (void) 0
313#define RCU_READ_INVARIANT_SLOW(x) \
314 (void) 0
315#define RCU_CHANGE_INVARIANT_SLOW(x) \
316 (void) 0
317#define RCU_NEW_INVARIANT_SLOW(x) \
318 (void) 0
319#define RCU_DESTROY_INVARIANT_SLOW(x) \
320 (void) 0
321
322#endif
323
324
325#endif
const bool typeAbort[typeNum]
Definition Assert.cxx:45
TestInvariant invariant_tester(T *object)
effects: create the right invariant testing object returns: the tester
Definition Assert.h:121
const int typeNum
Definition Assert.h:70
void fail(const char *package, const char *file, unsigned line, Type type, const char *error)
effects: report the error and abort either by exception or assert like guarantee: all-fail failures: ...
Definition Assert.cxx:64
void testInvariantVoid(const void *object)
Definition Assert.h:95
@ require_hard
Definition Assert.h:59
@ provide_noimp
Definition Assert.h:65
@ require_soft
function parameter requirement
Definition Assert.h:58
@ invariant
invariant violation
Definition Assert.h:68
@ require_noimp
Definition Assert.h:60
@ assert_hard
Definition Assert.h:54
@ assert_noimp
Definition Assert.h:55
@ assert_soft
regular old style assertion
Definition Assert.h:53
@ provide_soft
function postcondition
Definition Assert.h:63
@ provide_hard
Definition Assert.h:64
void(* TestInvariantFunction)(const void *object)
effects: apply the test invariant method on an object guarantee: no-fail availability: experts only r...
Definition Assert.h:93
const char *const typeLiteral[typeNum]
Definition Assert.cxx:26
This module defines a variety of assert style macros.
Definition Assert.cxx:23
const void * m_object
Definition Assert.h:114
TestInvariantFunction m_function
Definition Assert.h:113
TestInvariant(TestInvariantFunction function, const void *object)
availability: experts only description: this class will perform an invariant test as the object goes ...
Definition Assert.cxx:89
TFile * file