home *** CD-ROM | disk | FTP | other *** search
/ Game Audio Programming / GameAudioProgramming.iso / Game_Audio / audio_sdk / include / AudioLib / Diagnostics.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-06-17  |  2.1 KB  |  88 lines

  1. /***********************************************************\
  2. Copyright (C) James Boer, 2002. 
  3. All rights reserved worldwide.
  4.  
  5. This software is provided "as is" without express or implied
  6. warranties. You may freely copy and compile this source into
  7. applications you distribute provided that the copyright text
  8. below is included in the resulting source code, for example:
  9. "Portions Copyright (C) James Boer, 2002"
  10. \***********************************************************/
  11. #ifndef __DIAGNOSTICS_H
  12. #define __DIAGNOSTICS_H
  13.  
  14. namespace Audio
  15. {
  16.  
  17. #define MAX_DEBUG_LINE_LEN 256
  18.  
  19. inline void OutputStringFn(const char* pszString)
  20. {  
  21. #ifdef _WINDOWS_
  22.     OutputDebugString(pszString);
  23. #endif
  24. }
  25.  
  26. #ifdef _DEBUG
  27. // The diagnostics flag is by default tied to the _DEBUG flag, but can
  28. // be left on for use in release builds if desired.
  29. #define DIAGNOSTICS
  30. #endif
  31.  
  32. #ifdef DIAGNOSTICS
  33.  
  34. class DIAG
  35. {
  36. public: 
  37.  
  38.     static void SetDiagDebugLevel(int iLevel)    
  39.     {  m_iDebugLevel = iLevel;  }
  40.     static void DiagDebugOut(int iLevel, const char* lpszFormat, ...) 
  41.     { 
  42.         va_list args; 
  43.         va_start(args, lpszFormat); 
  44.         char szBuffer[MAX_DEBUG_LINE_LEN]; 
  45.         int nBuf = _vsnprintf(szBuffer, MAX_DEBUG_LINE_LEN, lpszFormat, args); 
  46.         assert(nBuf >= 0); 
  47.         if(m_iDebugLevel >= iLevel) 
  48.         { 
  49.             szBuffer[nBuf] = '\n';
  50.             szBuffer[nBuf + 1] = 0;
  51.             OutputStringFn(szBuffer); 
  52.         } 
  53.         va_end(args); 
  54.     }
  55.     static void DiagFN(const char* lpszFormat, ...) 
  56.     { 
  57.         va_list args; 
  58.         va_start(args, lpszFormat); 
  59.         char szBuffer[MAX_DEBUG_LINE_LEN]; 
  60.         int nBuf = _vsnprintf(szBuffer, MAX_DEBUG_LINE_LEN, lpszFormat, args); 
  61.         assert(nBuf >= 0); 
  62.         if(m_iDebugLevel >= 5) 
  63.         { 
  64.             szBuffer[nBuf] = '\n';
  65.             szBuffer[nBuf + 1] = 0;
  66.             OutputStringFn(szBuffer); 
  67.         } 
  68.         va_end(args); 
  69.     }
  70. private:
  71.     static int m_iDebugLevel;
  72. };
  73.  
  74. #define DebugOut                DIAG::DiagDebugOut
  75. #define FN                        DIAG::DiagFN
  76. #define SetDebugLevel            DIAG::SetDiagDebugLevel
  77.  
  78. #else // DIAGNOSTICS
  79.     #define DebugOut            ((void)0)
  80.     #define FN                    ((void)0)
  81.     #define SetDebugLevel        ((void)0)
  82.  
  83. #endif // DIAGNOSTICS
  84.  
  85. }; // namespace Audio
  86.  
  87.  
  88. #endif // __DIAGNOSTICS_H