-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.h
124 lines (100 loc) · 3.59 KB
/
debug.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef debug_h
#define debug_h
#include <iostream>
#include "traits.h"
__BEGIN_API
class Debug
{
public:
template<typename T>
Debug & operator<<(T p) { std::cout << p; return *this; }
struct Begl {};
struct Err {};
Debug & operator<<(const Begl & begl) { return *this; }
Debug & operator<<(const Err & err) { _error = true; return *this; }
private:
volatile bool _error;
public:
static Begl begl;
static Err error;
};
class Null_Debug
{
public:
template<typename T>
Null_Debug & operator<<(const T & o) { return *this; }
template<typename T>
Null_Debug & operator<<(const T * o) { return *this; }
};
template<bool debugged>
class Select_Debug: public Debug {};
template<>
class Select_Debug<false>: public Null_Debug {};
// Error
enum Debug_Error {ERR = 1};
template<typename T>
inline Select_Debug<(Traits<T>::debugged && Traits<Debug>::error)>
db(Debug_Error l)
{
Select_Debug<(Traits<T>::debugged && Traits<Debug>::error)>() << Debug::begl;
Select_Debug<(Traits<T>::debugged && Traits<Debug>::error)>() << Debug::error;
return Select_Debug<(Traits<T>::debugged && Traits<Debug>::error)>();
}
template<typename T1, typename T2>
inline Select_Debug<((Traits<T1>::debugged || Traits<T2>::debugged) && Traits<Debug>::error)>
db(Debug_Error l)
{
Select_Debug<((Traits<T1>::debugged || Traits<T2>::debugged) && Traits<Debug>::error)>() << Debug::begl;
Select_Debug<((Traits<T1>::debugged || Traits<T2>::debugged) && Traits<Debug>::error)>() << Debug::error;
return Select_Debug<((Traits<T1>::debugged || Traits<T2>::debugged) && Traits<Debug>::error)>();
}
// Warning
enum Debug_Warning {WRN = 2};
template<typename T>
inline Select_Debug<(Traits<T>::debugged && Traits<Debug>::warning)>
db(Debug_Warning l)
{
Select_Debug<(Traits<T>::debugged && Traits<Debug>::warning)>() << Debug::begl;
return Select_Debug<(Traits<T>::debugged && Traits<Debug>::warning)>();
}
template<typename T1, typename T2>
inline Select_Debug<((Traits<T1>::debugged || Traits<T2>::debugged) && Traits<Debug>::warning)>
db(Debug_Warning l)
{
Select_Debug<((Traits<T1>::debugged || Traits<T2>::debugged) && Traits<Debug>::warning)>() << Debug::begl;
return Select_Debug<((Traits<T1>::debugged || Traits<T2>::debugged) && Traits<Debug>::warning)>();
}
// Info
enum Debug_Info {INF = 3};
template<typename T>
inline Select_Debug<(Traits<T>::debugged && Traits<Debug>::info)>
db(Debug_Info l)
{
Select_Debug<(Traits<T>::debugged && Traits<Debug>::info)>() << Debug::begl;
return Select_Debug<(Traits<T>::debugged && Traits<Debug>::info)>();
}
template<typename T1, typename T2>
inline Select_Debug<((Traits<T1>::debugged || Traits<T2>::debugged) && Traits<Debug>::info)>
db(Debug_Info l)
{
Select_Debug<((Traits<T1>::debugged || Traits<T2>::debugged) && Traits<Debug>::info)>() << Debug::begl;
return Select_Debug<((Traits<T1>::debugged || Traits<T2>::debugged) && Traits<Debug>::info)>();
}
// Trace
enum Debug_Trace {TRC = 4};
template<typename T>
inline Select_Debug<(Traits<T>::debugged && Traits<Debug>::trace)>
db(Debug_Trace l)
{
Select_Debug<(Traits<T>::debugged && Traits<Debug>::trace)>() << Debug::begl;
return Select_Debug<(Traits<T>::debugged && Traits<Debug>::trace)>();
}
template<typename T1, typename T2>
inline Select_Debug<((Traits<T1>::debugged || Traits<T2>::debugged) && Traits<Debug>::trace)>
db(Debug_Trace l)
{
Select_Debug<((Traits<T1>::debugged || Traits<T2>::debugged) && Traits<Debug>::trace)>() << Debug::begl;
return Select_Debug<((Traits<T1>::debugged || Traits<T2>::debugged) && Traits<Debug>::trace)>();
}
__END_API
#endif