DEBUG_MACROS.hh
Go to the documentation of this file.
1 
4 #pragma once
5 #include "boca/generic/Debug.hh"
6 
7 // defined by cmake for debug runs
8 #ifndef NDEBUG
9 #define NOTIFICATION
10 #endif
11 // #define DEBUGGING
12 // #define INFORMATION
13 // #define NOTIFICATION
14 
15 
16 
17 // #define COMMA_IF_PARENS(...) ,
18 //
19 // #define LPAREN (
20 //
21 // #define EXPAND(...) __VA_ARGS__
22 //
23 // #define NORMAL(number) LOG ## number, impossible, LOG ## number
24 //
25 // #define SPECIAL LOG1, LOG0, LOG1,
26 //
27 // #define CHOOSE(...) EXPAND(LOG LPAREN __VA_ARGS__ COMMA_IF_PARENS __VA_ARGS__ COMMA_IF_PARENS __VA_ARGS__ (), NORMAL(4), NORMAL(3), NORMAL(2), SPECIAL))
28 //
29 // #define LOG(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg, ...) arg
30 
31 
32 
38 #define FILE_NAME ::boca::FileName(__FILE__)
39 
40 #define NAMESPACE_NAME ::boca::NameSpaceName(__PRETTY_FUNCTION__)
41 
42 #define CLASS_NAME ::boca::ClassName(__PRETTY_FUNCTION__)
43 
44 #define FUNCTION_NAME ::boca::FunctionName(__PRETTY_FUNCTION__)
45 
46 #define NAMES FILE_NAME, __LINE__, NAMESPACE_NAME, CLASS_NAME, FUNCTION_NAME
47 
48 #define VARIABLE(value) #value, value
49 
50 #define STREAM(value) ::boca::Stream2(VARIABLE(value))
51 
52 #define LOG0 ::boca::Log(NAMES)
53 
54 #define LOG1(value) ::boca::Log(NAMES, VARIABLE(value))
55 
56 #define LOG2(value, value2) ::boca::Log(NAMES, VARIABLE(value), VARIABLE(value2))
57 
58 #define LOG3(value, value2, value3) ::boca::Log(NAMES, VARIABLE(value), VARIABLE(value2), VARIABLE(value3))
59 
60 #define LOG4(value, value2, value3, value4) ::boca::Log(NAMES, VARIABLE(value), VARIABLE(value2), VARIABLE(value3), VARIABLE(value4))
61 
62 #define LOG5(value, value2, value3, value4, value5) ::boca::Log(NAMES, VARIABLE(value), VARIABLE(value2), VARIABLE(value3), VARIABLE(value4), VARIABLE(value5))
63 
64 #define LOG(arg0, arg1, arg2, arg3, arg4, arg5, arg, ...) arg
65 
66 #define CHOOSE(...) LOG(__VA_ARGS__, , LOG5, LOG4, LOG3, LOG2, LOG1, )
67 
68 #define ALIVE(...) CHOOSE(__VA_ARGS__)(__VA_ARGS__)
69 
70 #define DEAD(...) do { if (0) ALIVE(__VA_ARGS__); } while (0)
71 
72 #define DEAD0 do { if (0) LOG0; } while (0)
73 
74 #define ERROR(...) ALIVE(__VA_ARGS__)
75 #define ERROR0 LOG0
76 
77 #if defined(DETAILED)
78 #define DETAIL(...) ALIVE(__VA_ARGS__)
79 #define DETAIL0 LOG0
80 #else
81 #define DETAIL(...) DEAD(__VA_ARGS__)
82 #define DETAIL0 DEAD0
83 #endif
84 
85 #if defined(DETAILED) || defined(DEBUGGING)
86 #define DEBUG(...) ALIVE(__VA_ARGS__)
87 #define DEBUG0 LOG0
88 #else
89 #define DEBUG(...) DEAD(__VA_ARGS__)
90 #define DEBUG0 DEAD0
91 #endif
92 
93 #if defined(DETAILED) || defined(DEBUGGING) || defined(INFORMATION)
94 #define INFO(...) ALIVE(__VA_ARGS__)
95 #define INFO0 LOG0
96 #else
97 #define INFO(...) DEAD(__VA_ARGS__)
98 #define INFO0 DEAD0
99 #endif
100 
101 #if defined(DETAILED) || defined(DEBUGGING) || defined(INFORMATION) || defined(NOTIFICATION)
102 #define NOTE(...) ALIVE(__VA_ARGS__)
103 #define NOTE0 LOG0
104 #else
105 #define NOTE(...) DEAD(__VA_ARGS__)
106 #define NOTE0 DEAD0
107 #endif
108 
109 #define CHECK(condition, ...) if(!(condition)) { ERROR("Check failed", __VA_ARGS__); }
110 #define DEBUG_CHECK(condition, ...) if(!(condition)) { DEBUG(__VA_ARGS__); }
111 
112 #define DEFAULT_1(condition) default : ERROR("Switch Default", condition); break;
113 #define DEFAULT_2(condition, value) default : ERROR("Switch Default", condition); return value;
114 
115 #define DEFAULT_ARGUMENTS(arg1, arg2, arg, ...) arg
116 #define DEFAULT_CHOOSE(...) DEFAULT_ARGUMENTS(__VA_ARGS__, DEFAULT_2, DEFAULT_1, )
117 
118 #define DEFAULT(...) DEFAULT_CHOOSE(__VA_ARGS__)(__VA_ARGS__)
119 
120 // #include "boca/Logging.hh"
121 
122 // #define HAS_ARGS_IMPL2(_1, _2, _3, N, ...) N
123 // #define HAS_ARGS_SOURCE() MULTI, MULTI, ONE, ERROR
124 //
125 // #define HAS_ARGS_IMPL(...) HAS_ARGS_IMPL2(__VA_ARGS__)
126 // #define HAS_ARGS(...) HAS_ARGS_IMPL(__VA_ARGS__, HAS_ARGS_SOURCE())
127 //
128 // #define MACRO_ONE(x) ONE_ARG: x
129 // #define MACRO_MULTI(...) MULTI_ARG: __VA_ARGS__
130 //
131 // #define DISAMBIGUATE2(args, ...) MACRO_ ## args (__VA_ARGS__)
132 // #define DISAMBIGUATE(args, ...) DISAMBIGUATE2(args, __VA_ARGS__)
133 // #define ERROR(...) DISAMBIGUATE(HAS_ARGS(__VA_ARGS__), __VA_ARGS__)
134 
135 /*
136  * @}
137  */