Website Summary Files Commits Branches @commit @diff @stats
path: root / src / EventSystem
diff options
context:
space:
mode:
Commitb844597fd23bc57aa97e231fc90eecfd6322cecc (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-07 08:28:27 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-07 08:28:27 +0300
Files86a4112ecfa1e3a54dbcf44a7ddf37575ba4aa39 /src/EventSystem
FMI-OOP-P1_TicketSystem-b844597fd23bc57aa97e231fc90eecfd6322cecc.tar
FMI-OOP-P1_TicketSystem-b844597fd23bc57aa97e231fc90eecfd6322cecc.tar.gz
FMI-OOP-P1_TicketSystem-b844597fd23bc57aa97e231fc90eecfd6322cecc.zip
Parent0910afb91c8f9672be1d6184f47fb75947ea14f1 (diff)
Reorganized whole architecture
diff --git a/src/EventSystem/Event.cpp b/src/EventSystem/Event.cpp
deleted file mode 100644
index e6105eb..0000000
--- a/src/EventSystem/Event.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-#include "Event.h"
-#include "Reservation.h"
-#include "StatusCodes.h"
-
-Event::Event() : Event(nullptr, "", Date()) {}
-
-Event::Event(const Hall* hall, String name, Date date) : tickets(), reservations() {
- this->hall = hall;
- this->name = name;
- this->date = date;
-}
-
-const OrderedList<Ticket>& Event::get_tickets() const {
- return tickets;
-}
-
-const OrderedList<Reservation>& Event::get_reservations() const {
- return reservations;
-}
-
-const Hall& Event::get_hall() const {
- return *hall;
-}
-
-const String& Event::get_name() const {
- return name;
-}
-
-const Date& Event::get_date() const {
- return date;
-}
-
-StatusCode Event::reserveTicket(const Ticket& ticket, const char* password, const char* note) {
- if (tickets.contain(ticket)) return E_TicketAlreadyBought;
- if (reservations.contain(ticket)) return E_TicketAlreadyReserved;
-
- reservations.insert(Reservation(ticket, password, note));
- return Success;
-}
-
-StatusCode Event::cancelReservation(unsigned row, unsigned seat) {
- return cancelReservation(Ticket(row, seat));
-}
-
-StatusCode Event::cancelReservation(const Ticket& ticket) {
- unsigned ind = reservations.findIndex(ticket);
- if (ind == reservations.get_count())
- return W_TicketHadNotBeenReserved;
-
- reservations.removeAt(ind);
- return Success;
-}
-
-StatusCode Event::buyTicket(const Ticket& ticket) {
- if (tickets.contain(ticket)) return E_TicketAlreadyBought;
- if (reservations.contain(ticket)) return E_TicketAlreadyReserved;
-
- tickets.insert(ticket);
- return Success;
-}
-
-StatusCode Event::buyTicketFromReservation(const Reservation& reservation, const char* password) {
- unsigned resInd = reservations.findIndex(reservation);
- if (resInd == reservations.get_count()) return E_ReservationDoesNotExist;
-
- if (!reservations[resInd].validPassword(password)) return E_WrongReservationPassword;
-
- reservations.removeAt(resInd);
- tickets.insert(reservation.get_ticket());
- return Success;
-}
-
-int Event::compare(const Event& other) {
- // TODO: improve
- return name.compare(other.name);
-}
diff --git a/src/EventSystem/Event.h b/src/EventSystem/Event.h
deleted file mode 100644
index 43ad5d9..0000000
--- a/src/EventSystem/Event.h
+++ /dev/null
@@ -1,41 +0,0 @@
-#ifndef HEADER_EVENTSYSTEM_EVENT
-#define HEADER_EVENTSYSTEM_EVENT
-
-#include "../List/OrderedList.hpp"
-#include "../Date/Date.h"
-#include "../String/String.h"
-#include "../Venue/Hall.h"
-#include "Ticket.h"
-#include "Reservation.h"
-#include "StatusCodes.h"
-
-class Event {
- const Hall* hall;
- String name;
- Date date;
- OrderedList<Ticket> tickets;
- OrderedList<Reservation> reservations;
-
-public:
- Event();
- Event(const Hall* hall, String name, Date date);
-
- const Hall& get_hall() const;
- const String& get_name() const;
- const Date& get_date() const;
- const OrderedList<Ticket>& get_tickets() const;
- const OrderedList<Reservation>& get_reservations() const;
-
- StatusCode reserveTicket(const Ticket& ticket, const char* password, const char* note);
-
- StatusCode cancelReservation(unsigned row, unsigned seat);
- StatusCode cancelReservation(const Ticket& ticket);
-
- StatusCode buyTicket(const Ticket& ticket);
-
- StatusCode buyTicketFromReservation(const Reservation& reservation, const char* password);
-
- int compare(const Event& other);
-};
-
-#endif
diff --git a/src/EventSystem/EventSystem.cpp b/src/EventSystem/EventSystem.cpp
deleted file mode 100644
index 95bd1c4..0000000
--- a/src/EventSystem/EventSystem.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-#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();
-}
diff --git a/src/EventSystem/EventSystem.h b/src/EventSystem/EventSystem.h
deleted file mode 100644
index 4eeac61..0000000
--- a/src/EventSystem/EventSystem.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifndef HEADER_EVENTSYSTEM
-#define HEADER_EVENTSYSTEM
-
-#include "../List/OrderedList.hpp"
-#include "../Date/Date.h"
-
-#include "Event.h"
-#include "StatusCodes.h"
-
-class EventSystem {
- OrderedList<Event> events;
- unsigned indSoonestUpcoming;
-
- void updateSoonestUpcoming();
- unsigned indexOfEvent(const Date& date);
- unsigned indexOfEvent(const char* name, const Date& date);
-
-public:
- EventSystem();
- EventSystem(const Event* events, unsigned eventCount);
-
- StatusCode createEvent(const Hall* hall, String name, Date date);
- StatusCode cancelEvent(const char* name, const Date& date);
-
- StatusCode reserveTicket(const char* name, const Date& date, const char* password, const char* note, unsigned seatRow, unsigned seatColumn);
- StatusCode reserveTicket(const char* name, const Date& date, const char* password, const char* note, const Ticket& ticket);
-
- StatusCode cancelTicketReservation(const char* name, const Date& date, unsigned seatRow, unsigned seatColumn);
- StatusCode cancelTicketReservation(const char* name, const Date& date, const Ticket& ticket);
-
- StatusCode buyTicket(const char* name, const Date& date, unsigned row, unsigned seat);
- StatusCode buyTicket(const char* name, const Date& date, const Ticket& ticket);
- StatusCode buyTicket(const char* name, const Date& date, unsigned row, unsigned seat, const char* password);
- StatusCode buyTicket(const char* name, const Date& date, const Ticket& ticket, const char* password);
-
- const Hall* queryEventHall(const char* name, const Date& date);
- OrderedList<Ticket> queryTickets(const char* name, const Date& date);
- OrderedList<Reservation> queryReservations(const char* name, const Date& date);
-
- void queryMostVisited();
- void queryInsufficientlyVisited();
- void reportBoughtTickets(Date start, Date end, unsigned hall);
- void reportReservations(unsigned eventIndex);
-};
-
-#endif
diff --git a/src/EventSystem/Reservation.cpp b/src/EventSystem/Reservation.cpp
deleted file mode 100644
index 26278b2..0000000
--- a/src/EventSystem/Reservation.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#include "Reservation.h"
-#include <cstring>
-#include <ostream>
-
-Reservation::Reservation() : Reservation(Ticket(), "", "") {}
-
-Reservation::Reservation(const Ticket& ticket) : Reservation(ticket, "", "") {}
-
-Reservation::Reservation(const Ticket& ticket, const char* password, const char* note) {
- this->ticket = ticket;
- strcpy(this->password, password);
- strcpy(this->note, note);
-}
-
-bool Reservation::validPassword(const char* password) const {
- return !strcmp(this->password, password);
-}
-
-const Ticket& Reservation::get_ticket() const {
- return ticket;
-}
-
-void Reservation::read(std::istream& istr) {
- ticket.read(istr);
- istr.read(password, sizeof(password));
- istr.read(note, sizeof(note));
-}
-
-void Reservation::write(std::ostream& ostr) const {
- ticket.write(ostr);
- 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
deleted file mode 100644
index 1a415b5..0000000
--- a/src/EventSystem/Reservation.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef HEADER_EVENTSYSTEM_RESERVATION
-#define HEADER_EVENTSYSTEM_RESERVATION
-
-#include "Ticket.h"
-#include <istream>
-#include <ostream>
-
-#define PASSWORD_LEN 8
-#define NOTE_LEN 32
-
-class Reservation {
- Ticket ticket;
- char password[PASSWORD_LEN];
- char note[NOTE_LEN];
-
-public:
- Reservation();
- Reservation(const Ticket& ticket);
- Reservation(const Ticket& ticket, const char* password, const char* note);
-
- bool validPassword(const char* password) const;
- const Ticket& get_ticket() const;
-
- void read(std::istream& istr);
- void write(std::ostream& ostr) const;
- int compare(const Reservation& other) const;
-};
-
-#endif
diff --git a/src/EventSystem/StatusCodes.h b/src/EventSystem/StatusCodes.h
deleted file mode 100644
index 4068cd3..0000000
--- a/src/EventSystem/StatusCodes.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef HEADER_EVENTSYSTEM_STATUSCODES
-#define HEADER_EVENTSYSTEM_STATUSCODES
-
-enum StatusCode {
- Success,
-
-
- W_TicketHadNotBeenReserved,
-
-
- E_Generic,
- E_DoesntExist,
-
- E_HallDoesntExist,
-
- E_EventWillOverlap,
- E_EventDoesNotExist,
-
- E_TicketAlreadyBought,
- E_TicketAlreadyReserved,
- E_ReservationDoesNotExist,
- E_WrongReservationPassword,
-};
-
-#endif
diff --git a/src/EventSystem/Ticket.cpp b/src/EventSystem/Ticket.cpp
deleted file mode 100644
index e37cccf..0000000
--- a/src/EventSystem/Ticket.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-#include "Ticket.h"
-
-Ticket::Ticket() : Ticket(0, 0) {}
-
-Ticket::Ticket(unsigned row, unsigned seat) {
- this->row = row;
- this->seat = seat;
-}
-
-unsigned Ticket::get_row() const {
- return row;
-}
-
-unsigned Ticket::get_seat() const {
- return seat;
-}
-
-void Ticket::read(std::istream& istr) {
- istr.read((char*)&row, sizeof(row));
- istr.read((char*)&row, sizeof(seat));
-}
-
-void Ticket::write(std::ostream& ostr) const {
- ostr.write((const char*)&row, sizeof(row));
- ostr.write((const char*)&seat, sizeof(seat));
-}
-
-int Ticket::compare(const Ticket& other) const {
- if (row == other.row)
- return (seat > other.seat) - (seat < other.seat);
- return (row > other.row) - (row < other.row);
-}
-
-/* General */
-
-std::istream& operator>>(std::istream& istr, Ticket& ticket) {
- unsigned row, seat;
- istr >> row >> seat;
- ticket = Ticket(row, seat);
- return istr;
-}
-
-std::ostream& operator<<(std::ostream& ostr, const Ticket& ticket) {
- return ostr << ticket.get_row() << " " << ticket.get_seat();
-}
diff --git a/src/EventSystem/Ticket.h b/src/EventSystem/Ticket.h
deleted file mode 100644
index 5d26e35..0000000
--- a/src/EventSystem/Ticket.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef HEADER_EVENTSYSTEM_TICKET
-#define HEADER_EVENTSYSTEM_TICKET
-
-#include <istream>
-#include <ostream>
-
-class Ticket {
- unsigned row;
- unsigned seat;
-
-public:
- Ticket();
- Ticket(unsigned row, unsigned seat);
-
- unsigned get_row() const;
- unsigned get_seat() const;
-
- void read(std::istream& istr);
- void write(std::ostream& ostr) const;
- int compare(const Ticket& other) const;
-};
-
-std::istream& operator>>(std::istream& istr, Ticket& ticket);
-std::ostream& operator<<(std::ostream& ostr, const Ticket& ticket);
-
-#endif