CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ELassertN.h
Go to the documentation of this file.
1 // ELassertN.h
2 //
3 // Graded assert macros producing ErrorLogger messages
4 //
5 // There is no code guard in this file, since assert.h files can be
6 // included multiple times. That is, one can (in the same complilation unit)
7 // include ELassertN.h (or for that matter assert.h) and get meanings of the
8 // assert macros based on the current definition status of NDEBUG -- and later,
9 // one can alter NDEBUG (or NDEBUG1, NDEBUG2, NDBUG3) and re-include ELassertN.h
10 // so as to change to the new assertion behavior.
11 //
12 // Usage:
13 //
14 // The variable errlog must be an ErrorLog which is in scope where the
15 // ELassert is done. The error message will go to that errlog.
16 //
17 // ELassert (condition) will behave like assert(condition) but if
18 // triggered will issue an error message with
19 // ELabort severity, rather than a cerr output
20 // and an abort.
21 // ELassert1 (condition) will behave like ELassert(condition) but is
22 // disabled by either NDEBUG or NDEBUG1,
23 // ELassert2 (condition) is disabled by those and by NDEBUG2.
24 // ELassert3 (condition) is disabled by those and by NDEBUG2 or NDEBUG3.
25 //
26 // ELsanityCheck(condition) will behave like ELassert(condition) but
27 // is disabled by NOSANCHECK rather than NDEBUG.
28 //
29 // ELwarningAssert (condition) same as the corresponding ELassert,
30 // ELwarningAssert1 (condition) but will use ELwarning as the message
31 // ELwarningAssert1 (condition) severity if triggered.
32 // ELwarningAssert1 (condition)
33 // ELwarningCheck (condition) same as ELsanityCheck but will issue
34 // an error message with ELwarning severity
35 // (rather than ELabort) if triggered
36 
37 // Clean up any earlier definitions, in case this is not the first time the
38 // file has been included:
39 #if defined ELassert3
40  #undef ELassert3
41 #endif
42 #if defined ELwarningAssert3
43  #undef ELwarningAssert3
44 #endif
45 #if defined ELassert2
46  #undef ELassert2
47 #endif
48 #if defined ELwarningAssert2
49  #undef ELwarningAssert2
50 #endif
51 #if defined ELassert1
52  #undef ELassert1
53 #endif
54 #if defined ELwarningAssert1
55  #undef ELwarningAssert1
56 #endif
57 #if defined ELassert
58  #undef ELassert
59 #endif
60 #if defined ELwarningAssert
61  #undef ELwarningAssert
62 #endif
63 #if defined ELsanityCheck
64  #undef ELsanityCheck
65 #endif
66 #if defined ELwarningCheck
67  #undef ELwarningCheck
68 #endif
69 
70 #ifndef NDEBUG3
71 #define ELassert3(condition) ELassert2(condition)
72 #define ELwarningAssert3(condition) ELwarningAssert2(condition)
73 #else
74 #define ELassert3(condition) ((void)0)
75 #define ELwarningAssert3(condition) ((void)0)
76 #endif
77 
78 #ifndef NDEBUG2
79 #define ELassert2(condition) ELassert1(condition)
80 #define ELwarningAssert2(condition) ELwarningAssert1(condition)
81 #else
82 #define ELassert2(condition) ((void)0)
83 #define ELwarningAssert2(condition) ((void)0)
84 #endif
85 
86 #ifndef NDEBUG1
87 #define ELassert1(condition) ELassert(condition)
88 #define ELwarningAssert1(condition) ELwarningAssert(condition)
89 #else
90 #define ELassert1(condition) ((void)0)
91 #define ELwarningAssert1(condition) ((void)0)
92 #endif
93 
94 #ifndef NDEBUG
95 #define ELassert(condition) \
96  ((condition)?((void)(0)):((void)( \
97  errlog(ELabort,"assert failure")<<# condition<<"in"<<__FILE__<<"at line"\
98  <<__LINE__<<endmsg)))
99 #define ELwarningAssert(condition) \
100  ((condition)?((void)(0)):((void)( \
101  errlog(ELwarning,"assert warning")<<# condition<<"in"<<__FILE__<<"at line"\
102  <<__LINE__<<endmsg)))
103 #else
104 #define ELassert(condition) ((void)0)
105 #endif
106 
107 #ifndef NOSANCHECK
108 #define ELsanityCheck(condition) \
109  ((condition)?((void)(0)):((void)( \
110  errlog(ELabort,"assert failure")<<# condition<<"in"<<__FILE__<<"at line"\
111  <<__LINE__<<endmsg)))
112 #define ELwarningCheck(condition) \
113  ((condition)?((void)(0)):((void)( \
114  errlog(ELwarning,"assert warning")<<# condition<<"in"<<__FILE__<<"at line"\
115  <<__LINE__<<endmsg)))
116 #else
117 #define ELsanityCheck(condition) ((void)0)
118 #define ELwarningCheck(condition) ((void)0)
119 #endif
120 
121