home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ODDebug.h
-
- Contains: Useful debugging macros and functions.
-
- Owned by: Jens Alfke
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
- */
-
-
- #ifndef _ODDEBUG_
- #define _ODDEBUG_
-
- #ifndef _ODTYPES_
- #include "ODTypes.h"
- #endif
-
-
- #ifdef _OD_IMPL_SHARE_UTILS_
- #pragma import on
- #endif
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
-
- //=====================================================================================
- // ODInitExceptions
- //=====================================================================================
-
- void ODInitExceptions( );
-
-
- //=====================================================================================
- // Debug Output
- //=====================================================================================
-
- enum DebugOutputMode {
- kNoOutput,
- kWriteToFile,
- kWriteToDebugWindow,
- kGenerateDebugStrs
- };
-
- DebugOutputMode GetOutputMode( );
- void SetOutputMode( DebugOutputMode );
-
-
- //=====================================================================================
- // Warnings
- //=====================================================================================
-
- // WARN has the same syntax as printf but produces a SysBreakStr.
- // Warnings are disabled (and generate no code) when ODDebug is off.
-
- #define WARN if(!ODDebug) ; else _Warn
-
-
- //=====================================================================================
- // Assertions
- //=====================================================================================
-
- // These all cause a debugger break if the condition evaluates to false or 0.
- // Leading "W" is a Warning: it doesn't raise an exception.
- // Trailing "M" means special Message displayed instead of condition.
-
- #ifndef __MWERKS__
- #define _FIL_ "" /* MPW puts entire pathnames in; yuk! */
- #else
- #define _FIL_ __FILE__
- #endif
-
- #define ASSERT( COND, ERR ) \
- if(!ODDebug || (COND)) ; else _AssertionFailed( #COND, _FIL_, ERR )
- #define ASSERTM( COND, ERR, MSG ) \
- if(!ODDebug || (COND)) ; else _AssertionFailed( #COND, _FIL_, ERR, MSG )
- #define WASSERT( COND ) \
- if(!ODDebug || (COND)) ; else _AssertionFailed( #COND, _FIL_, 0)
- #define WASSERTM( COND, MSG ) \
- if(!ODDebug || (COND)) ; else _AssertionFailed( #COND, _FIL_, 0, MSG)
-
- // ASSERT_NOT_NULL causes a debugger break and an exception if the parameter
- // is NULL. Use this in functions that take a pointer as a parameter but do
- // not allow the parameter to be NULL.
- // Do **NOT** use this macro to make sure memory allocation succeeded! It
- // has no effect in non-debug builds. Use THROW_IF_NULL instead.
-
- #define ASSERT_NOT_NULL(PARAM) \
- ASSERT((PARAM)!=kODNULL, kODErrIllegalNullInput)
-
-
- //=====================================================================================
- // Logging
- //=====================================================================================
-
- // PRINT writes to the standard output via somPrintf if ODDebug is on. Use
- // SetOutputMode (or the ODDebug menu) to direct output to a file or to the
- // DebugWindow app.
-
- #define PRINT if(!ODDebug) ; else somPrintf
-
- // LOG is like PRINT but can easily be turned on or off on a per-file basis.
- // To enable logging in a source file, you must redefine the symbol LOGGING
- // as "1" in that file, otherwise LOG statements will not be compiled. Make
- // sure to #undef the symbol before you re-#define it, as some compilers
- // won't redefine an already-defined symbol.
-
- // PRINT and LOG statements do not generate any code if logging is off.
-
- #define LOGGING 0 // Redefine as 1 in source file to enable logging
-
- #define LOG if(!ODDebug || !LOGGING) ; else somPrintf
-
-
- //==============================================================================
- // Safe Type-Casting
- //==============================================================================
-
- /* Use CAST as a safe way to cast a SOM object from one class to another.
- For instance, if "o" is declared as an ODObject*, but your code knows
- it's an ODPart*, you can say:
- ODPart *part = CAST(o,ODPart);
- If ODDebug is turned on, this will do a runtime check and cause an assertion
- failure if o does not point to an ODPart (or subclass). Without ODDebug,
- it degenerates into a simple C-style cast that generates no code.
-
- ASSERT_IS_A is similar to CAST but is used when you just want to assert
- that the pointer points to the right kind of object.
- */
-
- #if ODDebug
- #define CAST(OBJ, CLASS) ( (CLASS*)_Cast((OBJ), (somClassDataStructure*) &CLASS##ClassData, \
- CLASS##_MajorVersion, CLASS##_MinorVersion) )
- #define ASSERT_IS_A(OBJ,CLASS) ( (void) CAST(OBJ,CLASS) )
- #else
- #define CAST(OBJ, CLASS) ( (CLASS*) (OBJ) )
- #define ASSERT_IS_A(OBJ,CLASS) /* */
- #endif
-
-
- //=====================================================================================
- // Internal goop...
- //=====================================================================================
-
- void _Warn ( char *fmt, ... );
- void _AssertionFailed ( char *cond, char *fileName,
- ODError, char *msg = kODNULL );
- #if ODDebug
- SOMObject* _Cast( SOMObject *obj, somClassDataStructure *cls, long major, long minor );
- #endif
-
-
- #ifdef __cplusplus
- }
- #endif
-
- #ifdef _OD_IMPL_SHARE_UTILS_
- #pragma import off
- #endif
-
- #endif /*_ODDEBUG_*/
-