summaryrefslogtreecommitdiff
path: root/competition/multilog.h
blob: ba0ff4de5d891c03d7ab5bf26451c2c84d4efa3a (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
#pragma once

#include <vector>
#include <string_view>
#include <mutex>

using namespace std;


// Access is thread-safe
class MultiLog {
	struct Item {
		int id;
		string line;
		bool complete = false;

		Item();
	};

	mutex mut;
	vector<Item> items;

	// Methods assume mutex is taken.
	size_t findId(int id);
	void redrawLine(size_t idx);

public:
	// Returns id of new item
	int add(const string_view prefix);
	void append(int id, const string_view text);
	void complete(int id);
};