-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.h
57 lines (38 loc) · 1.15 KB
/
Logger.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
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef BASM_LOGGER_H
#define BASM_LOGGER_H
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <vector>
using std::pair;
using std::string;
using std::priority_queue;
using std::map;
class Logger {
public:
struct LogInfo {
int raw, col, word_size;
string msg;
LogInfo() = default;
LogInfo(pair<int,int> loc, int word_size, string msg)
: raw(loc.first), col(loc.second), word_size(word_size), msg(std::move(msg)) {}
bool operator>(const LogInfo &other) const {
if (raw == other.raw) return col > other.col;
return raw > other.raw;
}
};
void set_source(const string& name);
void log_error(pair<int, int> loc, int word_size, const string &msg);
void log_error(const LogInfo &log_info);
void register_line(int line_num, const string &line);
void flush();
bool has_error();
private:
string source_name;
priority_queue<LogInfo, std::vector<LogInfo>, std::greater<>> buffer;
map<int, string> line_map;
static string indent_by_count(int count);
static string tilde(int count);
};
#endif //BASM_LOGGER_H