-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
40 lines (27 loc) · 783 Bytes
/
Copy pathutils.cpp
File metadata and controls
40 lines (27 loc) · 783 Bytes
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
#include "utils.h"
#include <sstream>
OrderInfo parseOrderInfo(const string& line) {
OrderInfo order;
stringstream ss(line);
string token;
getline(ss, order.timestamp, ',');
getline(ss, token, ',');
order.table_id = stoi(token);
getline(ss, order.item_name, ',');
getline(ss, order.category, ',');
getline(ss, token, ',');
order.price = stof(token);
return order;
}
void Buffer::push(OrderInfo info) {
std::lock_guard<std::mutex> lock(mtx);
q.push(std::move(info));
cv.notify_one();
}
bool Buffer::pop(OrderInfo& info) {
std::unique_lock<std::mutex> lock(mtx);
cv.wait(lock, [this] { return !q.empty(); });
info = std::move(q.front());
q.pop();
return true;
}