1 /*  NAME:
2         E3Debug.h
3 
4     DESCRIPTION:
5         Debugging routines.
6 
7     COPYRIGHT:
8         Copyright (c) 1999-2004, Quesa Developers. All rights reserved.
9 
10         For the current release of Quesa, please see:
11 
12             <http://www.quesa.org/>
13 
14         Redistribution and use in source and binary forms, with or without
15         modification, are permitted provided that the following conditions
16         are met:
17 
18             o Redistributions of source code must retain the above copyright
19               notice, this list of conditions and the following disclaimer.
20 
21             o Redistributions in binary form must reproduce the above
22               copyright notice, this list of conditions and the following
23               disclaimer in the documentation and/or other materials provided
24               with the distribution.
25 
26             o Neither the name of Quesa nor the names of its contributors
27               may be used to endorse or promote products derived from this
28               software without specific prior written permission.
29 
30         THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31         "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32         LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33         A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34         OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35         SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
36         TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37         PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38         LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39         NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40         SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41     ___________________________________________________________________________
42 */
43 #ifndef E3DEBUG_HDR
44 #define E3DEBUG_HDR
45 //=============================================================================
46 //		C++ preamble
47 //-----------------------------------------------------------------------------
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 
53 
54 
55 
56 //=============================================================================
57 //      Function prototypes
58 //-----------------------------------------------------------------------------
59 // Report failed assertions
60 void		E3Assert(const char *srcFile, TQ3Uns32 lineNum, const char *theAssertion);
61 
62 
63 // Check a pointer for validity
64 TQ3Boolean	E3IsValidPtr(void *thePtr);
65 
66 
67 
68 
69 
70 //=============================================================================
71 //		Misc macros
72 //-----------------------------------------------------------------------------
73 // Check to see if a pointer is valid
74 #if Q3_DEBUG
75 	#define Q3_VALID_PTR(_thePtr)				E3IsValidPtr((void *) (_thePtr))
76 #else
77 	#define Q3_VALID_PTR(_thePtr)				(_thePtr != NULL)
78 #endif
79 
80 
81 
82 
83 
84 //=============================================================================
85 //		Assertion macros
86 //-----------------------------------------------------------------------------
87 #if Q3_DEBUG
88 	// Generate an assertion error if a test fails
89 	#define Q3_ASSERT(_theTest)													\
90 				((_theTest) ?													\
91 					((void) 0) :												\
92 					E3Assert(__FILE__, __LINE__, #_theTest)						\
93 				)
94 
95 	#define	Q3_ASSERT_MESSAGE(_condition, _message)								\
96 				((_condition) ?													\
97 					((void) 0) :												\
98 					E3Assert(__FILE__, __LINE__, (_message))					\
99 				)
100 
101 
102 	// Generates an assertion error for a bad pointer
103 	#define Q3_ASSERT_VALID_PTR(_thePtr)										\
104 				Q3_ASSERT(Q3_VALID_PTR(_thePtr))
105 
106 #else
107 	// Do nothing
108 	#define Q3_ASSERT(_theTest)													\
109 				((void) 0)
110 
111 	#define	Q3_ASSERT_MESSAGE(_condition, _message)		((void) 0)
112 
113 	// Do nothing
114 	#define Q3_ASSERT_VALID_PTR(_thePtr)										\
115 				((void) 0)
116 #endif
117 
118 
119 
120 
121 
122 //=============================================================================
123 //		Requirement macros
124 //-----------------------------------------------------------------------------
125 #if Q3_DEBUG
126 
127 // Check a condition or return
128 #define Q3_REQUIRE(_theTest)													\
129 			do																	\
130 				{																\
131 				TQ3Boolean	_cond = (TQ3Boolean)(_theTest); 					\
132 				Q3_ASSERT_MESSAGE(_cond, #_theTest);							\
133 				if (!(_cond))													\
134 					return;														\
135 				}																\
136 			while (0)
137 
138 // Check a condition or return a value
139 #define Q3_REQUIRE_OR_RESULT(_theTest, _theResult)								\
140 			do																	\
141 				{																\
142 				TQ3Boolean	_cond = (TQ3Boolean)(_theTest); 					\
143 				Q3_ASSERT_MESSAGE(_cond, #_theTest);							\
144 				if (!(_cond))													\
145 					return(_theResult);											\
146 				}																\
147 			while (0)
148 
149 #else
150 
151 // Check a condition or return
152 #define Q3_REQUIRE(_theTest)													\
153 			do																	\
154 				{																\
155 				if (!((TQ3Boolean)(_theTest)))													\
156 					return;														\
157 				}																\
158 			while (0)
159 
160 // Check a condition or return a value
161 #define Q3_REQUIRE_OR_RESULT(_theTest, _theResult)								\
162 			do																	\
163 				{																\
164 				if (!((TQ3Boolean)(_theTest)))													\
165 					return(_theResult);											\
166 				}																\
167 			while (0)
168 
169 #endif
170 
171 
172 
173 
174 
175 //=============================================================================
176 //		C++ postamble
177 //-----------------------------------------------------------------------------
178 #ifdef __cplusplus
179 }
180 #endif
181 
182 
183 
184 #endif
185 
186