-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLineManager.cpp
85 lines (71 loc) · 2.17 KB
/
LineManager.cpp
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
//Name: Chaoyi Wu
// Seneca Student ID: 154330179
// Seneca email: [email protected]
// Date of completion: Nov. 29th
//
// I confirm that the content of this file is created by me,
// with the exception of the parts provided to me by my professor.
#include <fstream>
#include <iostream>
#include "LineManager.h"
#include "Utilities.h"
LineManager::LineManager(std::string filename, std::vector<Task*>& allTasks, std::vector<CustomerOrder>& allOrders) {
std::ifstream f (filename);
Utilities utility;
utility.setDelimiter('|');
while (f.good()) {
bool more = true;
size_t nextPos = 0;
std::string line;
std::getline(f, line);
std::string token1 = utility.extractToken(line, nextPos, more);
if (more) {
std::string token2 = utility.extractToken(line, nextPos, more);
for (size_t i = 0; i < allTasks.size(); i++) {
if (allTasks[i]->getName() == token1) {
for (size_t j = 0; j < allTasks.size(); j++) {
if (allTasks[j]->getName() == token2) {
allTasks[i]->setNextTask(*allTasks[j]);
break;
}
}
}
}
}
}
for (size_t i = 0; i < allOrders.size(); i++) {
ToBeFilled.push_front(std::move(allOrders[i]));
}
m_cntCustomerOrder = ToBeFilled.size();
for (size_t i = 0; i < allTasks.size(); i++) {
AssemblyLine.push_back(allTasks[i]);
}
}
bool LineManager::run(std::ostream& os) {
if (!ToBeFilled.empty()) {
// beginning of AssemblyLine (PowerSupply)
*AssemblyLine[4] += std::move(ToBeFilled.back());
ToBeFilled.pop_back();
}
for (size_t i = 0; i < AssemblyLine.size(); i++) {
AssemblyLine[i]->runProcess(os);
}
for (size_t i = 0; i < AssemblyLine.size(); i++) {
if (AssemblyLine[i]->moveTask()) {
CustomerOrder temp;
AssemblyLine[i]->getCompleted(temp);
Completed.push_front(std::move(temp));
}
}
return m_cntCustomerOrder == Completed.size();
}
void LineManager::displayCompleted(std::ostream& os) const {
for (int i = Completed.size()-1; i >= 0; i--) {
Completed[i].display(os);
}
}
void LineManager::validateTasks() const {
for (size_t i = 0; i < AssemblyLine.size(); i++) {
AssemblyLine[i]->validate(std::cout);
}
}