MonteCarloLogger.h 1.33 KB
Newer Older
1
2
3
4
5
#ifndef MLMC__MULTILEVELMONTECARLO__HPP
#define MLMC__MULTILEVELMONTECARLO__HPP

#include "m++.h"

niklas.baumgarten's avatar
..    
niklas.baumgarten committed
6

7
8
class IndentedLogger {
    static IndentedLogger *instance;
9

10
11
    string indent;
    string innerIndent;
12

13
    const string defaultIndent = "   ";
14

15
    vector<Date> timestamps;
16

17
18
    IndentedLogger() {
        indent = "";
19
20
21
    }

public:
22
23
24
25
    static IndentedLogger *GetInstance() {
        if (!instance)
            instance = new IndentedLogger;
        return instance;
26
27
    }

28
29
    int DecreaseIndent() {
        indent = indent.erase(0, defaultIndent.length());
30
31
    }

32
33
    void IncreaseIndent() {
        indent = indent.append(defaultIndent);
34
    }
35

36
37
    string GetIndent() {
        return indent;
38
39
    }

40
    void StartMethod(const string& msg, int verbose) {
41
        Date start;
42
43
44
        timestamps.push_back(start);
        vout (1) << indent << "<" << msg << ">" << endl;
        IncreaseIndent();
45
46
    }

47
48
49
50
    void EndMethod(int verbose) {
        DecreaseIndent();
        vout (1) << indent << "<End after " << Date() - timestamps.back() << ">" << endl;
        timestamps.erase(timestamps.end());
51
52
    }

53
54
    void InnerMsg(const string& msg, int verbose) {
        vout (1) << indent << msg << endl;
55
56
    }

57
58
    void LogMsgFlush(const string &msg, int verbose) {
        vout(1) << "\r" << indent << msg << flush;
59
60
61
    }
};

62
#endif //MLMC__MULTILEVELMONTECARLO__HPP