-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineManager.cpp
More file actions
97 lines (83 loc) · 2.13 KB
/
Copy pathLineManager.cpp
File metadata and controls
97 lines (83 loc) · 2.13 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <string>
#include <fstream>
#include <algorithm>
#include "LineManager.h"
#include "Utilities.h"
namespace sdds
{
LineManager::LineManager(const std::string& file, const std::vector<Workstation*>& stations)
{
std::ifstream f(file);
Utilities ut;
bool more = false;
size_t pos = 0;
std::string str;
std::string item;
std::string nextItem;
if (!f)
{
throw std::string("Error: Unable to open file!");
}
else
{
Workstation* curStation{};
Workstation* nextStation{};
Workstation* firstStation{};
while (getline(f, str))
{
item = ut.extractToken(str, pos, more);
curStation = *std::find_if(stations.begin(), stations.end(), [&](Workstation* s) {
return s->getItemName() == item;
});
m_activeLine.push_back(curStation);
if (more != false)
{
nextItem = ut.extractToken(str, pos, more);
nextStation = *std::find_if(stations.begin(), stations.end(), [&](Workstation* s) {
return s->getItemName() == nextItem;
});
curStation->setNextStation(nextStation);
}
}
for_each(stations.begin(), stations.end(), [&](Workstation* s) {
firstStation = *std::find_if(stations.begin(), stations.end(), [&](Workstation* s) {
return s->getNextStation() == firstStation;
});
});
m_firstStation = firstStation;
}
f.close();
m_cntCustomerOrder = g_pending.size();
}
void LineManager::reorderStations()
{
Workstation* station = m_firstStation;
std::vector<Workstation*> reOrdered;
while (station)
{
reOrdered.push_back(station);
station = station->getNextStation();
}
m_activeLine = reOrdered;
}
bool LineManager::run(std::ostream& os)
{
static size_t count = 0u;
os << "Line Manager Iteration: " << ++count << std::endl;
if (!g_pending.empty())
{
*m_activeLine.front() += std::move(g_pending.front());
g_pending.pop_front();
}
for (auto& i : m_activeLine)
i->fill(os);
for (auto& i : m_activeLine)
i->attemptToMoveOrder();
return (g_completed.size() + g_incomplete.size() == m_cntCustomerOrder);
}
void LineManager::display(std::ostream& os) const
{
for (auto& i : m_activeLine)
i->display(os);
}
}