diff options
Autocommit at 02.05.2022 @ 21:40
5 files changed, 14 insertions, 2 deletions
| -rw-r--r-- | src/EventSystem/Event.cpp | 4 | ||||
| -rw-r--r-- | src/EventSystem/Reservation.cpp | 4 | ||||
| -rw-r--r-- | src/EventSystem/Reservation.h | 1 | ||||
| -rw-r--r-- | src/List/List.cpp | 5 | ||||
| -rw-r--r-- | src/List/List.h | 2 |
diff --git a/src/EventSystem/Event.cpp b/src/EventSystem/Event.cpp index cdbc017..9744e2e 100644 --- a/src/EventSystem/Event.cpp +++ b/src/EventSystem/Event.cpp @@ -10,7 +10,9 @@ Event::Event(const Hall* hall, String name, DateTime time) { } StatusCode Event::reserveTicket(const Ticket& ticket, const char* password, const char* note) { - // TODO: if (reservations.contains(ticket) || tickets.contain(ticket)) return E_... + if (tickets.contain(ticket)) return E_TicketAlreadyBought; + if (reservations.contain(Reservation(ticket, "", ""))) return E_TicketAlreadyReserved; + reservations.insert(Reservation(ticket, password, note)); return Success; } diff --git a/src/EventSystem/Reservation.cpp b/src/EventSystem/Reservation.cpp index ba12547..613a715 100644 --- a/src/EventSystem/Reservation.cpp +++ b/src/EventSystem/Reservation.cpp @@ -21,3 +21,7 @@ void Reservation::write(std::ostream& ostr) const { ostr.write(password, sizeof(password)); ostr.write(note, sizeof(note)); } + +int Reservation::compare(const Reservation& other) const { + return ticket.compare(other.ticket); +} diff --git a/src/EventSystem/Reservation.h b/src/EventSystem/Reservation.h index 7e96412..acc294c 100644 --- a/src/EventSystem/Reservation.h +++ b/src/EventSystem/Reservation.h @@ -16,6 +16,7 @@ public: void read(std::istream& istr); void write(std::ostream& ostr) const; + int compare(const Reservation& other) const; }; #endif diff --git a/src/List/List.cpp b/src/List/List.cpp index d5c2f04..d455c04 100644 --- a/src/List/List.cpp +++ b/src/List/List.cpp @@ -72,6 +72,11 @@ unsigned List<T>::findIndex(const T& element) const { } template <class T> +bool List<T>::contain(const T& element) const { + return findIndex(element) < count; +} + +template <class T> T& List<T>::operator[](unsigned index) { return elements[index]; } diff --git a/src/List/List.h b/src/List/List.h index 24003a6..23e3ee5 100644 --- a/src/List/List.h +++ b/src/List/List.h @@ -20,7 +20,7 @@ public: bool insertAt(const T& element, unsigned index); bool removeAt(unsigned index); unsigned findIndex(const T& element) const; - bool contains(const T& element) const; + bool contain(const T& element) const; T& operator[](unsigned index); const T& operator[](unsigned index) const; |
