-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordle_buffer.h
40 lines (37 loc) · 877 Bytes
/
wordle_buffer.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
#pragma once
#include <iostream>
#include <mutex>
#include <sstream>
#include <string>
#include <map>
class WordleBuffer {
public:
void write(const std::string& str, size_t idx, bool newline=false) {
std::lock_guard<std::mutex> lck(m_mtx);
//*m_buf << str;
//m_str += str;
if (m_map.find(idx) == m_map.end()) {
if (newline) {
m_map[idx] = str + "\n";
} else {
m_map[idx] = str;
}
} else {
if (newline) {
m_map[idx] += str + "\n";
} else {
m_map[idx] += str;
}
}
}
std::string read() {
std::string s;
for (auto& i : m_map) {
s += i.second;
}
return s;
}
private:
std::map<size_t, std::string> m_map;
std::mutex m_mtx{};
};