-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomerOrder.cpp
More file actions
168 lines (141 loc) · 3.51 KB
/
Copy pathCustomerOrder.cpp
File metadata and controls
168 lines (141 loc) · 3.51 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
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
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
#include <iomanip>
#include "CustomerOrder.h"
#include "Utilities.h"
using namespace std;
namespace sdds
{
size_t CustomerOrder::m_widthField = 0u;
CustomerOrder::CustomerOrder(const std::string& str)
{
Utilities temp_utility{};
size_t pos = 0u;
bool more = false;
m_name = temp_utility.extractToken(str, pos, more); //Cornel B.
m_product = temp_utility.extractToken(str, pos, more); //1-Room Home Office
//Bed|Dresser|Office Chair|Desk|Bookcase|Bookcase|Filing Cabinet
m_cntItem = unsigned(std::count(str.begin()+pos, str.end(), temp_utility.getDelimiter())) + 1;
//for (size_t i = pos; i < str.length(); i++)
//{
// if (str[i] == temp_utility.getDelimiter())
// {
// m_cntItem++;
// }
//}
//m_cntItem++;
//Allocate
m_lstItem = new Item* [m_cntItem];
for (size_t i = 0; i < m_cntItem; i++)
{
const std::string& oneItem = temp_utility.extractToken(str, pos, more);
//Allocate
m_lstItem[i] = new Item(oneItem);
}
if (m_widthField < temp_utility.getFieldWidth())
{
m_widthField = temp_utility.getFieldWidth();
}
}
CustomerOrder& CustomerOrder::operator=(CustomerOrder&& other) noexcept
{
if (this != &other)
{
//cleanup
for (size_t i = 0; i < m_cntItem; i++)
{
delete m_lstItem[i];
}
this->m_name = other.m_name;
this->m_product = other.m_product;
this->m_lstItem = other.m_lstItem;
this->m_cntItem = other.m_cntItem;
other.m_name = {};
other.m_product = {};
other.m_lstItem = nullptr;
other.m_cntItem = 0u;
}
return *this;
}
CustomerOrder::~CustomerOrder()
{
for (size_t i = 0; i < m_cntItem; i++)
{
delete this->m_lstItem[i];
}
delete[] m_lstItem;
}
bool CustomerOrder::isFilled() const
{
bool check = true;
for (size_t i = 0; i < m_cntItem; i++)
{
if (m_lstItem[i]->m_isFilled == false)
{
check = false;
break;
}
}
return check;
}
bool CustomerOrder::isItemFilled(const std::string& itemName) const
{
bool check = true;
for (size_t i = 0; i < m_cntItem; i++)
{
if (m_lstItem[i]->m_itemName == itemName)
{
if (m_lstItem[i]->m_isFilled == false)
{
check = false;
break;
}
}
}
return check;
}
void CustomerOrder::fillItem(Station& station, std::ostream& os)
{
for (size_t i = 0; i < m_cntItem; i++)
{
if (m_lstItem[i]->m_itemName == station.getItemName())
{
if (station.getQuantity() >= 1)
{
station.updateQuantity();
m_lstItem[i]->m_serialNumber = station.getNextSerialNumber();
m_lstItem[i]->m_isFilled = true;
os << " Filled ";
}
else
{
os << " Unable to fill ";
}
os << m_name << ", " << m_product << " [" << station.getItemName() << "]" << endl;
}
}
}
void CustomerOrder::display(std::ostream& os) const
{
//CUSTOMER_NAME - PRODUCT
//[SERIAL] ITEM_NAME - STATUS
//[SERIAL] ITEM_NAME - STATUS
int width = 6;
os << m_name << " - " << m_product << endl;
for (size_t i = 0; i < m_cntItem; i++)
{
os << "[" << setw(width) << right << setfill('0') << m_lstItem[i]->m_serialNumber << "] " << setfill(' ') << left << setw(m_widthField) << m_lstItem[i]->m_itemName << " - ";
if (m_lstItem[i]->m_isFilled)
{
os << "FILLED" << endl;
}
else
{
os << "TO BE FILLED" << endl;
}
}
}
}