aboutsummaryrefslogtreecommitdiff
path: root/src/debugspew.h
blob: 0c3e14aa85baf25f977d965cf1ea6227e03c988b (plain)
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
#pragma once

#include "lanesconf.h"
#include "universe.h"

// #################################################################################################

#if USE_DEBUG_SPEW()

class DebugSpewIndentScope
{
    private:
    Universe* const U;

    public:
    static char const* const debugspew_indent;

    DebugSpewIndentScope(Universe* U_)
    : U{ U_ }
    {
        if (U)
            U->debugspewIndentDepth.fetch_add(1, std::memory_order_relaxed);
    }

    ~DebugSpewIndentScope()
    {
        if (U)
            U->debugspewIndentDepth.fetch_sub(1, std::memory_order_relaxed);
    }
};

// #################################################################################################

#define INDENT_BEGIN "%.*s "
#define INDENT_END(U_) , (U_ ? U_->debugspewIndentDepth.load(std::memory_order_relaxed) : 0), DebugSpewIndentScope::debugspew_indent
#define DEBUGSPEW_CODE(_code) _code
#define DEBUGSPEW_OR_NOT(a_, b_) a_
#define DEBUGSPEW_PARAM_COMMA(param_) param_,
#define DEBUGSPEW_COMMA_PARAM(param_) , param_

#else // USE_DEBUG_SPEW()

#define DEBUGSPEW_CODE(_code)
#define DEBUGSPEW_OR_NOT(a_, b_) b_
#define DEBUGSPEW_PARAM_COMMA(param_)
#define DEBUGSPEW_COMMA_PARAM(param_)

#endif // USE_DEBUG_SPEW()