Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

debug.hpp

Go to the documentation of this file.
00001 #ifndef DEBUG_HPP
00002 #define DEBUG_HPP
00003 
00004 
00005 #include <assert.h>
00006 #include <stdio.h>
00007 #include <string>
00008 
00009 
00010 #if defined(_DEBUG) || defined(DEBUG)
00011 
00012   class Log {
00013   public:
00014     static void Write(const char* str);
00015     static void IncrementIndent() { ++indent_count; }
00016     static void DecrementIndent() { --indent_count; }
00017 
00018   private:
00019     static void EnsureOpen();
00020     static void Close();
00021 
00022   private:
00023     static FILE* handle;
00024     static int indent_count;
00025   };
00026 
00027 
00028   class Guard {
00029   public:
00030     Guard(const char* label)
00031     : m_label(label) {
00032       Write("+");
00033       Log::IncrementIndent();
00034     }
00035 
00036     ~Guard() {
00037       Log::DecrementIndent();
00038       Write("-");
00039     }
00040 
00041     void Write(const char* prefix) {
00042       Log::Write((prefix + m_label).c_str());
00043     }
00044 
00045   private:
00046     std::string m_label;
00047   };
00048 
00049 
00050   #define ADR_GUARD(label) Guard guard_obj__(label)
00051   #define ADR_LOG(label)   (Log::Write(label))
00052   #define ADR_IF_DEBUG     if (true)
00053 
00054   #ifdef _MSC_VER
00055     #define ADR_ASSERT(condition, label) if (!(condition)) { __asm int 3 }
00056   #else  // assume x86 gcc
00057     #define ADR_ASSERT(condition, label) assert(condition && label);
00058   #endif
00059 
00060 #else
00061 
00062   #define ADR_GUARD(label) 
00063   #define ADR_LOG(label)
00064   #define ADR_IF_DEBUG     if (false)
00065   #define ADR_ASSERT(condition, label)
00066 
00067 #endif
00068 
00069 
00070 #endif

Generated at Mon Jun 10 02:55:12 2002 for audiere by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001