forked from miki151/keeperrl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.cpp
More file actions
86 lines (77 loc) · 2.03 KB
/
debug.cpp
File metadata and controls
86 lines (77 loc) · 2.03 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "stdafx.h"
#include "debug.h"
#include "util.h"
using namespace std;
Debug::Debug(DebugType t, const string& msg, int line)
: out((string[]) { "INFO ", "FATAL "}[t] + msg + ":" + convertToString(line) + " "), type(t) {
#ifdef RELEASE
if (t == DebugType::FATAL)
throw out;
#endif
}
static ofstream output;
void Debug::init() {
output.open("log.out");
}
void Debug::add(const string& a) {
out += a;
}
Debug::~Debug() {
if (type == FATAL) {
output << out << endl;
output.flush();
throw out;
} else {
#ifndef RELEASE
output << out << endl;
output.flush();
#endif
}
}
Debug& Debug::operator <<(const string& msg) {
add(msg);
return *this;
}
Debug& Debug::operator <<(const int msg) {
add(convertToString(msg));
return *this;
}
Debug& Debug::operator <<(const char msg) {
add(convertToString(msg));
return *this;
}
Debug& Debug::operator <<(const double msg) {
add(convertToString(msg));
return *this;
}
template<class T>
Debug& Debug::operator<<(const vector<T>& container){
(*this) << "{";
for (const T& elem : container) {
(*this) << elem << ",";
}
(*this) << "}";
return *this;
}
template<class T>
Debug& Debug::operator<<(const vector<vector<T> >& container){
(*this) << "{";
for (int i : Range(container[0].size())) {
for (int j : Range(container.size())) {
(*this) << container[j][i] << ",";
}
(*this) << '\n';
}
(*this) << "}";
return *this;
}
template Debug& Debug::operator <<(const vector<string>&);
template Debug& Debug::operator <<(const vector<int>&);
template Debug& Debug::operator <<(const vector<Vec2>&);
template Debug& Debug::operator <<(const vector<double>&);
template Debug& Debug::operator <<(const vector<vector<double> >&);
template NoDebug& NoDebug::operator <<(const vector<string>&);
template NoDebug& NoDebug::operator <<(const vector<int>&);
template NoDebug& NoDebug::operator <<(const vector<Vec2>&);
template NoDebug& NoDebug::operator <<(const vector<double>&);
template NoDebug& NoDebug::operator <<(const vector<vector<double> >&);