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