-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask.cpp
73 lines (60 loc) · 1.49 KB
/
Task.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
//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 <iostream>
#include "Task.h"
Task::Task(const std::string& record) : Item(record){
m_pNextTask = nullptr;
}
void Task::runProcess(std::ostream& os) {
if (!m_orders.empty()) {
if (!m_orders.back().getItemFillState(Item::getName())) {
m_orders.back().fillItem(*this, os);
}
}
}
bool Task::moveTask() {
if (!m_orders.empty()) {
if (m_orders.back().getItemFillState(Item::getName())) {
// moves the last CustomerOrder in the queue to the next task
if (m_pNextTask != nullptr) {
*m_pNextTask += (std::move(m_orders.back()));
m_orders.pop_back();
}
else {
return true;
}
}
}
return false;
}
void Task::setNextTask(Task& task) {
m_pNextTask = &task;
}
bool Task::getCompleted(CustomerOrder& co) {
bool result = false;
if (!m_orders.empty()) {
co = std::move(m_orders.back());
m_orders.pop_back();
result = true;
}
return result;
}
void Task::validate(std::ostream& os) {
os << Item::getName();
if (m_pNextTask != nullptr) {
os << " --> " << m_pNextTask->getName();
}
else {
os << " --> END OF LINE";
}
os << std::endl;
}
Task& Task::operator+=(CustomerOrder&& co) {
m_orders.push_front(std::move(co));
return *this;
}