2 * NOTICE and LICENSE for Tecplot Input/Output Library (TecIO) - OpenFOAM
4 * Copyright (C) 1988-2009 Tecplot, Inc. All rights reserved worldwide.
6 * Tecplot hereby grants OpenCFD limited authority to distribute without
7 * alteration the source code to the Tecplot Input/Output library, known
8 * as TecIO, as part of its distribution of OpenFOAM and the
9 * OpenFOAM_to_Tecplot converter. Users of this converter are also hereby
10 * granted access to the TecIO source code, and may redistribute it for the
11 * purpose of maintaining the converter. However, no authority is granted
12 * to alter the TecIO source code in any form or manner.
14 * This limited grant of distribution does not supersede Tecplot, Inc.'s
15 * copyright in TecIO. Contact Tecplot, Inc. for further information.
18 * 3535 Factoria Blvd, Ste. 550
19 * Bellevue, WA 98006, USA
20 * Phone: +1 425 653 1200
21 * http://www.tecplot.com/
25 ******************************************************************
26 ******************************************************************
28 ****** (C) 1988-2008 Tecplot, Inc. *******
30 ******************************************************************
31 ******************************************************************
34 * Provide four levels of assertion control. Assertions provide a mechanism
35 * to enforce a contract between a client and service provider. The assertions
36 * are listed in order of highest to lowest priority. Assertions can be turned
37 * off individually by defining the appropriate name (see preprossessor
38 * definitions below), however, lower priority assertions should be turned
39 * off prior to higher ones. As confidence in the code increases all assertions
40 * can be turned off by defining NO_ASSERTS.
42 * The assertions defined below have the following meanings:
44 * INVARIANT - Asserts that a property's state is invariant throughout the
45 * life of the property's scope. Stating invariant properties
46 * of an application provides a deeper understanding of the
47 * application's state. These statements are usually
48 * positioned just ahead of the preconditions and just after
51 * REQUIRE - Asserts that a method's preconditions are within their
52 * valid domains. Preconditions are conditions placed upon
53 * any state information relied upon for the call. These
54 * statements should be as close to the top of the method
55 * as possible (except for assertions on invariant properties).
57 * ENSURE - Asserts that a method's postconditions are within their
58 * valid ranges. Postconditions are conditions placed upon
59 * any state information modified by the call. These
60 * statements should be as close to the bottom of the method
61 * (presumably there is only one exit point) as possible
62 * (except for assertions on invariant properties).
64 * CHECK - Any other assertion not covered by the above assertions.
65 * These are often added within a method body to specify
66 * something that may not be immediately obvious to the reader
67 * or to validate your assumptions about a call to a 3rd party
68 * method that does not use runtime assertions for its
69 * preconditions or postconditions. Obviously if the 3rd party
70 * method uses assertions then there is no need for the CHECK.
72 * Additionally a convenience macro is available to place in code that is
73 * pending implementation.
75 * NOT_IMPLEMENTED - Assertion that always fails during runtime for debug
76 * builds and always fails at compile time for release
79 #if !defined TASSERT_H
86 #if !defined TECPLOTKERNEL && !defined STD_ASSERTS
93 # define ASSERT assert
98 /* MFC .NET defines ENSURE, so we undefine it here */
104 /* BEGINREMOVEFROMADDON */
105 #define INVALID_REF ((void *)0x0000FFFF)
107 * Chances are low the address 0x11111111 will be used, so we'll risk asserting
108 * against it (see unitialized assignment in newmalloc).
110 #define UNINITIALIZED_REF ((void *)0x11111111)
111 #define INVALID_FN_REF ((void *)NULL)
112 /* ENDREMOVEFROMADDON */
115 /* BEGINREMOVEFROMADDON */
116 #if defined TECPLOTKERNEL
117 /* CORE SOURCE CODE REMOVED */
118 # if defined NO_ASSERTS
121 #endif /* TECPLOTKERNAL */
122 /* ENDREMOVEFROMADDON */
124 /* BEGINREMOVEFROMADDON */
125 #if !defined TECPLOTKERNEL
126 /* For add-ons, there is a problem with VALID_REF, so just test for non-NULL */
127 /* ENDREMOVEFROMADDON */
128 # define VALID_REF(p) ( (p) != NULL )
129 # define VALID_FN_REF(fp) ( (fp) != NULL )
130 /* BEGINREMOVEFROMADDON */
131 #endif /* !defined TECPLOTKERNAL */
132 /* ENDREMOVEFROMADDON */
134 /* BEGINREMOVEFROMADDON */
135 /* Widgets are pointers under Motif */
136 # define VALID_WIDGET(widget) VALID_REF((widget))
137 /* Menu widgets are pointers too */
138 # define VALID_MENU_WIDGET(widget) VALID_REF((widget))
139 /* ENDREMOVEFROMADDON */
143 /* BEGINREMOVEFROMADDON */
144 /* Don't use AfxIsValidAddress()! See Bug <7245>.
146 /* ENDREMOVEFROMADDON */
148 #if defined NO_ASSERTS
149 /* release build in TecUtil layer uses these for TUASSERT */
150 # define VALID_REF(p) ((p) != NULL)
151 # define VALID_FN_REF(pf) ((pf) != NULL)
153 # define VALID_REF(p) ((p) != NULL && !IsBadReadPtr((const void *)(p), 1))
154 # define VALID_FN_REF(pf) ((pf) != NULL && !IsBadReadPtr((const void *)(pf),(UINT_PTR)sizeof(const void*)))
157 /* BEGINREMOVEFROMADDON */
158 /* Widgets are numbers under Windows, so we decode it with GetWindowFromWidget */
160 # define VALID_WIDGET(widget) ((widget) != NULL)
162 # define VALID_WIDGET(widget) ((widget) != NULL && GetWindowFromWidget((widget))!=NULL)
165 /* Menu widgets are numbers too, so we just check against zero */
166 # define VALID_MENU_WIDGET(widget) ((widget)!=NULL)
167 /* ENDREMOVEFROMADDON */
169 /* BEGINREMOVEFROMADDON */
170 /* handles are not pointers to memory, so the only test we can */
171 /* perform is to check for 0 */
172 #define VALID_HANDLE(handle) ((handle)!=0)
175 #define VALID_FLEX_JOB_HANDLE(handle) ((handle) != NULL)
176 #define VALID_FLEX_ERROR_CODE(ErrorCode)(ErrorCode <= 0)
179 /* ENDREMOVEFROMADDON */
180 /* other useful validity checks */
181 #define VALID_BOOLEAN(b) ((b) == TRUE || (b) == FALSE)
182 #define VALID_ENUM(value, type) (0 <= (value) && \
183 (value) < END_##type)
185 /* Test a parameter than can be NULL or a valid pointer */
186 #define VALID_REF_OR_NULL(ptr) IMPLICATION((ptr) != NULL, VALID_REF(ptr))
187 #define VALID_FN_REF_OR_NULL(ptr) IMPLICATION((ptr) != NULL, VALID_FN_REF(ptr))
189 /* BEGINREMOVEFROMADDON */
190 #define VALID_TRANSLATED_STRING(ts) (!(ts).isNull())
193 * These macros are a little complicated but it allows one to
194 * write a simple assertion regardless of the zone type or
197 * REQUIRE(VALID_CELL_INDEX(CZData, CellIndex, Plane)));
199 * Prior to using the macros a call to SetupXxx,
200 * or at a minimum SetupCZData, must be called to setup
201 * the globals defining the dataset structure.
203 #define VALID_FE_CELL_INDEX(CZData, CellIndex) \
204 (/* CellIndex range test */ \
205 0 <= (CellIndex) && \
206 (CellIndex) < (CZData)->NumElements)
208 #define VALID_IPLANE_CELL_INDEX(CZData,CellIndex) \
209 (/* CellIndex range test */ \
210 (CellIndex) >= 0 && \
211 IINDEX((CZData),CellIndex) <= MAX((CZData)->NumIPtsM1,1) && \
212 JINDEX((CZData),CellIndex) < MAX((CZData)->NumJPtsM1,1) && \
213 KINDEX((CZData),CellIndex) < MAX((CZData)->NumKPtsM1,1))
215 #define VALID_JPLANE_CELL_INDEX(CZData,CellIndex) \
216 (/* CellIndex range test */ \
217 (CellIndex) >= 0 && \
218 IINDEX((CZData),CellIndex) < MAX((CZData)->NumIPtsM1,1) && \
219 JINDEX((CZData),CellIndex) <= MAX((CZData)->NumJPtsM1,1) && \
220 KINDEX((CZData),CellIndex) < MAX((CZData)->NumKPtsM1,1))
222 #define VALID_KPLANE_CELL_INDEX(CZData,CellIndex) \
223 (/* CellIndex range test */ \
224 (CellIndex) >= 0 && \
225 IINDEX((CZData),CellIndex) < MAX((CZData)->NumIPtsM1,1) && \
226 JINDEX((CZData),CellIndex) < MAX((CZData)->NumJPtsM1,1) && \
227 KINDEX((CZData),CellIndex) <= MAX((CZData)->NumKPtsM1,1))
229 #define VALID_ORDERED_CELL_INDEX(CZData, CellIndex, Plane) \
230 (/* macro preconditions */ \
231 ((IJKPlanes_e)(Plane) == IJKPlanes_I || \
232 (IJKPlanes_e)(Plane) == IJKPlanes_J || \
233 (IJKPlanes_e)(Plane) == IJKPlanes_K || \
234 (IJKPlanes_e)(Plane) == IJKPlanes_Volume) && \
236 /* CellIndex range test */ \
237 (IMPLICATION(((IJKPlanes_e)(Plane) == IJKPlanes_I || \
238 (IJKPlanes_e)(Plane) == IJKPlanes_Volume), \
239 VALID_IPLANE_CELL_INDEX((CZData),CellIndex)) && \
240 IMPLICATION(((IJKPlanes_e)(Plane) == IJKPlanes_J || \
241 (IJKPlanes_e)(Plane) == IJKPlanes_Volume), \
242 VALID_JPLANE_CELL_INDEX((CZData),CellIndex)) && \
243 IMPLICATION(((IJKPlanes_e)(Plane) == IJKPlanes_K || \
244 (IJKPlanes_e)(Plane) == IJKPlanes_Volume), \
245 VALID_KPLANE_CELL_INDEX((CZData),CellIndex))))
247 #define VALID_CELL_INDEX(CZData, CellIndex, Plane) \
248 (((CZData)->NM != NULL || (CZData)->FM != NULL) ? \
249 VALID_FE_CELL_INDEX((CZData), (CellIndex)) : \
250 VALID_ORDERED_CELL_INDEX((CZData), (CellIndex), (Plane)))
252 #define VALID_DATASET(dataSet,checkNumZones) (((dataSet) != NULL) && \
253 IMPLICATION((checkNumZones),(dataSet)->NumZones >= 1))
258 /* Here is a more specific check in Windows for a valid
259 pointer to an MFC Window object.
260 Note that GetSafeHwnd() works even if pWnd is NULL, because
261 it checks the 'this' pointer first */
262 # define VALID_WND(pWnd) (::IsWindow((pWnd)->GetSafeHwnd()))
265 # define VALID_WND(pWnd) /* Should not be used in Motif */
267 /* ENDREMOVEFROMADDON */
269 /* Check for a non-zero length string */
271 # if defined NO_ASSERTS
272 # define VALID_NON_ZERO_LEN_STR(str) (VALID_REF(str) && !ISEMPTYSTRING(str))
274 # define VALID_NON_ZERO_LEN_STR(str) \
276 !IsBadReadPtr((const void*)(str),(UINT_PTR)(1+strlen((const char*)(str)))) && \
280 # define VALID_NON_ZERO_LEN_STR(str) (VALID_REF(str) && !ISEMPTYSTRING(str))
283 #define VALID_SET_INDEX(setIndex) (((SetIndex_t)setIndex)>=(SetIndex_t)1)
285 /* Check for valid stdio file handle */
286 #define VALID_FILE_HANDLE(stream) ((stream) != NULL)
288 /* To check colors and pen numbers */
289 /* BEGINREMOVEFROMADDON */
290 #define VALID_BASIC_COLOR(BColor) \
291 (FirstBasicColor<=(BColor) && (BColor)<=LastBasicColor)
292 #define VALID_CONTOUR_COLOR(Color) \
293 (ContourColorOffset<=(Color) && \
294 (Color)<ContourColorOffset+GeneralBase.Limits.MaxNumContourLevels+1)
295 #define VALID_PLOTTING_COLOR(Color) \
296 (VALID_BASIC_COLOR(Color) || VALID_CONTOUR_COLOR(Color))
297 #define VALID_INTERFACE_SPECIFIC_COLOR(BColor) \
298 (FirstInterfaceColor<=(BColor) && (BColor)<=LastInterfaceColor)
299 #define VALID_INTERFACE_COLOR(Color) \
300 (VALID_PLOTTING_COLOR(Color) || VALID_INTERFACE_SPECIFIC_COLOR(Color))
301 #define VALID_MULTICOLOR_COLOR(Color) \
302 (((Color) == MultiColor_C) || ((Color) == MultiColor2_C) || \
303 ((Color) == MultiColor3_C) || ((Color) == MultiColor4_C) || \
304 ((Color) == MultiColor5_C) || ((Color) == MultiColor6_C) || \
305 ((Color) == MultiColor7_C) || ((Color) == MultiColor8_C))
306 #define VALID_RGB_COLOR(Color) \
307 ((Color) == RGBColor_C)
308 #define VALID_ASSIGNABLE_COLOR(C) \
309 (VALID_BASIC_COLOR(C) || \
310 VALID_MULTICOLOR_COLOR(C) || \
312 #define VALID_PEN_OFFSET(PenOffset) \
313 (Black_C<=(PenOffset) && (PenOffset)<=NumPlotterPens)
314 #define VALID_PEN_OFFSET_FOR_OBJECT(PenOffset) \
315 (FirstObjectPen<=(PenOffset) && (PenOffset)<=LastObjectPen)
318 /* to check FE cells */
319 #define VALID_ELEMENT_TYPE(element_type) \
320 ((element_type) == ZoneType_FETriangle || \
321 (element_type) == ZoneType_FEQuad || \
322 (element_type) == ZoneType_FETetra || \
323 (element_type) == ZoneType_FEBrick || \
324 (element_type) == ZoneType_FELineSeg)
329 * Test validity of zone and variable names. A valid name is one that has a
330 * valid reference, is not padded with spaces and is within the maximum
333 #define VALID_NAME(Name, MaxLength) \
334 (VALID_REF(Name) && \
335 (ISEMPTYSTRING(Name) || \
336 (!isspace((Name)[0]) && !isspace((Name)[strlen(Name)-1]))) && \
337 strlen(Name) <= (MaxLength))
338 #define VALID_ZONE_NAME(Name) VALID_NAME((Name), MaxChrsZnTitle)
339 #define VALID_VAR_NAME(Name) VALID_NAME((Name), MaxChrsVarName)
342 /* Special test for lighting effect (don't allow "none" in some cases) */
343 #define VALID_LIGHTINGEFFECT(L) \
344 (((L) == LightingEffect_Paneled) || ((L) == LightingEffect_Gouraud))
347 /* type definition for assert failure notification function */
348 typedef void (*TAssertFailureNotifyFunc
)(
349 const char *expression
, /* text representation of the assertion */
350 const char *file_name
, /* name of the file containing the assertion */
351 int line
); /* line number in the file of the assertion */
353 #if !defined STD_ASSERTS
354 /* external function prototypes */
356 const char *expression
, /* text representation of the assertion */
357 const char *file_name
, /* name of the file containing the assertion */
358 int line
); /* line number in the file of the assertion */
360 extern TAssertFailureNotifyFunc
InstallTAssertFailureNotify(
361 TAssertFailureNotifyFunc new_function
); /* new notification function */
362 #endif /* !STD_ASSERTS */
363 /* ENDREMOVEFROMADDON */
365 #if defined NO_ASSERTS
366 /* BEGINREMOVEFROMADDON */
367 # define TASSERT(EXPR)
368 /* ENDREMOVEFROMADDON */
369 # define INVARIANT(EXPR)
370 # define REQUIRE(EXPR)
371 # define ENSURE(EXPR)
376 # define VERIFY(EXPR) ((void)(EXPR))
378 * Only define IGNORENOTIMPLEMENTED if building a "test" release build
379 * that you are fully aware may contain unimplemented features.
381 # if defined IGNORENOTIMPLEMENTED
382 # define NOT_IMPLEMENTED() CHECK(FALSE)
386 * NOT_IMPLEMENTED is defined using a parameter, but should be called with none,
387 * this will then throw a warning and not break the compile. Unix doesn't pick
388 * up this warning, so break the compile under Unix
390 # define NOT_IMPLEMENTED(x) TAssert("Not Implemented", __FILE__, __LINE__)
393 # define NOT_IMPLEMENTED() not implemented /* intentionally break the compile */
396 #elif defined STD_ASSERTS
397 /* BEGINREMOVEFROMADDON */
398 # define TASSERT(EXPR) assert(EXPR)
399 /* ENDREMOVEFROMADDON */
400 # define INVARIANT(EXPR) assert(EXPR)
401 # define REQUIRE(EXPR) assert(EXPR)
402 # define ENSURE(EXPR) assert(EXPR)
403 # define CHECK(EXPR) assert(EXPR)
409 # define VERIFY(EXPR) ((void)(EXPR))
411 # define VERIFY(EXPR) assert(EXPR)
414 # define NOT_IMPLEMENTED() assert(!("Not Implemented"))
416 /* BEGINREMOVEFROMADDON */
418 #if defined CHECKED_BUILD
426 static void initializeAssertLog(const std::string
&fileName
);
427 static bool isLoggingAssertions();
428 static void addAssertion(const std::string
&message
);
430 static void writeOutAssertion(const std::string
&message
);
432 static bool logAssertions
;
433 static std::string logFileName
;
434 static std::vector
<std::string
> assertList
;
437 extern void TWinCheckedFailedLine(const char *Expr
,
438 const char *FileName
,
441 #define TASSERT(EXPR)\
442 do { if (!(EXPR)) { TWinCheckedFailedLine(#EXPR,__FILE__,__LINE__); } } while (0)
444 #define TASSERT(EXPR) ASSERT(EXPR) /* MFC assert.
445 Works in both release & debug builds */
446 #endif /* CHECKED_BUILD */
448 #define TASSERT(EXPR) (void)((EXPR) || (TAssert(#EXPR, __FILE__, __LINE__), 0))
451 # if defined NO_INVARIANTS
452 # define INVARIANT(EXPR)
454 # define INVARIANT(EXPR) TASSERT(EXPR)
457 # if defined NO_PRECONDITIONS
458 # define REQUIRE(EXPR)
460 # define REQUIRE(EXPR) TASSERT(EXPR)
463 # if defined NO_POSTCONDITIONS
464 # define ENSURE(EXPR)
466 # define ENSURE(EXPR) TASSERT(EXPR)
473 # if defined NO_CHECKS
475 # define VERIFY(EXPR) ((void)(EXPR))
477 # define CHECK(EXPR) TASSERT(EXPR)
479 # define VERIFY(EXPR) ((void)(EXPR))
481 # define VERIFY(EXPR) TASSERT(EXPR)
485 # if defined NICE_NOT_IMPLEMENTED
486 # define NOT_IMPLEMENTED() NiceNotImplemented()
488 # define NOT_IMPLEMENTED() TASSERT(!("Not Implemented"))
490 /* ENDREMOVEFROMADDON */
492 /* BEGINREMOVEFROMADDON */
493 #if !defined STD_ASSERTS
494 extern void TecplotMopupOnAssert(void);
495 #endif /* !STD_ASSERTS */
497 #if defined NICE_NOT_IMPLEMENTED
498 extern void NiceNotImplemented(void);
500 /* ENDREMOVEFROMADDON */
502 /* convenience macros for implication, P -> Q, and equivalence, P <-> Q. */
503 #define IMPLICATION(P,Q) (!(P) || (Q))
504 #define EQUIVALENCE(P,Q) ((P) == (Q))
506 /* BEGINREMOVEFROMADDON */
508 #define VALID_RLM_HANDLE(h) ((h) != NULL)
510 /* ENDREMOVEFROMADDON */
513 #endif /* TASSERT_H */