aboutsummaryrefslogtreecommitdiff
path: root/src/debugspew.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/debugspew.h')
-rw-r--r--src/debugspew.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/debugspew.h b/src/debugspew.h
new file mode 100644
index 0000000..0c3e14a
--- /dev/null
+++ b/src/debugspew.h
@@ -0,0 +1,48 @@
1#pragma once
2
3#include "lanesconf.h"
4#include "universe.h"
5
6// #################################################################################################
7
8#if USE_DEBUG_SPEW()
9
10class DebugSpewIndentScope
11{
12 private:
13 Universe* const U;
14
15 public:
16 static char const* const debugspew_indent;
17
18 DebugSpewIndentScope(Universe* U_)
19 : U{ U_ }
20 {
21 if (U)
22 U->debugspewIndentDepth.fetch_add(1, std::memory_order_relaxed);
23 }
24
25 ~DebugSpewIndentScope()
26 {
27 if (U)
28 U->debugspewIndentDepth.fetch_sub(1, std::memory_order_relaxed);
29 }
30};
31
32// #################################################################################################
33
34#define INDENT_BEGIN "%.*s "
35#define INDENT_END(U_) , (U_ ? U_->debugspewIndentDepth.load(std::memory_order_relaxed) : 0), DebugSpewIndentScope::debugspew_indent
36#define DEBUGSPEW_CODE(_code) _code
37#define DEBUGSPEW_OR_NOT(a_, b_) a_
38#define DEBUGSPEW_PARAM_COMMA(param_) param_,
39#define DEBUGSPEW_COMMA_PARAM(param_) , param_
40
41#else // USE_DEBUG_SPEW()
42
43#define DEBUGSPEW_CODE(_code)
44#define DEBUGSPEW_OR_NOT(a_, b_) b_
45#define DEBUGSPEW_PARAM_COMMA(param_)
46#define DEBUGSPEW_COMMA_PARAM(param_)
47
48#endif // USE_DEBUG_SPEW()