Repository navigation
Expand file tree
/
Copy pathCustomerOrder.cpp
More file actions
130 lines (124 loc) · 3.28 KB
/
Copy pathCustomerOrder.cpp
File metadata and controls
130 lines (124 loc) · 3.28 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
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
// Name:Enock lubega
// Seneca Student ID: 154192181
// Seneca email:elubega@myseneca.ca
// Date of completion:7/22/2021
//
// I confirm that I am the only author of this file
// and the content was created entirely by me.
#include "CustomerOrder.h"
namespace sdds {
size_t CustomerOrder::m_widthField = 0;
CustomerOrder::CustomerOrder()
{
m_name = "";
m_product = "";
m_cntItem = 0;
}
CustomerOrder::CustomerOrder(const std::string& line)
{
Utilities util;
size_t pos = 0u;
bool isMore = true;
std::string item = "";
m_name = util.extractToken(line, pos, isMore);
m_product = util.extractToken(line, pos, isMore);
m_cntItem = std::count(line.begin(), line.end(), util.getDelimiter()) - 1;
this->m_lstItem = new Item * [m_cntItem];
for(size_t i = 0; i < m_cntItem; i++) {
item = util.extractToken(line, pos, isMore);
m_lstItem[i] = new Item(item);
}
if (util.getFieldWidth() > m_widthField) {
m_widthField = util.getFieldWidth();
}
}
CustomerOrder::CustomerOrder(const CustomerOrder&)
{
throw std::string("Cannot make copies.");
}
CustomerOrder::CustomerOrder(CustomerOrder&& that) noexcept
{
*this = std::move(that);
}
CustomerOrder& CustomerOrder::operator=(CustomerOrder&& that) noexcept
{
if (this != &that) {
for (size_t i = 0; i < m_cntItem; i++)
delete m_lstItem[i];
delete[] m_lstItem;
m_lstItem = nullptr;
m_lstItem = that.m_lstItem;
m_name = that.m_name;
m_product = that.m_product;
m_cntItem = that.m_cntItem;
that.m_lstItem = nullptr;
that.m_name = "";
that.m_cntItem = 0u;
that.m_product = "";
}
return *this;
}
CustomerOrder::~CustomerOrder()
{
for (size_t i = 0; i < m_cntItem; i++)
delete m_lstItem[i];
delete[] m_lstItem;
m_lstItem = nullptr;
}
bool CustomerOrder::isFilled() const
{
bool isFilled = true;
for (size_t i = 0; i < m_cntItem; i++)
{
if (m_lstItem[i]->m_isFilled == false)
isFilled = false;
}
return isFilled;
}
bool CustomerOrder::isItemFilled(const std::string& itemName) const
{
bool isGood = true;
for (size_t i = 0; i < m_cntItem; i++)
{
if (m_lstItem[i]->m_itemName == itemName)
if (m_lstItem[i]->m_isFilled == false)
isGood = false;
}
return isGood;
}
void CustomerOrder::fillItem(Station& station, std::ostream& os)
{
for (size_t i = 0; i < m_cntItem; i++)
{
if (station.getItemName() == m_lstItem[i]->m_itemName)
{
if (station.getQuantity() > 0)
{
station.updateQuantity();
m_lstItem[i]->m_serialNumber = station.getNextSerialNumber();
m_lstItem[i]->m_isFilled = true;
os << " Filled " << m_name << ", "
<< m_product << " [" << station.getItemName() << "]" << std::endl;
}
else
{
os << " Unable to fill " << m_name << ", "
<< m_product << " [" << station.getItemName() << "]" << std::endl;
}
}
}
}
void CustomerOrder::display(std::ostream& os) const
{
os << m_name << " - " << m_product << std::endl;
for (size_t i = 0; i < m_cntItem; i++)
{
os << "[" <<std::right<< std::setw(6) << std::setfill('0') << m_lstItem[i]->m_serialNumber << "] " <<std::left;
os << std::setw(m_widthField) << std::setfill(' ') << m_lstItem[i]->m_itemName << " - ";
if (m_lstItem[i]->m_isFilled)
os << "FILLED";
else os << "TO BE FILLED";
os << std::endl;
}
}
}