home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / odtlktv4.zip / ODTLKT / TOOLKIT / BETA / SAMPLES / OPENDOC / PUBUTILS / ODDEBUG.CPP < prev    next >
C/C++ Source or Header  |  1995-11-16  |  4KB  |  133 lines

  1. /*************************************************************************/
  2. /*  Licensed Materials - Property of IBM                                 */
  3. /*                                                                       */
  4. /*                                                                       */
  5. /* Copyright (C) International Business Machines Corp., 1994.            */
  6. /* Copyright (C) Apple Computer, Inc., 1994                              */
  7. /*                                                                       */
  8. /*  US Government Users Restricted Rights -                              */
  9. /*  Use, duplication, or disclosure restricted                           */
  10. /*  by GSA ADP Schedule Contract with IBM Corp.                          */
  11. /*                                                                       */
  12. /*  File:    ODDebug.cpp                                                 */
  13. /*                                                                       */
  14. /*  Contains:  Useful debugging macros and functions.                    */
  15. /*                                                                       */
  16. /*  133493  08/18/95  ced Use SOM_WarnMsg instead of somPrintf in _Warn  */
  17. /*                                                                       */
  18. /*************************************************************************/
  19.  
  20. #include <builtin.h>
  21.  
  22. #ifndef _ODDEBUG_
  23. #include "ODDebug.h"
  24. #endif
  25.  
  26. #ifndef _EXCEPT_
  27. #include "Except.h"
  28. #endif
  29.  
  30. #include <stdio.h>
  31. #include <stdarg.h>
  32. #include <string.h>
  33.  
  34.  
  35. //=====================================================================================
  36. // BREAK() 
  37. //=====================================================================================
  38. #ifndef _PLATFORM_OS2_PPC_
  39. #define BREAK(msg) _interrupt(3);
  40. #else
  41. #define BREAK(msg) // How do you break into debugger on PPC???
  42. #endif
  43.  
  44. //===================================================================================
  45. // ASSERTION-FAILED
  46. //===================================================================================
  47.  
  48. #if ODDebug
  49.  
  50. void _AssertionFailed( const char *cond, ODError error, const char *msg, 
  51.                        int linenum, const char* function, const char* file )
  52. {
  53.   char dbg[512];
  54.   if (error)
  55.   {
  56.      sprintf(dbg,"%s: %s ...NOT!\n", msg ? msg : "Assertion failed",cond);
  57.      THROWproc(error, dbg, linenum, function, file);  // THROWproc prints message
  58.   } 
  59.   else
  60.      somPrintf(dbg, "%s: %s ...NOT! in %s - %s(%d)\n", msg ? msg : "Assertion failed",
  61.                cond, function, file, linenum);
  62. }
  63.  
  64. #else
  65.  
  66. void _AssertionFailed( const char *cond, ODError error, const char *msg, 
  67.                        int linenum, const char* function, const char* file )
  68. {
  69. }
  70.  
  71. #endif /*ODDebug*/
  72.  
  73.  
  74. //===================================================================================
  75. // WARN
  76. //===================================================================================
  77.  
  78. #if ODDebug
  79.  
  80. void _Warn( char *fmt, ... )
  81. {
  82.   char msg[512];
  83.   strcpy(msg, "ODWarning: ");
  84.   va_list args;
  85.   va_start(args,fmt);
  86.   vsprintf(msg+strlen(msg),fmt,args);
  87.   va_end(args);
  88.   SOM_WarnMsg(msg);                    // [133493] - ced
  89.   if (getenv("ODBREAKONWARN"))
  90.      BREAK(msg);
  91. }
  92.  
  93. #else
  94.  
  95. extern "C" void _Warn(  char *fmt, ... );
  96. void _Warn(  char *fmt, ... )
  97. {
  98. }
  99.  
  100. #endif /*ODDebug*/
  101.  
  102. //==============================================================================
  103. // SAFE CAST
  104. //==============================================================================
  105.  
  106.  
  107. #if ODDebug
  108.  
  109. SOMObject*
  110. _Cast( SOMObject *obj, SOMClass *cls, int line, const char* file, const char* function )
  111. {
  112.   char dbg[256];
  113.   if( !somIsObj(obj) )
  114.     sprintf(dbg, "Can't cast: %p is not a SOM object",obj);
  115.   else if( !somIsObj(cls) )
  116.     sprintf(dbg, "Can't cast: %p is not a SOM class",cls);
  117.   else if( !obj->somIsA(cls) )
  118.     sprintf(dbg, "Can't cast: %p is an %s, not an %s",obj, obj->somGetClassName(), cls->somGetName());
  119.   else
  120.     return obj;
  121.   THROWproc(kODErrAssertionFailed, dbg, line, file, function);
  122.   return NULL; /* keeps compiler quiet */
  123. }
  124.  
  125. #else
  126.  
  127. extern "C" void _Cast( );
  128. void _Cast( )
  129. {
  130. }
  131.  
  132. #endif /*ODDebug*/
  133.