ATLAS Offline Software
Assert.h
Go to the documentation of this file.
1 #ifndef ROOT_CORE_UTILS__ASSERT_H
2 #define ROOT_CORE_UTILS__ASSERT_H
3 
4 // - 2012.
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 
9 // Please feel free to contact me (krumnack@iastate.edu) for bug
10 // reports, feature suggestions, praise and complaints.
11 
12 
16 
22 
28 
35 
36 
43 
44 
45 
46 
47 
48 //protect
49 #include <RootCoreUtils/Global.h>
50 
51 namespace RCU
52 {
53  namespace Check
54  {
55  enum Type
56  {
61 
66 
71 
73  invariant
74  };
75  const int typeNum = invariant + 1;
76  extern const char * const typeLiteral [typeNum];
77  extern const bool typeAbort [typeNum];
78 
79 
89  void fail (const char *package, const char *file, unsigned line,
90  Type type, const char *error);
91 
92 
98  typedef void (*TestInvariantFunction) (const void *object);
99  template<class T> void
100  testInvariantVoid (const void *object)
101  {
102  static_cast<const T *>(object)->testInvariant ();
103  }
104 
105 
106 
108  {
112 
114  const void *object);
115  ~TestInvariant ();
116 
117  private:
119  const void *m_object;
120  };
121 
122 
123 
126  template<class T> inline TestInvariant invariant_tester (T *object)
127  {
128  return TestInvariant (testInvariantVoid<T>, object);
129  }
130  }
131 }
132 
133 
134 
135 
136 
137 #ifndef ROOTCORE_PACKAGE
138 #define ROOTCORE_PACKAGE 0
139 #endif
140 
144 #define RCU_CHECK(type,condition,message) \
145  (condition) ? (void) 0 : ::RCU::Check::fail (ROOTCORE_PACKAGE, __FILE__, __LINE__, ::RCU::Check::type, message)
146 
148 #define RCU_CHECK_JOIN2(a,b) RCU_CHECK_JOIN2_HIDDEN(a,b)
149 #define RCU_CHECK_JOIN2_HIDDEN(a,b) a ## b
150 
151 
152 
153 #define RCU_REQUIRE_SOFT(x) \
154  RCU_CHECK (require_soft, x, #x)
155 #define RCU_REQUIRE2_SOFT(x,y) \
156  RCU_CHECK (require_soft, x, y)
157 #define RCU_REQUIRE0_SOFT(y) \
158  RCU_CHECK (require_soft, 0, y)
159 
160 #define RCU_PROVIDE_SOFT(x) \
161  RCU_CHECK (provide_soft, x, #x)
162 #define RCU_PROVIDE2_SOFT(x,y) \
163  RCU_CHECK (provide_soft, x, y)
164 #define RCU_PROVIDE0_SOFT(y) \
165  RCU_CHECK (provide_soft, 0, y)
166 
167 #define RCU_ASSERT_SOFT(x) \
168  RCU_CHECK (assert_soft, x, #x)
169 #define RCU_ASSERT2_SOFT(x,y) \
170  RCU_CHECK (assert_soft, x, y)
171 #define RCU_ASSERT0_SOFT(y) \
172  RCU_CHECK (assert_soft, 0, y)
173 
174 
175 
176 #define RCU_REQUIRE_NOIMP(x) \
177  RCU_CHECK (require_noimp, x, #x)
178 #define RCU_REQUIRE2_NOIMP(x,y) \
179  RCU_CHECK (require_noimp, x, y)
180 #define RCU_REQUIRE0_NOIMP(y) \
181  RCU_CHECK (require_noimp, 0, y)
182 
183 #define RCU_PROVIDE_NOIMP(x) \
184  RCU_CHECK (provide_noimp, x, #x)
185 #define RCU_PROVIDE2_NOIMP(x,y) \
186  RCU_CHECK (provide_noimp, x, y)
187 #define RCU_PROVIDE0_NOIMP(y) \
188  RCU_CHECK (provide_noimp, 0, y)
189 
190 #define RCU_ASSERT_NOIMP(x) \
191  RCU_CHECK (assert_noimp, x, #x)
192 #define RCU_ASSERT2_NOIMP(x,y) \
193  RCU_CHECK (assert_noimp, x, y)
194 #define RCU_ASSERT0_NOIMP(y) \
195  RCU_CHECK (assert_noimp, 0, y)
196 
197 
198 
199 #ifndef NDEBUG
200 
201 #define RCU_INVARIANT(x) \
202  RCU_CHECK (invariant, x, #x)
203 #define RCU_INVARIANT2(x,y) \
204  RCU_CHECK (invariant, x, y)
205 #define RCU_INVARIANT0(y) \
206  RCU_CHECK (invariant, 0, y)
207 
208 #define RCU_REQUIRE(x) \
209  RCU_CHECK (require_hard, x, #x)
210 #define RCU_REQUIRE2(x,y) \
211  RCU_CHECK (require_hard, x, y)
212 #define RCU_REQUIRE0(y) \
213  RCU_CHECK (require_hard, 0, y)
214 
215 #define RCU_PROVIDE(x) \
216  RCU_CHECK (provide_hard, x, #x)
217 #define RCU_PROVIDE2(x,y) \
218  RCU_CHECK (provide_hard, x, y)
219 #define RCU_PROVIDE0(y) \
220  RCU_CHECK (provide_hard, 0, y)
221 
222 #define RCU_ASSERT(x) \
223  RCU_CHECK (assert_hard, x, #x)
224 #define RCU_ASSERT2(x,y) \
225  RCU_CHECK (assert_hard, x, y)
226 #define RCU_ASSERT0(y) \
227  RCU_CHECK (assert_hard, 0, y)
228 
229 #define RCU_READ_INVARIANT(x) \
230  (x)->testInvariant ()
231 #define RCU_CHANGE_INVARIANT(x) \
232  ::RCU::Check::TestInvariant RCU_CHECK_JOIN2 (invariant, __LINE__) = ::RCU::Check::invariant_tester (x);
233 #define RCU_NEW_INVARIANT(x) \
234  (x)->testInvariant ()
235 #define RCU_DESTROY_INVARIANT(x) \
236  (x)->testInvariant ()
237 
238 
239 
240 #else
241 
242 #define RCU_INVARIANT(x) \
243  (void) 0
244 #define RCU_INVARIANT2(x,y) \
245  (void) 0
246 #define RCU_INVARIANT0(y) \
247  (void) 0
248 #define RCU_REQUIRE(x) \
249  (void) 0
250 #define RCU_REQUIRE2(x,y) \
251  (void) 0
252 #define RCU_REQUIRE0(y) \
253  (void) 0
254 #define RCU_PROVIDE(x) \
255  (void) 0
256 #define RCU_PROVIDE2(x,y) \
257  (void) 0
258 #define RCU_PROVIDE0(y) \
259  (void) 0
260 #define RCU_ASSERT(x) \
261  (void) 0
262 #define RCU_ASSERT2(x,y) \
263  (void) 0
264 #define RCU_ASSERT0(y) \
265  (void) 0
266 #define RCU_READ_INVARIANT(x) \
267  (void) 0
268 #define RCU_CHANGE_INVARIANT(x) \
269  (void) 0
270 #define RCU_NEW_INVARIANT(x) \
271  (void) 0
272 #define RCU_DESTROY_INVARIANT(x) \
273  (void) 0
274 
275 #endif
276 
277 
278 
279 
280 
281 #ifdef RCU_DEBUG_SLOW
282 
283 #define RCU_REQUIRE_SLOW(x) \
284  RCU_REQUIRE(x)
285 #define RCU_REQUIRE2_SLOW(x,y) \
286  RCU_REQUIRE2(x,y)
287 #define RCU_PROVIDE_SLOW(x) \
288  RCU_PROVIDE(x)
289 #define RCU_PROVIDE2_SLOW(x,y) \
290  RCU_PROVIDE2(x,y)
291 #define RCU_ASSERT_SLOW(x) \
292  RCU_ASSERT(x)
293 #define RCU_ASSERT2_SLOW(x,y) \
294  RCU_ASSERT2(x,y)
295 #define RCU_READ_INVARIANT_SLOW(x) \
296  RCU_READ_INVARIANT (x)
297 #define RCU_CHANGE_INVARIANT_SLOW(x) \
298  RCU_CHANGE_INVARIANT (x)
299 #define RCU_NEW_INVARIANT_SLOW(x) \
300  RCU_NEW_INVARIANT (x)
301 #define RCU_DESTROY_INVARIANT_SLOW(x) \
302  RCU_DESTROY_INVARIANT (x)
303 
304 #else
305 
306 #define RCU_REQUIRE_SLOW(x) \
307  (void) 0
308 #define RCU_REQUIRE2_SLOW(x,y) \
309  (void) 0
310 #define RCU_PROVIDE_SLOW(x) \
311  (void) 0
312 #define RCU_PROVIDE2_SLOW(x,y) \
313  (void) 0
314 #define RCU_ASSERT_SLOW(x) \
315  (void) 0
316 #define RCU_ASSERT2_SLOW(x,y) \
317  (void) 0
318 #define RCU_READ_INVARIANT_SLOW(x) \
319  (void) 0
320 #define RCU_CHANGE_INVARIANT_SLOW(x) \
321  (void) 0
322 #define RCU_NEW_INVARIANT_SLOW(x) \
323  (void) 0
324 #define RCU_DESTROY_INVARIANT_SLOW(x) \
325  (void) 0
326 
327 #endif
328 
329 
330 #endif
RCU::Check::TestInvariant::~TestInvariant
~TestInvariant()
Definition: Assert.cxx:102
RCU::Check::invariant_tester
TestInvariant invariant_tester(T *object)
effects: create the right invariant testing object returns: the tester
Definition: Assert.h:126
checkFileSG.line
line
Definition: checkFileSG.py:75
RCU::Check::require_hard
@ require_hard
Definition: Assert.h:64
RCU::Check::require_noimp
@ require_noimp
Definition: Assert.h:65
RCU::Check::require_soft
@ require_soft
function parameter requirement
Definition: Assert.h:63
Global.h
RCU::Check::fail
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:67
RCU::Check::typeLiteral
const char *const typeLiteral[typeNum]
Definition: Assert.cxx:29
RCU
This module defines a variety of assert style macros.
Definition: Assert.cxx:26
RCU::Check::TestInvariant::TestInvariant
TestInvariant(TestInvariantFunction function, const void *object)
availability: experts only description: this class will perform an invariant test as the object goes ...
Definition: Assert.cxx:92
RCU::Check::TestInvariant::m_function
TestInvariantFunction m_function
Definition: Assert.h:118
RCU::Check::provide_noimp
@ provide_noimp
Definition: Assert.h:70
RCU::Check::provide_hard
@ provide_hard
Definition: Assert.h:69
RCU::Check::testInvariantVoid
void testInvariantVoid(const void *object)
Definition: Assert.h:100
file
TFile * file
Definition: tile_monitor.h:29
RCU::Check::assert_hard
@ assert_hard
Definition: Assert.h:59
RCU::Check::invariant
@ invariant
invariant violation
Definition: Assert.h:73
RCU::Check::typeAbort
const bool typeAbort[typeNum]
Definition: Assert.cxx:48
xAODType
Definition: ObjectType.h:13
RCU::Check::typeNum
const int typeNum
Definition: Assert.h:75
RCU::Check::TestInvariant
Definition: Assert.h:108
RCU::Check::TestInvariantFunction
void(* TestInvariantFunction)(const void *object)
effects: apply the test invariant method on an object guarantee: no-fail availability: experts only r...
Definition: Assert.h:98
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
pickleTool.object
object
Definition: pickleTool.py:30
RCU::Check::TestInvariant::m_object
const void * m_object
Definition: Assert.h:119
RCU::Check::assert_noimp
@ assert_noimp
Definition: Assert.h:60
RCU::Check::provide_soft
@ provide_soft
function postcondition
Definition: Assert.h:68
error
Definition: IImpactPoint3dEstimator.h:70
RCU::Check::assert_soft
@ assert_soft
regular old style assertion
Definition: Assert.h:58