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
|
#include "EventSystem.h"
#include "StatusCodes.h"
/* Private */
void EventSystem::updateSoonestUpcoming() {
}
unsigned EventSystem::indexOfEvent(const Date& date) {
// TODO: make binary search
for (unsigned i = indSoonestUpcoming; i < events.get_count(); i++) {
if (events[i].get_date().compare(date) == 0)
return i;
}
return events.get_count();
}
unsigned EventSystem::indexOfEvent(const char* name, const Date& date) {
unsigned ind = indexOfEvent(date);
if (ind < events.get_count() && events[ind].get_name().compare(name) == 0)
return ind;
return events.get_count();
}
/* Public */
EventSystem::EventSystem() {
events = OrderedList<Event>();
indSoonestUpcoming = 0;
}
EventSystem::EventSystem(const Event* events, unsigned eventCount) {
this->events = OrderedList<Event>(events, eventCount);
indSoonestUpcoming = 0;
updateSoonestUpcoming();
}
StatusCode EventSystem::createEvent(const Hall* hall, String name, Date date) {
if (indexOfEvent(date) < events.get_count())
return E_EventWillOverlap;
events.insert(Event(hall, name, date));
return Success;
}
StatusCode EventSystem::cancelEvent(const char* name, const Date& date) {
unsigned ind = indexOfEvent(name, date);
if (ind == events.get_count())
return E_EventDoesNotExist;
events.removeAt(ind);
return Success;
}
StatusCode EventSystem::reserveTicket(const char* name, const Date& date, const char* password, const char* note, unsigned seatRow, unsigned seatColumn) {
return reserveTicket(name, date, password, note, Ticket(seatRow, seatColumn));
}
StatusCode EventSystem::reserveTicket(const char* name, const Date& date, const char* password, const char* note, const Ticket& ticket) {
unsigned ind = indexOfEvent(name, date);
if (ind == events.get_count())
return E_EventDoesNotExist;
return events[ind].reserveTicket(ticket, password, note);
}
StatusCode EventSystem::cancelTicketReservation(const char* name, const Date& date, unsigned seatRow, unsigned seatColumn) {
return cancelTicketReservation(name, date, Ticket(seatRow, seatColumn));
}
StatusCode EventSystem::cancelTicketReservation(const char* name, const Date& date, const Ticket& ticket) {
unsigned ind = indexOfEvent(name, date);
if (ind == events.get_count())
return E_EventDoesNotExist;
return events[ind].cancelReservation(ticket);
}
StatusCode EventSystem::buyTicket(const char* name, const Date& date, unsigned row, unsigned seat) {
return buyTicket(name, date, Ticket(row, seat));
}
StatusCode EventSystem::buyTicket(const char* name, const Date& date, const Ticket& ticket) {
unsigned ind = indexOfEvent(name, date);
if (ind == events.get_count())
return E_EventDoesNotExist;
return events[ind].buyTicket(ticket);
}
StatusCode EventSystem::buyTicket(const char* name, const Date& date, unsigned row, unsigned seat, const char* password) {
return buyTicket(name, date, Ticket(row, seat), password);
}
StatusCode EventSystem::buyTicket(const char* name, const Date& date, const Ticket& ticket, const char* password) {
unsigned ind = indexOfEvent(name, date);
if (ind == events.get_count())
return E_EventDoesNotExist;
return events[ind].buyTicketFromReservation(Reservation(ticket), password);
}
const Hall* EventSystem::queryEventHall(const char* name, const Date& date) {
unsigned ind = indexOfEvent(name, date);
if (ind == events.get_count())
return nullptr;
return &events[ind].get_hall();
}
OrderedList<Ticket> EventSystem::queryTickets(const char* name, const Date& date) {
unsigned ind = indexOfEvent(name, date);
if (ind == events.get_count())
return OrderedList<Ticket>();
return events[ind].get_tickets();
}
OrderedList<Reservation> EventSystem::queryReservations(const char* name, const Date& date) {
unsigned ind = indexOfEvent(name, date);
if (ind == events.get_count())
return OrderedList<Reservation>();
return events[ind].get_reservations();
}
|