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

debug.h

Go to the documentation of this file.
00001 #ifndef DEBUG_H
00002 #define DEBUG_H
00003 
00004 
00005 #include <assert.h>
00006 #include <stdio.h>
00007 #include <string>
00008 
00009 
00010 namespace audiere {
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 
00051 
00052 #if defined(_DEBUG) || defined(DEBUG)
00053 
00054   #define ADR_GUARD(label) Guard guard_obj__(label)
00055   #define ADR_LOG(label)   (Log::Write(label))
00056   #define ADR_IF_DEBUG     if (true)
00057 
00058   #ifdef _MSC_VER
00059     #define ADR_ASSERT(condition, label) if (!(condition)) { __asm int 3 }
00060   #else  // assume x86 gcc
00061     #define ADR_ASSERT(condition, label) assert(condition && label);
00062   #endif
00063 
00064 #else
00065 
00066   #define ADR_GUARD(label) 
00067   #define ADR_LOG(label)
00068   #define ADR_IF_DEBUG     if (false)
00069   #define ADR_ASSERT(condition, label)
00070 
00071 #endif
00072 
00073 
00074 #endif

Generated on Sat Oct 12 01:43:01 2002 for audiere by doxygen1.2.17