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