-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
executable file
·95 lines (70 loc) · 2.91 KB
/
main.cc
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
#include <iostream>
#include <fstream>
#include <uPRNG.h>
#include "convert.h"
#include "config.h"
#include "bottlingplant.h"
#include "printer.h"
#include "vendingmachine.h"
#include "student.h"
#include "watcardoffice.h"
#include "nameserver.h"
#include "groupoff.h"
#include "bank.h"
#include "parent.h"
int main (int argc, char* argv[]) {
const char * configFileName = "soda.config";
int processors = 1;
try {
switch (argc) {
case 4: if ( strcmp( argv[3], "d" ) != 0 ) { // default ?
processors = convert( argv[3] ); if ( processors <= 0 ) throw 1; }
case 3: if ( strcmp( argv[2], "d" ) != 0 ) { // default ?
int seed = convert( argv[2] ); if ( seed <= 0 ) throw 1; else set_seed(seed); }
case 2:
if ( strcmp( argv[1], "d" ) != 0 ) { // default ?
configFileName = argv[1]; }
case 1: break; // use all defaults
default: throw 1;
}
} catch (...) {
std::cerr << "Usage: " << argv[0] << " soda [ config-file | 'd' [ seed (> 0) | 'd' [ processors (> 0) | 'd' ] ] ]" << std::endl;
exit( EXIT_FAILURE );
}
uProcessor p[processors - 1] __attribute__(( unused )); // create more kernel thread
ConfigParms configParms;
processConfigFile(configFileName, configParms);
std::ofstream test_out{"t.out"};
Printer printer{ configParms.numStudents, configParms.numVendingMachines, configParms.numCouriers };
Bank * bank = new Bank{configParms.numStudents};
WATCardOffice * watCardOffice = new WATCardOffice{printer, *bank, configParms.numCouriers};
NameServer nameServer{printer, configParms.numVendingMachines, configParms.numStudents};
Groupoff groupoff{printer, configParms.numStudents, configParms.sodaCost, configParms.groupoffDelay };
BottlingPlant * bottlingPlant = new BottlingPlant{
printer,
nameServer,
configParms.numVendingMachines,
configParms.maxShippedPerFlavour,
configParms.maxStockPerFlavour,
configParms.timeBetweenShipments
};
Parent * parent = new Parent{printer, *bank, configParms.numStudents, configParms.parentalDelay};
std::vector<Student*> students;
for (int i = 0; i < configParms.numStudents; ++i) {
students.emplace_back(new Student{printer, nameServer, *watCardOffice, groupoff, i, configParms.maxPurchases});
}
std::vector<VendingMachine *> vendingMachines;
for (int i = 0; i < configParms.numVendingMachines; ++i) {
vendingMachines.emplace_back(new VendingMachine{printer, nameServer, i, configParms.sodaCost});
}
for (int i = 0; i < configParms.numStudents; ++i) {
delete students[i];
}
delete bottlingPlant;
for (int i = 0; i < configParms.numVendingMachines; ++i) {
delete vendingMachines[i];
}
delete watCardOffice;
delete parent;
delete bank;
}