-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task.cpp
174 lines (122 loc) · 3.87 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Name:Badal Sarkar
// Seneca Student ID:137226189
// Seneca email:[email protected]
// Date of completion:December 1, 2019
//
// I confirm that I am the only author of this file
// and the content was created entirely by me.
#include<iostream>
#include "Task.h"
/*********************************************
custom constructor
parameter:a single record that holds information about item
action: instantiate item object
put m_pNextTask in safe state
**********************************************/
Task::Task(const std::string& record):Item(record)
{
//m_pNextTask is already in safe state
}
/***********************************************
runprocess function
parameter: 1. ostream as it will be passed to another function (fillItem)
steps: 1. check if the m_orders is empty or not. If not empty, get
the last element
2. check the fill status of the current task in the last element(customerOrder)
3. if it is not filled, fill it
*************************************************/
void Task::runProcess(std::ostream& os)
{
//step 1:
if(!m_orders.empty())
{
//step 2:
if(!m_orders.back().getItemFillState(getName()))
{
//step 3:
m_orders.back().fillItem(*this, os);
}
}
}
/*****************************************************
movetask function
steps: 1.check if m_orders is not empty
2. check if the fill status of the current task for the
last CustomerOrder in the m_orders is true(if false do nothing)
3. if true move the CustomerOrder to the m_pNextTask
as the first element of the m_orders(use operator+=)
4. return true (or false if m_orders is empty)
******************************************************/
bool Task::moveTask()
{
bool result {false};
//step 1:
if(!m_orders.empty())
{
//step 2:
if(m_orders.back().getItemFillState(this->getName()))
{
//step 3:
if(m_pNextTask!=nullptr){
(*m_pNextTask)+=std::move(m_orders.back());
m_orders.pop_back();
result=true;
}
}
}
return result;
}
/*************************************************************
setnexttask function
parameter: a reference to a Task object
step: assign the reference to m_pNextTask
**************************************************************/
void Task::setNextTask(Task& nextTask)
{
m_pNextTask=&nextTask;
}
/**************************************************************
getcompleted function
parameter: reference to CustomerOrder
steps: 1. check that m_orders is not empty
2. pop the last element from m_order
3. move the popped element to the parameter (CustomerOrder)
****************************************************************/
bool Task::getCompleted(CustomerOrder& completedOrder)
{
bool result {false};
if(!m_orders.empty())
{
if(m_orders.back().getOrderFillState()){
completedOrder=std::move(m_orders.back());
m_orders.pop_back();
result=true;
}
}
return result;
}
/**************************************************************
validate function
prints task name
**************************************************************/
void Task::validate(std::ostream& os)
{
if(m_pNextTask!=nullptr)
{
os<<getName()<<" --> "<<m_pNextTask->getName()<<std::endl;
}
else
{
os<<getName()<<" --> "<<"END OF LINE"<<std::endl;
}
}
/************************************************************
operator+= function
parameter: rvalue reference to CustomerOrder object
steps: 1. moves the parameter at the front of m_orders
************************************************************/
Task& Task::operator+=(CustomerOrder&& order)
{
m_orders.push_front(std::move(order));
return *this;
}