-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
151 lines (124 loc) · 4.23 KB
/
main.cpp
File metadata and controls
151 lines (124 loc) · 4.23 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
#include "Point.h"
#include "Matrix2D.h"
#include "Driver.h"
#include "TaxiCenter.h"
#include "TaxiStandard.h"
#include "TaxiLuxury.h"
#include "src/sockets/Udp.h"
#include <boost/archive/text_iarchive.hpp>
#include <sstream>
#include <iostream>
#include <fstream>
using namespace std;
//main function.
int main(int argc, char* argv[]) {
char dummy;
int sizeGridX, sizeGridY, numbersOfObstacles;
int selection = -1;
// getting the grid.
cin >> sizeGridX >> sizeGridY;
Matrix2D *matrix2D = new Matrix2D(sizeGridX, sizeGridY);
// getting obstacles.
cin >> numbersOfObstacles;
if (numbersOfObstacles > 0) {
for (int j = 0; j < numbersOfObstacles; ++j) {
int x, y;
cin >> x >> dummy >> y;
}
}
TaxiCenter* taxiCenter = new TaxiCenter();
do {
cin >> selection;
taxiCenter->setAll();
switch (selection) {
// insert driver
case 1: {
/*
int driver_id, age, xp, vehicle_id;
char status;
Point p = Point(0,0);
Node* n = matrix2D->getNodeInMatrix((&p));
// getting details.
cin >> driver_id >> dummy >> age >> dummy >> status >> dummy
>> xp >> dummy >> vehicle_id;
Driver *driver = new Driver(driver_id, age, status, xp,
vehicle_id, n);
*/
Udp udp(1, 5555);
udp.initialize();
char buffer[1024];
udp.reciveData(buffer, sizeof(buffer));
cout << buffer << endl;
istringstream iss;
boost::archive::text_iarchive ia(iss);
Driver* driver;
ia >> BOOST_SERIALIZATION_NVP(driver);
// adding the driver.
taxiCenter->addDriver(driver);
break;
}
// new ride
case 2: {
int ride_id, x_start, y_start, x_end, y_end, num_passengers;
double tariff;
//getting details.
cin >> ride_id >> dummy >> x_start >> dummy >> y_start
>> dummy >> x_end >> dummy >> y_end >> dummy
>> num_passengers >> dummy >> tariff;
Point pStart(x_start, y_start);
Point pEnd(x_end, y_end);
Node *start = matrix2D->getNodeInMatrix(&pStart);
Node *end = matrix2D->getNodeInMatrix(&pEnd);
Trip *ride = new Trip(start, end, ride_id, num_passengers,
tariff);
// adding the ride.
taxiCenter->addTrip(ride);
break;
}
// insert taxi
case 3: {
int taxi_id, taxi_type;
char manufacturer, color;
// getting details.
cin >> taxi_id >> dummy >> taxi_type >> dummy >> manufacturer
>> dummy >> color;
Taxi* taxi;
// checking the type of the taxi and adding it to the
// taxi center.
switch (taxi_type) {
case 1: {
taxi = new TaxiStandard(taxi_id, color, manufacturer);
taxiCenter->addTaxi(taxi);
break;
}
case 2: {
taxi = new TaxiLuxury(taxi_id, color, manufacturer);
taxiCenter->addTaxi(taxi);
}
default: {
break;
}
}
break;
}
// printing driver location
case 4: {
int driverId;
cin >> driverId;
taxiCenter->printDriverLocation(driverId);
break;
}
// start driving
case 6: {
taxiCenter->doTrip();
}
default: {
break;
}
}
} while (selection != 7);
// deleting items.
delete(taxiCenter);
delete(matrix2D);
return 0;
}