Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / Ticket.cpp
diff options
context:
space:
mode:
Commitbf7689ba06764b72a6212549a5c8a39e294cceee (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-08 20:40:30 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-08 20:40:30 +0300
Filesa9ff9780c4f502de58b9d075290acbacf4769d44 /src/Models/Ticket.cpp
FMI-OOP-P1_TicketSystem-bf7689ba06764b72a6212549a5c8a39e294cceee.tar
FMI-OOP-P1_TicketSystem-bf7689ba06764b72a6212549a5c8a39e294cceee.tar.gz
FMI-OOP-P1_TicketSystem-bf7689ba06764b72a6212549a5c8a39e294cceee.zip
Parenta8388cfdc47386dcb61f1b5bb9190ce382bf3f1d (diff)
Fully documented all Models
1 files changed, 27 insertions, 1 deletions
-rw-r--r--src/Models/Ticket.cpp28
diff --git a/src/Models/Ticket.cpp b/src/Models/Ticket.cpp
index 196f5f5..bc8ef84 100644
--- a/src/Models/Ticket.cpp
+++ b/src/Models/Ticket.cpp
@@ -15,24 +15,45 @@ unsigned Ticket::get_seat() const {
return seat;
}
+/*! \param istr An input stream
+ *
+ * Directly reads bytes from stream (calls read() function).
+ *
+ * \remark Doesn't alter the stream in any other way.
+ * \note Best used with binary ifstream
+ */
void Ticket::read(std::istream& istr) {
istr.read((char*)&row, sizeof(row));
istr.read((char*)&seat, sizeof(seat));
}
+/*! \param ostr An output stream
+ *
+ * Directly writes bytes to stream (calls write() function).
+ *
+ * \remark Doesn't alter the stream in any other way.
+ * \note Best used with binary ofstream
+ */
void Ticket::write(std::ostream& ostr) const {
ostr.write((const char*)&row, sizeof(row));
ostr.write((const char*)&seat, sizeof(seat));
}
+/*! \return If rows are equal, -1 if seat < other.seat, 1 if seat > other.seat, 0 if seat == other.seat, else the same, but for rows
+ */
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 */
+/* Outside of class */
+/*!
+ * Uses the stream's >> operator to read and parse row and seat.
+ *
+ * \note Best used with std::cin or text std::ifstream
+ */
std::istream& operator>>(std::istream& istr, Ticket& ticket) {
unsigned row, seat;
istr >> row >> seat;
@@ -40,6 +61,11 @@ std::istream& operator>>(std::istream& istr, Ticket& ticket) {
return istr;
}
+/*!
+ * Uses the stream's << operator to write row and seat, separated by a space.
+ *
+ * \note Best used with std::cout or text std::ofstream
+ */
std::ostream& operator<<(std::ostream& ostr, const Ticket& ticket) {
return ostr << ticket.get_row() << " " << ticket.get_seat();
}