From 0521180c61e7d8970f164f3154599e49800e85c6 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 2 May 2022 21:40:36 +0300 Subject: Autocommit at 02.05.2022 @ 21:40 --- src/EventSystem/Event.cpp | 4 +++- src/EventSystem/Reservation.cpp | 4 ++++ src/EventSystem/Reservation.h | 1 + src/List/List.cpp | 5 +++++ src/List/List.h | 2 +- 5 files changed, 14 insertions(+), 2 deletions(-) (limited to 'src') 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 @@ -71,6 +71,11 @@ unsigned List::findIndex(const T& element) const { return ind; } +template +bool List::contain(const T& element) const { + return findIndex(element) < count; +} + template T& List::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; -- cgit v1.3.1-26-gb76a