-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGarage.cpp
More file actions
48 lines (35 loc) · 1.02 KB
/
Copy pathGarage.cpp
File metadata and controls
48 lines (35 loc) · 1.02 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
#include "Garage.h"
const char* ParkingFullError::what() const _NOEXCEPT {
return "Parking is full";
}
ParkingIdNotFound::ParkingIdNotFound(const std::string& parkingId): parkingId(parkingId) {}
const char* ParkingIdNotFound::what() const _NOEXCEPT {
return "Parking id not found";
}
Garage::Garage(unsigned int capacity): capacity(capacity) {}
std::string Garage::createTicketId() const {
static int i = 1;
std::stringstream ss;
ss << i++;
return ss.str();
}
std::string Garage::park(const Vehicle& vehicle) {
if (parkingInfoMap.size() >= capacity) {
throw ParkingFullError();
}
std::string ticketId = createTicketId();
parkingInfoMap[ticketId] = {
vehicle.getVehicleType(),
vehicle.getId(),
"",
""
};
return ticketId;
}
int Garage::takeVehicleOut(const std::string& parkingId) {
auto parkingInfoIterator = parkingInfoMap.find(parkingId);
if (parkingInfoIterator == parkingInfoMap.end()) {
throw ParkingIdNotFound(parkingId);
}
return parkingInfoIterator->second.vehicleId;
}