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 Write(const std::string& str) { Write(str.c_str()); }
00016 static void IncrementIndent() { ++indent_count; }
00017 static void DecrementIndent() { --indent_count; }
00018
00019 private:
00020 static void EnsureOpen();
00021 static void Close();
00022
00023 private:
00024 static FILE* handle;
00025 static int indent_count;
00026 };
00027
00028
00029 class Guard {
00030 public:
00031 Guard(const char* label)
00032 : m_label(label) {
00033 Write("+");
00034 Log::IncrementIndent();
00035 }
00036
00037 ~Guard() {
00038 Log::DecrementIndent();
00039 Write("-");
00040 }
00041
00042 void Write(const char* prefix) {
00043 Log::Write((prefix + m_label).c_str());
00044 }
00045
00046 private:
00047 std::string m_label;
00048 };
00049
00050 }
00051
00052
00053
00054
00055
00056 #if defined(ADR_FORCE_DEBUG) || defined(_DEBUG) || defined(DEBUG)
00057
00058 #define ADR_GUARD(label) Guard guard_obj__(label)
00059 #define ADR_LOG(label) (Log::Write(label))
00060 #define ADR_IF_DEBUG if (true)
00061
00062 #ifdef _MSC_VER
00063 #define ADR_ASSERT(condition, label) if (!(condition)) { __asm int 3 }
00064 #else // assume x86 gcc
00065 #define ADR_ASSERT(condition, label) assert(condition && label);
00066 #endif
00067
00068 #else
00069
00070 #define ADR_GUARD(label)
00071 #define ADR_LOG(label)
00072 #define ADR_IF_DEBUG if (false)
00073 #define ADR_ASSERT(condition, label)
00074
00075 #endif
00076
00077
00078 #endif