1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                   CHECK.H                                 */
4 /*                                                                           */
5 /* (C) 1993-96  Ullrich von Bassewitz                                        */
6 /*              Wacholderweg 14                                              */
7 /*              D-70597 Stuttgart                                            */
8 /* EMail:       uz@ibb.schwaben.com                                          */
9 /*                                                                           */
10 /*****************************************************************************/
11 
12 
13 
14 // $Id$
15 //
16 // $Log$
17 //
18 //
19 
20 
21 
22 #ifndef _CHECK_H
23 #define _CHECK_H
24 
25 
26 
27 /*****************************************************************************/
28 /*                                   Data                                    */
29 /*****************************************************************************/
30 
31 
32 
33 extern const char* _MsgInternalError;           // "Internal error: "
34 extern const char* _MsgAbstractCall;            // "Call to abstract method"
35 extern const char* _MsgPrecondition;            // "Precondition violated: "
36 extern const char* _MsgCheckFailed;             // "Check failed: "
37 
38 
39 
40 extern
41 void (*CheckFailed) (const char* Msg, const char* Cond, int Code,
42                             const char* File, int Line);
43 // Function pointer that is called from Check if the condition code is true.
44 
45 
46 
47 /*****************************************************************************/
48 /*                                   Code                                    */
49 /*****************************************************************************/
50 
51 
52 
53 extern void Check (const char* Msg, const char* Cond, int Code,
54                    const char* File, int Line);
55 // This function is called from all check macros (see below). It checks, wether
56 // the given Code is true (!= 0). If so, it calls the CheckFailed vector with
57 // the given strings. If not, it simply returns.
58 
59 
60 
61 #define FAIL(s) CheckFailed (_MsgInternalError, s, 0, __FILE__, __LINE__)
62 // Fail macro. Is used if something evil happens, calls CheckFailed directly.
63 
64 
65 
66 #define ABSTRACT() FAIL(_MsgAbstractCall)
67 // Short for FAIL. Is used in abstract class member functions.
68 
69 
70 #ifdef SPUNK_NODEBUG
71 
72 #define PRECONDITION(c)
73 #define CHECK(c)
74 #define ZCHECK(c)
75 
76 #else
77 
78 // These macros are usually defined!!!
79 #define PRECONDITION(c) Check (_MsgPrecondition,                \
80                         #c, !(c), __FILE__, __LINE__)
81 
82 #define CHECK(c)        Check (_MsgCheckFailed,                 \
83                         #c, !(c), __FILE__, __LINE__)
84 
85 #define ZCHECK(c)       Check (_MsgCheckFailed,                 \
86                         #c, c, __FILE__, __LINE__)
87 
88 #endif
89 
90 
91 
92 // End of CHECK.H
93 
94 #endif
95