summaryrefslogtreecommitdiff
path: root/src/debug.cpp
blob: 8a0d1f3cbf4c7743e14d20ae5caceaed80e05b5c (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
49
50
51
52
/*
 * MRustC - Mutabah's Rust Compiler
 * - By John Hodge (Mutabah/thePowersGang)
 *
 * debug.cpp
 * - Debug printing (with indenting)
 */
#include <debug.hpp>

TraceLog::TraceLog(const char* tag, ::std::function<void(::std::ostream&)> info_cb, ::std::function<void(::std::ostream&)> ret):
    m_tag(tag),
    m_ret(ret)
{
    if(debug_enabled() && m_tag) {
        auto& os = debug_output(g_debug_indent_level, m_tag);
        os << ">> (";
        info_cb(os);
        os << ")" << ::std::endl;
    }
    INDENT();
}
TraceLog::TraceLog(const char* tag, ::std::function<void(::std::ostream&)> info_cb):
    m_tag(tag),
    m_ret([](const auto&){})
{
    if(debug_enabled() && m_tag) {
        auto& os = debug_output(g_debug_indent_level, m_tag);
        os << ">> (";
        info_cb(os);
        os << ")" << ::std::endl;
    }
    INDENT();
}
TraceLog::TraceLog(const char* tag):
    m_tag(tag),
    m_ret([](const auto&){})
{
    if(debug_enabled() && m_tag) {
        auto& os = debug_output(g_debug_indent_level, m_tag);
        os << ">>" << ::std::endl;
    }
    INDENT();
}
TraceLog::~TraceLog() {
    UNINDENT();
    if(debug_enabled() && m_tag) {
        auto& os = debug_output(g_debug_indent_level, m_tag);
        os << "<< (";
        m_ret(os);
        os << ")" << ::std::endl;
    }
}