aboutsummaryrefslogtreecommitdiff
path: root/src/debugspew.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/debugspew.hpp')
-rw-r--r--src/debugspew.hpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/debugspew.hpp b/src/debugspew.hpp
new file mode 100644
index 0000000..1eb5556
--- /dev/null
+++ b/src/debugspew.hpp
@@ -0,0 +1,60 @@
1#pragma once
2
3#include "lanesconf.h"
4#include "universe.hpp"
5
6// #################################################################################################
7
8#if USE_DEBUG_SPEW()
9
10class DebugSpewIndentScope
11{
12 private:
13 Universe* const U{};
14
15 public:
16 static std::string_view 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
26 ~DebugSpewIndentScope()
27 {
28 if (U) {
29 U->debugspewIndentDepth.fetch_sub(1, std::memory_order_relaxed);
30 }
31 }
32};
33
34// #################################################################################################
35
36inline std::string_view DebugSpewIndent(Universe const* const U_)
37{
38 return DebugSpewIndentScope::debugspew_indent.substr(0, static_cast<size_t>(U_->debugspewIndentDepth.load(std::memory_order_relaxed)));
39}
40
41inline auto& DebugSpew(Universe const* const U_)
42{
43 if (!U_) {
44 return std::cerr;
45 }
46 return std::cerr << DebugSpewIndent(U_) << " ";
47}
48#define DEBUGSPEW_CODE(_code) _code
49#define DEBUGSPEW_OR_NOT(a_, b_) a_
50#define DEBUGSPEW_PARAM_COMMA(param_) param_,
51#define DEBUGSPEW_COMMA_PARAM(param_) , param_
52
53#else // USE_DEBUG_SPEW()
54
55#define DEBUGSPEW_CODE(_code)
56#define DEBUGSPEW_OR_NOT(a_, b_) b_
57#define DEBUGSPEW_PARAM_COMMA(param_)
58#define DEBUGSPEW_COMMA_PARAM(param_)
59
60#endif // USE_DEBUG_SPEW()