-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathms3.cpp
182 lines (155 loc) · 5.15 KB
/
ms3.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
173
174
175
176
177
178
179
180
181
182
// Final Project
// Milestone 3
// ms3_prof.cpp
// Winter 2021
// Chris Szalwinski
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "Station.h"
#include "Station.h"
#include "Workstation.h"
#include "Workstation.h"
#include "CustomerOrder.h"
#include "CustomerOrder.h"
#include "Utilities.h"
#include "Utilities.h"
#include "LineManager.h"
#include "LineManager.h"
using namespace std;
using namespace sdds;
template<typename T>
static void loadFromFile(const char*, vector<T>&);
template<typename T>
static void loadFromFile(const char*, vector<T*>&);
int main(int argc, char** argv)
{
cout << "Command Line: " << argv[0];
for (int i = 1; i < argc; i++)
cout << " " << argv[i];
cout << endl << endl;
if (argc != 5) {
cerr << "ERROR: Incorrect number of arguments\n";
return 1;
}
vector<Workstation*> theStations;
vector<CustomerOrder> theOrders;
try {
Utilities::setDelimiter(',');
loadFromFile(argv[1], theStations);
Utilities::setDelimiter('|');
loadFromFile(argv[2], theStations);
cout << "========================================" << endl;
cout << "= Stations (summary) =" << endl;
cout << "========================================" << endl;
for (const auto* station : theStations)
station->Station::display(cout, false);
cout << endl << endl;
cout << "========================================" << endl;
cout << "= Stations (full) =" << endl;
cout << "========================================" << endl;
for (const auto* station : theStations)
station->Station::display(cout, true);
cout << endl << endl;
//Select an object and verify all the functionality it working
cout << "========================================" << endl;
cout << "= Manual Validation =" << endl;
cout << "========================================" << endl;
cout << "getItemName(): " << theStations[0]->getItemName() << endl;
cout << "getNextSerialNumber(): " << theStations[0]->getNextSerialNumber() << endl;
cout << "getNextSerialNumber(): " << theStations[0]->getNextSerialNumber() << endl;
cout << "getQuantity(): " << theStations[0]->getQuantity() << endl;
theStations[0]->updateQuantity();
cout << "getQuantity(): " << theStations[0]->getQuantity() << endl;
cout << endl << endl;
loadFromFile<CustomerOrder>(argv[3], theOrders);
cout << "========================================" << endl;
cout << "= Orders =" << endl;
cout << "========================================" << endl;
for (auto& order : theOrders) {
order.display(std::cout);
pending.push_back(std::move(order));
}
cout << endl << endl;
cout << "========================================" << endl;
cout << "= Display Stations (loaded) =" << endl;
cout << "========================================" << endl;
LineManager lm(argv[4], theStations);
lm.display(cout);
cout << endl << endl;
cout << "========================================" << endl;
cout << "= Display Stations (ordered) =" << endl;
cout << "========================================" << endl;
lm.linkStations();
lm.display(cout);
cout << endl << endl;
cout << "========================================" << endl;
cout << "= Filling Orders =" << endl;
cout << "========================================" << endl;
//run the assembly line until all orders processed
while (!lm.run(cout));
cout << endl << endl;
}
catch (const string& msg) {
cerr << msg << '\n';
return 2;
}
cout << "========================================" << endl;
cout << "= Processed Orders (complete) =" << endl;
cout << "========================================" << endl;
for (const auto& o : completed)
o.display(cout);
cout << endl << endl;
cout << "========================================" << endl;
cout << "= Processed Orders (incomplete) =" << endl;
cout << "========================================" << endl;
for (const auto& o : incomplete)
o.display(cout);
cout << endl << endl;
cout << "========================================" << endl;
cout << "= Inventory (full) =" << endl;
cout << "========================================" << endl;
for (const Station* theItem : theStations)
theItem->display(cout, true);
cout << endl;
// cleanup
for (auto station : theStations)
delete station;
return 0;
}
template<typename T>
static void loadFromFile(const char* filename, vector<T>& theCollection)
{
if (!filename) {
throw string("ERROR: No filename provided.");
}
ifstream file(filename);
if (!file)
throw string("Unable to open [") + filename + "] file.";
string record;
while (!file.eof())
{
std::getline(file, record);
T elem(record);
theCollection.push_back(std::move(elem));
}
file.close();
}
template<typename T>
static void loadFromFile(const char* filename, vector<T*>& theCollection)
{
if (!filename) {
throw string("ERROR: No filename provided.");
}
ifstream file(filename);
if (!file)
throw string("Unable to open [") + filename + "] file.";
string record;
while (!file.eof())
{
std::getline(file, record);
theCollection.push_back(new T(record));
}
file.close();
}