-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemProcessor.h
More file actions
76 lines (57 loc) · 1.52 KB
/
ItemProcessor.h
File metadata and controls
76 lines (57 loc) · 1.52 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
#include <thread>
#include <algorithm>
#include <map>
#include <string>
#include <mutex>
#include <iostream>
namespace ndtech {
template<typename ItemType>
struct ItemProcessor {
enum class WrappedTypeState {
Created,
Processing,
Processed
};
template<typename WrappedType, WrappedTypeState state>
struct ItemWrapper {
ItemType m_item;
ItemProcessor::WrappedTypeState m_wrappedTypeState;
ItemWrapper(ItemType item) :
m_item(std::move(item))
{
}
};
std::map<std::string, ItemType> m_itemsMap;
std::function<bool(ItemType&)> m_processingFunction;
std::thread m_processingThread;
bool m_shutdown = false;
std::mutex m_itemsMutex;
ItemProcessor(std::function<bool(ItemType&)> processingFunction) :
m_processingFunction(processingFunction),
m_processingThread(ItemProcessor::Run, this)
{
}
void Run() {
while (!m_shutdown) {
std::for_each(m_itemsMap.begin(), m_itemsMap.end(), [](ItemType& item) {
if (m_processingFunction(item)) {
m_itemsMap.erase(
std::remove_if(
m_itemsMap.begin(),
m_itemsMap.end(),
[](std::pair<std::string, ItemType> pair) {
std::cout << pair.second << std::endl;
}));
}
});
}
}
void AddItem(ItemType item) {
std::lock_guard lockGuard(m_itemsMutex);
//m_itemsMutex.
}
ItemType GetItem() {
}
};
}