-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.h
44 lines (36 loc) · 876 Bytes
/
log.h
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
#ifndef LOG_H_
#define LOG_H_
#include <assert.h>
#include <fstream>
#include <string>
#include <iostream>
#define FILE_NAME "gamelog.txt"
class Log {
public:
static void init() {
outputFileStream.open(FILE_NAME, std::ofstream::out);
assert(outputFileStream.is_open());
}
static void closeLog() {
outputFileStream.close();
}
static std::ofstream outputFileStream;
/* set floating point precision */
static void precision(int precision) {
outputFileStream << std::fixed;
outputFileStream.precision(precision);
}
};
template <typename T>
Log& operator << (Log& log, const T& data) {
Log::outputFileStream << data;
Log::outputFileStream.flush();
return log;
}
template <typename T>
Log& operator << (Log& log, const T data[]) {
Log::outputFileStream << data;
Log::outputFileStream.flush();
return log;
}
#endif // LOG_H_