/* * NOTICE and LICENSE for Tecplot Input/Output Library (TecIO) - OpenFOAM * * Copyright (C) 1988-2009 Tecplot, Inc. All rights reserved worldwide. * * Tecplot hereby grants OpenCFD limited authority to distribute without * alteration the source code to the Tecplot Input/Output library, known * as TecIO, as part of its distribution of OpenFOAM and the * OpenFOAM_to_Tecplot converter. Users of this converter are also hereby * granted access to the TecIO source code, and may redistribute it for the * purpose of maintaining the converter. However, no authority is granted * to alter the TecIO source code in any form or manner. * * This limited grant of distribution does not supersede Tecplot, Inc.'s * copyright in TecIO. Contact Tecplot, Inc. for further information. * * Tecplot, Inc. * 3535 Factoria Blvd, Ste. 550 * Bellevue, WA 98006, USA * Phone: +1 425 653 1200 * http://www.tecplot.com/ * */ /* ****************************************************************** ****************************************************************** ******* ******** ****** (C) 1988-2008 Tecplot, Inc. ******* ******* ******** ****************************************************************** ****************************************************************** */ /* * Provide four levels of assertion control. Assertions provide a mechanism * to enforce a contract between a client and service provider. The assertions * are listed in order of highest to lowest priority. Assertions can be turned * off individually by defining the appropriate name (see preprossessor * definitions below), however, lower priority assertions should be turned * off prior to higher ones. As confidence in the code increases all assertions * can be turned off by defining NO_ASSERTS. * * The assertions defined below have the following meanings: * * INVARIANT - Asserts that a property's state is invariant throughout the * life of the property's scope. Stating invariant properties * of an application provides a deeper understanding of the * application's state. These statements are usually * positioned just ahead of the preconditions and just after * the postconditions. * * REQUIRE - Asserts that a method's preconditions are within their * valid domains. Preconditions are conditions placed upon * any state information relied upon for the call. These * statements should be as close to the top of the method * as possible (except for assertions on invariant properties). * * ENSURE - Asserts that a method's postconditions are within their * valid ranges. Postconditions are conditions placed upon * any state information modified by the call. These * statements should be as close to the bottom of the method * (presumably there is only one exit point) as possible * (except for assertions on invariant properties). * * CHECK - Any other assertion not covered by the above assertions. * These are often added within a method body to specify * something that may not be immediately obvious to the reader * or to validate your assumptions about a call to a 3rd party * method that does not use runtime assertions for its * preconditions or postconditions. Obviously if the 3rd party * method uses assertions then there is no need for the CHECK. * * Additionally a convenience macro is available to place in code that is * pending implementation. * * NOT_IMPLEMENTED - Assertion that always fails during runtime for debug * builds and always fails at compile time for release * builds. */ #if !defined TASSERT_H #define TASSERT_H #if defined (MSWIN) # include #endif /* MSWIN */ #if !defined TECPLOTKERNEL && !defined STD_ASSERTS #define STD_ASSERTS #endif #if !defined (MSWIN) # include # if !defined ASSERT # define ASSERT assert # endif #endif #if defined MSWIN /* MFC .NET defines ENSURE, so we undefine it here */ #if defined ENSURE #undef ENSURE #endif /* ENSURE */ #endif /* MSWIN */ /* BEGINREMOVEFROMADDON */ #define INVALID_REF ((void *)0x0000FFFF) /* * Chances are low the address 0x11111111 will be used, so we'll risk asserting * against it (see unitialized assignment in newmalloc). */ #define UNINITIALIZED_REF ((void *)0x11111111) #define INVALID_FN_REF ((void *)NULL) /* ENDREMOVEFROMADDON */ #ifdef UNIXX /* BEGINREMOVEFROMADDON */ #if defined TECPLOTKERNEL /* CORE SOURCE CODE REMOVED */ # if defined NO_ASSERTS # else # endif #endif /* TECPLOTKERNAL */ /* ENDREMOVEFROMADDON */ /* BEGINREMOVEFROMADDON */ #if !defined TECPLOTKERNEL /* For add-ons, there is a problem with VALID_REF, so just test for non-NULL */ /* ENDREMOVEFROMADDON */ # define VALID_REF(p) ( (p) != NULL ) # define VALID_FN_REF(fp) ( (fp) != NULL ) /* BEGINREMOVEFROMADDON */ #endif /* !defined TECPLOTKERNAL */ /* ENDREMOVEFROMADDON */ /* BEGINREMOVEFROMADDON */ /* Widgets are pointers under Motif */ # define VALID_WIDGET(widget) VALID_REF((widget)) /* Menu widgets are pointers too */ # define VALID_MENU_WIDGET(widget) VALID_REF((widget)) /* ENDREMOVEFROMADDON */ #endif /* UNIXX */ #ifdef MSWIN /* BEGINREMOVEFROMADDON */ /* Don't use AfxIsValidAddress()! See Bug <7245>. 1/4/08, dto. */ /* ENDREMOVEFROMADDON */ #if defined NO_ASSERTS /* release build in TecUtil layer uses these for TUASSERT */ # define VALID_REF(p) ((p) != NULL) # define VALID_FN_REF(pf) ((pf) != NULL) #else # define VALID_REF(p) ((p) != NULL && !IsBadReadPtr((const void *)(p), 1)) # define VALID_FN_REF(pf) ((pf) != NULL && !IsBadReadPtr((const void *)(pf),(UINT_PTR)sizeof(const void*))) #endif /* BEGINREMOVEFROMADDON */ /* Widgets are numbers under Windows, so we decode it with GetWindowFromWidget */ # if defined ENGINE # define VALID_WIDGET(widget) ((widget) != NULL) # else # define VALID_WIDGET(widget) ((widget) != NULL && GetWindowFromWidget((widget))!=NULL) # endif // ENGINE /* Menu widgets are numbers too, so we just check against zero */ # define VALID_MENU_WIDGET(widget) ((widget)!=NULL) /* ENDREMOVEFROMADDON */ #endif /* MSWIN */ /* BEGINREMOVEFROMADDON */ /* handles are not pointers to memory, so the only test we can */ /* perform is to check for 0 */ #define VALID_HANDLE(handle) ((handle)!=0) #if defined FLEXLM #define VALID_FLEX_JOB_HANDLE(handle) ((handle) != NULL) #define VALID_FLEX_ERROR_CODE(ErrorCode)(ErrorCode <= 0) #endif /* FLEXLM */ /* ENDREMOVEFROMADDON */ /* other useful validity checks */ #define VALID_BOOLEAN(b) ((b) == TRUE || (b) == FALSE) #define VALID_ENUM(value, type) (0 <= (value) && \ (value) < END_##type) /* Test a parameter than can be NULL or a valid pointer */ #define VALID_REF_OR_NULL(ptr) IMPLICATION((ptr) != NULL, VALID_REF(ptr)) #define VALID_FN_REF_OR_NULL(ptr) IMPLICATION((ptr) != NULL, VALID_FN_REF(ptr)) /* BEGINREMOVEFROMADDON */ #define VALID_TRANSLATED_STRING(ts) (!(ts).isNull()) /** * These macros are a little complicated but it allows one to * write a simple assertion regardless of the zone type or * selected plane: * * REQUIRE(VALID_CELL_INDEX(CZData, CellIndex, Plane))); * * Prior to using the macros a call to SetupXxx, * or at a minimum SetupCZData, must be called to setup * the globals defining the dataset structure. */ #define VALID_FE_CELL_INDEX(CZData, CellIndex) \ (/* CellIndex range test */ \ 0 <= (CellIndex) && \ (CellIndex) < (CZData)->NumElements) #define VALID_IPLANE_CELL_INDEX(CZData,CellIndex) \ (/* CellIndex range test */ \ (CellIndex) >= 0 && \ IINDEX((CZData),CellIndex) <= MAX((CZData)->NumIPtsM1,1) && \ JINDEX((CZData),CellIndex) < MAX((CZData)->NumJPtsM1,1) && \ KINDEX((CZData),CellIndex) < MAX((CZData)->NumKPtsM1,1)) #define VALID_JPLANE_CELL_INDEX(CZData,CellIndex) \ (/* CellIndex range test */ \ (CellIndex) >= 0 && \ IINDEX((CZData),CellIndex) < MAX((CZData)->NumIPtsM1,1) && \ JINDEX((CZData),CellIndex) <= MAX((CZData)->NumJPtsM1,1) && \ KINDEX((CZData),CellIndex) < MAX((CZData)->NumKPtsM1,1)) #define VALID_KPLANE_CELL_INDEX(CZData,CellIndex) \ (/* CellIndex range test */ \ (CellIndex) >= 0 && \ IINDEX((CZData),CellIndex) < MAX((CZData)->NumIPtsM1,1) && \ JINDEX((CZData),CellIndex) < MAX((CZData)->NumJPtsM1,1) && \ KINDEX((CZData),CellIndex) <= MAX((CZData)->NumKPtsM1,1)) #define VALID_ORDERED_CELL_INDEX(CZData, CellIndex, Plane) \ (/* macro preconditions */ \ ((IJKPlanes_e)(Plane) == IJKPlanes_I || \ (IJKPlanes_e)(Plane) == IJKPlanes_J || \ (IJKPlanes_e)(Plane) == IJKPlanes_K || \ (IJKPlanes_e)(Plane) == IJKPlanes_Volume) && \ \ /* CellIndex range test */ \ (IMPLICATION(((IJKPlanes_e)(Plane) == IJKPlanes_I || \ (IJKPlanes_e)(Plane) == IJKPlanes_Volume), \ VALID_IPLANE_CELL_INDEX((CZData),CellIndex)) && \ IMPLICATION(((IJKPlanes_e)(Plane) == IJKPlanes_J || \ (IJKPlanes_e)(Plane) == IJKPlanes_Volume), \ VALID_JPLANE_CELL_INDEX((CZData),CellIndex)) && \ IMPLICATION(((IJKPlanes_e)(Plane) == IJKPlanes_K || \ (IJKPlanes_e)(Plane) == IJKPlanes_Volume), \ VALID_KPLANE_CELL_INDEX((CZData),CellIndex)))) #define VALID_CELL_INDEX(CZData, CellIndex, Plane) \ (((CZData)->NM != NULL || (CZData)->FM != NULL) ? \ VALID_FE_CELL_INDEX((CZData), (CellIndex)) : \ VALID_ORDERED_CELL_INDEX((CZData), (CellIndex), (Plane))) #define VALID_DATASET(dataSet,checkNumZones) (((dataSet) != NULL) && \ IMPLICATION((checkNumZones),(dataSet)->NumZones >= 1)) #ifdef MSWIN /* Here is a more specific check in Windows for a valid pointer to an MFC Window object. Note that GetSafeHwnd() works even if pWnd is NULL, because it checks the 'this' pointer first */ # define VALID_WND(pWnd) (::IsWindow((pWnd)->GetSafeHwnd())) #else /* !MSWIN */ # define VALID_WND(pWnd) /* Should not be used in Motif */ #endif /* MSWIN */ /* ENDREMOVEFROMADDON */ /* Check for a non-zero length string */ #if defined MSWIN # if defined NO_ASSERTS # define VALID_NON_ZERO_LEN_STR(str) (VALID_REF(str) && !ISEMPTYSTRING(str)) # else # define VALID_NON_ZERO_LEN_STR(str) \ (VALID_REF(str) && \ !IsBadReadPtr((const void*)(str),(UINT_PTR)(1+strlen((const char*)(str)))) && \ !ISEMPTYSTRING(str)) # endif #else # define VALID_NON_ZERO_LEN_STR(str) (VALID_REF(str) && !ISEMPTYSTRING(str)) #endif #define VALID_SET_INDEX(setIndex) (((SetIndex_t)setIndex)>=(SetIndex_t)1) /* Check for valid stdio file handle */ #define VALID_FILE_HANDLE(stream) ((stream) != NULL) /* To check colors and pen numbers */ /* BEGINREMOVEFROMADDON */ #define VALID_BASIC_COLOR(BColor) \ (FirstBasicColor<=(BColor) && (BColor)<=LastBasicColor) #define VALID_CONTOUR_COLOR(Color) \ (ContourColorOffset<=(Color) && \ (Color) #include #include class AssertionLog { public: static void initializeAssertLog(const std::string &fileName); static bool isLoggingAssertions(); static void addAssertion(const std::string &message); private: static void writeOutAssertion(const std::string &message); private: static bool logAssertions; static std::string logFileName; static std::vector assertList; }; extern void TWinCheckedFailedLine(const char *Expr, const char *FileName, int LineNum); #define TASSERT(EXPR)\ do { if (!(EXPR)) { TWinCheckedFailedLine(#EXPR,__FILE__,__LINE__); } } while (0) #else #define TASSERT(EXPR) ASSERT(EXPR) /* MFC assert. Works in both release & debug builds */ #endif /* CHECKED_BUILD */ #else #define TASSERT(EXPR) (void)((EXPR) || (TAssert(#EXPR, __FILE__, __LINE__), 0)) #endif # if defined NO_INVARIANTS # define INVARIANT(EXPR) # else # define INVARIANT(EXPR) TASSERT(EXPR) # endif # if defined NO_PRECONDITIONS # define REQUIRE(EXPR) # else # define REQUIRE(EXPR) TASSERT(EXPR) # endif # if defined NO_POSTCONDITIONS # define ENSURE(EXPR) # else # define ENSURE(EXPR) TASSERT(EXPR) # endif # if defined VERIFY # undef VERIFY # endif # if defined NO_CHECKS # define CHECK(EXPR) # define VERIFY(EXPR) ((void)(EXPR)) # else # define CHECK(EXPR) TASSERT(EXPR) # if defined NDEBUG # define VERIFY(EXPR) ((void)(EXPR)) # else # define VERIFY(EXPR) TASSERT(EXPR) # endif # endif # if defined NICE_NOT_IMPLEMENTED # define NOT_IMPLEMENTED() NiceNotImplemented() # else # define NOT_IMPLEMENTED() TASSERT(!("Not Implemented")) # endif /* ENDREMOVEFROMADDON */ #endif /* BEGINREMOVEFROMADDON */ #if !defined STD_ASSERTS extern void TecplotMopupOnAssert(void); #endif /* !STD_ASSERTS */ #if defined NICE_NOT_IMPLEMENTED extern void NiceNotImplemented(void); #endif /* ENDREMOVEFROMADDON */ /* convenience macros for implication, P -> Q, and equivalence, P <-> Q. */ #define IMPLICATION(P,Q) (!(P) || (Q)) #define EQUIVALENCE(P,Q) ((P) == (Q)) /* BEGINREMOVEFROMADDON */ #if defined RLM #define VALID_RLM_HANDLE(h) ((h) != NULL) #endif /* RLM */ /* ENDREMOVEFROMADDON */ #endif /* TASSERT_H */