-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkstation.cpp
90 lines (78 loc) · 1.68 KB
/
Workstation.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
// Author: Kathleen Monks
// Purpose: Final Project for Seneca's OOP345
// Date of completion: 2021-11-27
// ==========================================
#include <iostream>
#include <algorithm>
#include "Workstation.h"
using namespace std;
namespace sdds
{
// global queues
std::deque<CustomerOrder> pending;
std::deque<CustomerOrder> completed;
std::deque<CustomerOrder> incomplete;
void Workstation::fill(std::ostream& os)
{
if (!m_orders.empty())
{
m_orders.front().fillItem(*this, os);
}
}
bool Workstation::attemptToMoveOrder()
{
bool isMoved{ false };
if (!m_orders.empty()) // ensure there are current orders
{
if (m_orders.front().isItemFilled(this->getItemName()) || this->getQuantity() == 0)
{
if (m_pNextStation)
{
*m_pNextStation += move(m_orders.front());
}
else if (m_orders.front().isFilled())
{
completed.push_back(move(m_orders.front()));
}
else
{
incomplete.push_back(move(m_orders.front()));
}
m_orders.pop_front();
isMoved = true;
}
}
return isMoved;
}
void Workstation::setNextStation(Workstation* station = nullptr)
{
m_pNextStation = station;
}
Workstation* Workstation::getNextStation() const
{
return m_pNextStation;
}
void Workstation::display(std::ostream& os) const
{
if (m_pNextStation)
{
// this station item
os << getItemName();
os << " --> ";
// next station item
os << m_pNextStation->getItemName();
}
else
{
// last station item
os << getItemName();
os << " --> End of Line";
}
os << endl;
}
Workstation& Workstation::operator+=(CustomerOrder&& newOrder)
{
m_orders.push_back(move(newOrder));
return *this;
}
}