Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / Event.cpp
blob: 8ba5449ea76912b46cbde3a3de71270502a9da4d (plain) (blame)
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
#include "Event.h"
#include "Reservation.h"

Event::Event() : hall(), name(), date() {}

Event::Event(const Hall& hall, String name, Date date) : tickets(), reservations() {
	this->hall = hall;
	this->name = name;
	this->date = date;
}

OrderedList<Ticket>& Event::get_tickets() {
	return tickets;
}

const OrderedList<Ticket>& Event::get_tickets() const {
	return tickets;
}

OrderedList<Reservation>& Event::get_reservations() {
	return reservations;
}

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;
}

void Event::read(std::istream& istr) {
	hall.read(istr);
	name.read(istr);
	date.read(istr);
	tickets.read(istr);
	reservations.read(istr);
}

void Event::write(std::ostream& ostr) {
	hall.write(ostr);
	name.write(ostr);
	date.write(ostr);
	tickets.write(ostr);
	reservations.write(ostr);
}

int Event::compare(const Event& other) {
	if (hall.compare(other.hall) == 0)
		return date.compare(other.date);
	return hall.compare(other.hall);
}

std::istream& operator>>(std::istream& istr, Event& event) {
	Hall newHall;
	String newString;
	Date newDate;
	OrderedList<Ticket> newTickets;
	OrderedList<Reservation> newReservation;

	istr >> newHall >> newString >> newDate >> newTickets >> newReservation;
	event = Event(newHall, newString, newDate);
	event.get_tickets() = newTickets;
	event.get_reservations() = newReservation;

	return istr;
}

std::ostream& operator<<(std::ostream& ostr, const Event& event) {
	ostr << "| Hall: " << event.get_hall().get_number() << " | Name: " << event.get_name() << " | Date: " << event.get_date() << std::endl;

	ostr << "Bought tickets: ";
	for (unsigned i = 0; i < event.get_tickets().get_count(); i++)
		ostr << "[" << event.get_tickets()[i] << "] ";
	ostr << std::endl << "Reserved tickets: ";
	for (unsigned i = 0; i < event.get_reservations().get_count(); i++)
		ostr << "[" << event.get_reservations()[i] << "] ";
	return ostr << std::endl;
}