Website Summary Files Commits Branches @commit @diff @stats
path: root / src / EventSystem / Ticket.cpp
blob: 997045e67eb7f9370e1cdf80e05fe8503b4cd736 (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
#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) - (other.seat < seat);
	return (row > other.row) - (other.row < 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();
}