blob: 2fec0474b6da7e5dfefd37c378520b317b718e6f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#ifndef DEBUG_H
#define DEBUG_H
#include <assert.h>
#include <stdio.h>
#include <string>
namespace audiere {
class Log {
public:
static void Write(const char* str);
static void Write(const std::string& str) { Write(str.c_str()); }
static void IncrementIndent() { ++indent_count; }
static void DecrementIndent() { --indent_count; }
private:
static void EnsureOpen();
static void Close();
private:
static FILE* handle;
static int indent_count;
};
class Guard {
public:
Guard(const char* label)
: m_label(label) {
Write("+");
Log::IncrementIndent();
}
~Guard() {
Log::DecrementIndent();
Write("-");
}
void Write(const char* prefix) {
Log::Write((prefix + m_label).c_str());
}
private:
std::string m_label;
};
}
//#define ADR_FORCE_DEBUG
#if defined(ADR_FORCE_DEBUG)
#define ADR_GUARD(label) Guard guard_obj__(label)
#define ADR_LOG(label) (Log::Write(label))
#define ADR_IF_DEBUG if (true)
#ifdef _MSC_VER
#define ADR_ASSERT(condition, label) if (!(condition)) { __asm int 3 }
#else // assume x86 gcc
#define ADR_ASSERT(condition, label) assert(condition && label);
#endif
#else
#define ADR_GUARD(label)
#define ADR_LOG(label)
#define ADR_IF_DEBUG if (false)
#define ADR_ASSERT(condition, label)
#endif
#endif
|