-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
72 lines (63 loc) · 2.77 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
#include <iostream>
#include <sstream>
#include "student.h"
#include "parent.h"
#include "config.h"
using namespace std;
MPRNG mprng{};
bool convert( int & val, char * buffer ) { // convert C string to integer
std::stringstream ss( buffer ); // connect stream and buffer
string temp;
ss >> dec >> val; // convert integer from buffer
return ! ss.fail() && // conversion successful ?
! ( ss >> temp ); // characters after conversion all blank ?
} // convert
int main( int argc, char *argv[] ) {
int seed = getpid();
const char *configFile = "soda.config";
try {
switch ( argc ) {
case 3:
if ( strcmp( argv[2], "d" ) != 0 ) { // default ?
if ( ! convert( seed, argv[2] ) || seed <= 0 ) throw 1; // invalid ?
} // if
// FALL THROUGH
case 2:
configFile = argv[1];
// FALL THROUGH
case 1: break;
default: throw 1;
}
} catch ( ... ) {
cerr << "Usage: " << argv[0]
<< "soda [ config-file [ Seed (> 0)] ]" << endl;
exit(EXIT_FAILURE); // TERMINATE
}// try
ConfigParms config{};
processConfigFile( configFile, config );
// unsigned int sodaCost = 3; // MSRP per bottle
// unsigned int numStudents = 4; // number of students to create
// unsigned int maxPurchases = 5; // maximum number of bottles a student purchases
// unsigned int numVendingMachines = 2; // number of vending machines
// unsigned int maxStockPerFlavour; // maximum number of bottles of each flavour stocked
// unsigned int maxShippedPerFlavour; // number of bottles of each flavour in a shipment
// unsigned int timeBetweenShipments; // length of time between shipment pickup
// unsigned int groupoffDelay = 2; // length of time between initializing gift cards
// unsigned int parentalDelay = 1; // length of time between cash deposits
// unsigned int numCouriers = 2;
unsigned int processors = 1;
mprng.set_seed( getpid() );
uProcessor p[processors - 1]; // number of kernel threads
Printer prt( config.numStudents, config.numVendingMachines, config.numCouriers );
Bank bank( config.numStudents );
Parent parent( prt, bank, config.numStudents, config.parentalDelay );
WATCardOffice office( prt, bank, config.numCouriers );
Groupoff groupoff( prt, config.numStudents, config.sodaCost, config.groupoffDelay );
Student *studentList[config.numStudents];
for ( unsigned int s=0; s < config.numStudents; s++ ) {
studentList[s] = new Student( prt, office, groupoff, s, config.maxPurchases );
}
for ( unsigned int s=0; s < config.numStudents; s++ ) {
delete studentList[s];
}
}