home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_07.cab / debug.h < prev    next >
C/C++ Source or Header  |  1997-10-25  |  3KB  |  116 lines

  1. /*
  2.  * Some simple debugging macros that look and behave a lot like their
  3.  * namesakes in MFC.  These macros should work in both C and C++ and
  4.  * do something useful with almost any Win32 compiler.
  5.  *
  6.  * George V. Reilly  <georgere@microsoft.com>
  7.  */
  8.  
  9. #ifndef __DEBUG_H__
  10. #define __DEBUG_H__
  11.  
  12. #include <tchar.h>
  13.  
  14. #ifdef _DEBUG
  15.  
  16. # if defined(_MSC_VER)  &&  (_MSC_VER >= 1000)
  17.    /* Use the new debugging tools in Visual C++ 4.x */
  18. #  include <crtdbg.h>
  19.    /* _ASSERTE will give a more meaningful message, but the string takes
  20.     * space.  Use _ASSERT if this is an issue. */
  21. #  define ASSERT(f) _ASSERTE(f)
  22. # else
  23. #  include <assert.h>
  24. #  define ASSERT(f) assert(f)
  25. # endif
  26.  
  27. # define VERIFY(f)               ASSERT(f)
  28. # define DEBUG_ONLY(f)           (f)
  29. # define TRACE                   Trace
  30. # define TRACE0(psz)             Trace(_T("%s"), _T(psz))
  31. # define TRACE1(psz, p1)         Trace(_T(psz), p1)
  32. # define TRACE2(psz, p1, p2)     Trace(_T(psz), p1, p2)
  33. # define TRACE3(psz, p1, p2, p3) Trace(_T(psz), p1, p2, p3)
  34. # define ASSERT_VALID(pObj)  \
  35.     do {ASSERT((pObj) != NULL); (pObj)->AssertValid();} while (0)
  36. # define DUMP(pObj)  \
  37.     do {ASSERT((pObj) != NULL); (pObj)->Dump();} while (0)
  38. # define DEBUG_INIT()            DebugInit()
  39. # define DEBUG_TERM()            DebugTerm()
  40.  
  41. #else /* !_DEBUG */
  42.  
  43.   /* These macros should all compile away to nothing */
  44. # define ASSERT(f)               ((void)0)
  45. # define VERIFY(f)               ((void)(f))
  46. # define DEBUG_ONLY(f)           ((void)0)
  47. # define TRACE                   1 ? (void)0 : Trace
  48. # define TRACE0(psz)
  49. # define TRACE1(psz, p1)
  50. # define TRACE2(psz, p1, p2)
  51. # define TRACE3(psz, p1, p2, p3)
  52. # define ASSERT_VALID(pObj)      ((void)0)
  53. # define DUMP(pObj)              ((void)0)
  54. # define DEBUG_INIT()            ((void)0)
  55. # define DEBUG_TERM()            ((void)0)
  56.  
  57. #endif /* !_DEBUG */
  58.  
  59.  
  60. #define ASSERT_POINTER(p, type) \
  61.     ASSERT(((p) != NULL)  &&  IsValidAddress((p), sizeof(type), FALSE))
  62.  
  63. #define ASSERT_NULL_OR_POINTER(p, type) \
  64.     ASSERT(((p) == NULL)  ||  IsValidAddress((p), sizeof(type), FALSE))
  65.  
  66.  
  67. /* Declarations for non-Windows apps */
  68.  
  69. #ifndef _WINDEF_
  70. typedef void*           LPVOID;
  71. typedef const void*     LPCVOID;
  72. typedef unsigned int    UINT;
  73. typedef int             BOOL;
  74. typedef const char*     LPCTSTR;
  75. #endif /* _WINDEF_ */
  76.  
  77. #ifndef TRUE
  78. # define FALSE  0
  79. # define TRUE   1
  80. #endif
  81.  
  82.  
  83. #ifdef __cplusplus
  84. extern "C" {
  85.  
  86. /* Low-level sanity checks for memory blocks */
  87. BOOL IsValidAddress(LPCVOID pv, UINT nBytes, BOOL fReadWrite = TRUE);
  88. BOOL IsValidString(LPCTSTR ptsz, int nLength = -1);
  89.  
  90. #else /* !__cplusplus */
  91.  
  92. /* Low-level sanity checks for memory blocks */
  93. BOOL IsValidAddress(LPCVOID pv, UINT nBytes, BOOL fReadWrite);
  94. BOOL IsValidString(LPCTSTR ptsz, int nLength);
  95.  
  96. #endif /* !__cplusplus */
  97.  
  98. /* in debug version, writes trace messages to debug stream */
  99. void __cdecl
  100. Trace(
  101.     LPCTSTR pszFormat,
  102.     ...);
  103.  
  104. /* should be called from main(), WinMain(), or DllMain() */
  105. void
  106. DebugInit();
  107.  
  108. void
  109. DebugTerm();
  110.  
  111. #ifdef __cplusplus
  112. }
  113. #endif /* __cplusplus */
  114.  
  115. #endif /* __DEBUG_H__ */
  116.