diff options
Fully documented all Models
8 files changed, 200 insertions, 3 deletions
| -rw-r--r-- | src/Models/Event.cpp | 47 | ||||
| -rw-r--r-- | src/Models/Event.h | 24 | ||||
| -rw-r--r-- | src/Models/Hall.cpp | 26 | ||||
| -rw-r--r-- | src/Models/Hall.h | 17 | ||||
| -rw-r--r-- | src/Models/Reservation.cpp | 29 | ||||
| -rw-r--r-- | src/Models/Reservation.h | 17 | ||||
| -rw-r--r-- | src/Models/Ticket.cpp | 28 | ||||
| -rw-r--r-- | src/Models/Ticket.h | 15 |
diff --git a/src/Models/Event.cpp b/src/Models/Event.cpp index ca9d830..c4557b7 100644 --- a/src/Models/Event.cpp +++ b/src/Models/Event.cpp @@ -37,6 +37,14 @@ const Date& Event::get_date() const { return date; } +/*! \param istr An input stream + * + * Directly reads bytes from stream (calls read() function). + * Stored types must have defined a read() function. + * + * \remark Doesn't alter the stream in any other way. + * \note Best used with binary ifstream + */ void Event::read(std::istream& istr) { hall.read(istr); name.read(istr); @@ -45,6 +53,14 @@ void Event::read(std::istream& istr) { reservations.read(istr); } +/*! \param ostr An output stream + * + * Directly writes bytes to stream (calls write() function). + * Stored types must have defined a read() function. + * + * \remark Doesn't alter the stream in any other way. + * \note Best used with binary ofstream + */ void Event::write(std::ostream& ostr) { hall.write(ostr); name.write(ostr); @@ -53,12 +69,20 @@ void Event::write(std::ostream& ostr) { reservations.write(ostr); } +/*! \return compare of halls, or if they are equal, compare of dates + */ int Event::compare(const Event& other) { if (hall.compare(other.hall) == 0) return date.compare(other.date); return hall.compare(other.hall); } +/*! + * Uses the stream's >> operator to read and parse all internal values. + * Stored types must have defined operator >>. + * + * \note Best used with std::cin or text std::ifstream + */ std::istream& operator>>(std::istream& istr, Event& event) { Hall newHall; String newString; @@ -76,10 +100,33 @@ std::istream& operator>>(std::istream& istr, Event& event) { unsigned insertionOpSet = 0; +/*! \param setting A number, defining the different options. It's best if it is passed as binary number. + * + * Sets a configuration setting for how operator<< should behave. Setting is stored as a global variable in the cpp file, so it's independent of Event instance. + * + * Each bit in the number is a certain setting. Each bit from left to right represents one of these options, from top to bottom: + * 1. Write count of bought tickets (available only if 5. is set) + * 2. Write count of reserved tickets (available only if 5. is set) + * 3. Write reservations + * 4. Write bought tickets + * 5. Write Hall information + * + * \par Example + * To configure printing the Hall information, bought tickets count and the bought tickets themselves, you would do: + * \code{.cpp} + * configureEventInsertionOp(0b10011); + * \endcode + */ void configureEventInsertionOp(unsigned setting) { insertionOpSet = setting; } +/*! + * Uses the stream's << operator to write all internal data, following setting from configureEventInsertionOp() + * Stored types must have defined operator <<. + * + * \note Best used with std::cout or text std::ofstream + */ std::ostream& operator<<(std::ostream& ostr, const Event& event) { if (insertionOpSet & 1) { ostr << "| Hall: " << event.get_hall().get_number() << " | Name: " << event.get_name() << " | Date: " << event.get_date(); diff --git a/src/Models/Event.h b/src/Models/Event.h index 496ecab..1162b8f 100644 --- a/src/Models/Event.h +++ b/src/Models/Event.h @@ -1,6 +1,10 @@ #ifndef HEADER_MODEL_EVENT #define HEADER_MODEL_EVENT +/*! \file Event.h + * \brief Stores the declaration of class Event + */ + #include "../Generic/List/OrderedList.hpp" #include "../Generic/Date/Date.h" #include "../Generic/String/String.h" @@ -10,6 +14,8 @@ #include <istream> #include <ostream> +/*! \brief Stores an event's hall, name, date, bought tickets and reservations + */ class Event { Hall hall; String name; @@ -18,26 +24,40 @@ class Event { OrderedList<Reservation> reservations; public: + //! Calls default constructors on data Event(); + //! Copies given hall and sets name and date Event(const Hall& hall, String name, Date date); + //! Returns constant reference Hall in which event will be held const Hall& get_hall() const; + //! Returns constant reference to name of event const String& get_name() const; + //! Returns constant reference to date on which event will be held const Date& get_date() const; + //! Returns reference to bought tickets OrderedList<Ticket>& get_tickets(); + //! Returns constant reference to bought tickets const OrderedList<Ticket>& get_tickets() const; + //! Returns reference to reservations OrderedList<Reservation>& get_reservations(); + //! Returns constant reference to reservations const OrderedList<Reservation>& get_reservations() const; - void write(std::ostream& ostr); + //! Reads Event from stream void read(std::istream& istr); - + //! Writes Event to stream + void write(std::ostream& ostr); + //! Compares two events int compare(const Event& other); }; +//! Reads Event from stream with >> operator std::istream& operator>>(std::istream& istr, Event& event); +//! Configures how Event should be shown, when written to stream with << operator void configureEventInsertionOp(unsigned setting); +//! Writes Event to stream with << operator std::ostream& operator<<(std::ostream& ostr, const Event& event); #endif diff --git a/src/Models/Hall.cpp b/src/Models/Hall.cpp index d1c25f7..feacdac 100644 --- a/src/Models/Hall.cpp +++ b/src/Models/Hall.cpp @@ -21,22 +21,43 @@ unsigned Hall::get_seatsPerRow() const { return seatsPerRow; } +/*! \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 Hall::read(std::istream& istr) { istr.read((char*)&number, sizeof(number)); istr.read((char*)&rows, sizeof(rows)); istr.read((char*)&seatsPerRow, sizeof(seatsPerRow)); } +/*! \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 Hall::write(std::ostream& ostr) const { ostr.write((char*)&number, sizeof(number)); ostr.write((char*)&rows, sizeof(rows)); ostr.write((char*)&seatsPerRow, sizeof(seatsPerRow)); } +/*! \return -1 if number < other.number, 1 if number > other.number, 0 if number == other.number + */ int Hall::compare(const Hall& other) const { return (number > other.get_number()) - (number < other.get_number()); } +/*! + * Uses the stream's >> operator to read and parse all internal values. + * + * \note Best used with std::cin or text std::ifstream + */ std::istream& operator>>(std::istream& istr, Hall& hall) { int number; unsigned rows, seatsPerRow; @@ -45,6 +66,11 @@ std::istream& operator>>(std::istream& istr, Hall& hall) { return istr; } +/*! + * Uses the stream's << operator to write all internal data. + * + * \note Best used with std::cout or text std::ofstream + */ std::ostream& operator<<(std::ostream& ostr, const Hall& hall) { return ostr << hall.get_number() << " " << hall.get_rows() << " "<< hall.get_seatsPerRow(); } diff --git a/src/Models/Hall.h b/src/Models/Hall.h index d493573..c567c75 100644 --- a/src/Models/Hall.h +++ b/src/Models/Hall.h @@ -1,30 +1,47 @@ #ifndef HEADER_MODEL_HALL #define HEADER_MODEL_HALL +/*! \file Hall.h + * \brief Stores the declaration of class Hall + */ + #include <istream> #include <ostream> +/*! \brief Each hall contains a number, rows and seats per row + */ class Hall { int number; unsigned rows; unsigned seatsPerRow; public: + //! Sets values to 0 Hall(); + //! Sets values, except number, to 0 Hall(int number); + //! Sets values Hall(int number, unsigned rows, unsigned seatsPerRow); + //! Returns a Hall's number int get_number() const; + //! Returns a Hall's row count unsigned get_rows() const; + //! Return a Hall's seats per row count unsigned get_seatsPerRow() const; + //! Reads Hall from stream void read(std::istream& istr); + //! Writes Hall to steam void write(std::ostream& ostr) const; + //! Compare two Halls int compare(const Hall& other) const; }; +//! Reads Hall from stream with >> operator std::istream& operator>>(std::istream& istr, Hall& hall); +//! Writes Hall to stream with << operator std::ostream& operator<<(std::ostream& ostr, const Hall& hall); #endif diff --git a/src/Models/Reservation.cpp b/src/Models/Reservation.cpp index 159b996..002ba29 100644 --- a/src/Models/Reservation.cpp +++ b/src/Models/Reservation.cpp @@ -23,28 +23,57 @@ const char* Reservation::get_note() const { return note; } +/*! \param istr An input stream + * + * Directly reads bytes from stream (calls read() function). + * Uses ticket's read() function. + * + * \remark Doesn't alter the stream in any other way. + * \note Best used with binary ifstream + */ void Reservation::read(std::istream& istr) { ticket.read(istr); istr.read(password, sizeof(password)); istr.read(note, sizeof(note)); } +/*! \param ostr An output stream + * + * Directly writes bytes to stream (calls write() function). + * Uses ticket's write() function. + * + * \remark Doesn't alter the stream in any other way. + * \note Best used with binary ofstream + */ void Reservation::write(std::ostream& ostr) const { ticket.write(ostr); ostr.write(password, sizeof(password)); ostr.write(note, sizeof(note)); } +/*! \return Compares tickets + */ int Reservation::compare(const Reservation& other) const { return ticket.compare(other.ticket); } +/*! + * Uses the stream's >> operator to read and parse the ticket. + * Password and note are left blank. + * + * \note Best used with std::cin or text std::ifstream + */ std::istream& operator>>(std::istream& istr, Reservation& reservation) { strncpy(reservation.password, "", PASSWORD_LEN); strncpy(reservation.note, "", NOTE_LEN); return istr >> reservation.ticket; } +/*! + * Uses the stream's << operator to write the ticket only. + * + * \note Best used with std::cout or text std::ofstream + */ std::ostream& operator<<(std::ostream& ostr, const Reservation& reservation) { return ostr << reservation.ticket; } diff --git a/src/Models/Reservation.h b/src/Models/Reservation.h index eb7013b..10035b9 100644 --- a/src/Models/Reservation.h +++ b/src/Models/Reservation.h @@ -1,6 +1,10 @@ #ifndef HEADER_MODEL_RESERVATION #define HEADER_MODEL_RESERVATION +/*! \file Reservation.h + * \brief Stores the declaration of class Reservation + */ + #include "Ticket.h" #include <istream> #include <ostream> @@ -8,25 +12,38 @@ #define PASSWORD_LEN 8 #define NOTE_LEN 32 +/*! \brief Each Reservations contains a ticket, a password and a note + */ class Reservation { Ticket ticket; char password[PASSWORD_LEN]; char note[NOTE_LEN]; public: + //! Sets ticket as default value and leaves password and note blank Reservation(); + //! Sets ticket and leaves password and note blank Reservation(const Ticket& ticket); + //! Sets ticket, password and note Reservation(const Ticket& ticket, const char* password, const char* note); + //! Returns constant reference to ticket const Ticket& get_ticket() const; + //! Returns constant C-style string to password const char* get_password() const; + //! Returns constant C-style string to note const char* get_note() const; + //! Reads Reservation from stream void read(std::istream& istr); + //! Writes Reservation to stream void write(std::ostream& ostr) const; + //! Compares two Reservations int compare(const Reservation& other) const; + //! Reads Reservation from stream with >> operator friend std::istream& operator>>(std::istream& istr, Reservation& reservation); + //! Writes Reservation to stream with << operator friend std::ostream& operator<<(std::ostream& ostr, const Reservation& reservation); }; 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(); } diff --git a/src/Models/Ticket.h b/src/Models/Ticket.h index fb242e3..06b4571 100644 --- a/src/Models/Ticket.h +++ b/src/Models/Ticket.h @@ -1,26 +1,41 @@ #ifndef HEADER_HEADER_TICKET #define HEADER_HEADER_TICKET +/*! \file Ticket.h + * \brief Stores the declaration of class Ticket + */ + #include <istream> #include <ostream> +/*! \brief Each Ticket contains a row and a seat number + */ class Ticket { unsigned row; unsigned seat; public: + //! Sets row and seat to zeroes Ticket(); + //! Sets row and seat Ticket(unsigned row, unsigned seat); + //! Returns row unsigned get_row() const; + //! Returns seat unsigned get_seat() const; + //! Reads Ticket from stram void read(std::istream& istr); + //! Writes Ticket to stream void write(std::ostream& ostr) const; + //! Compares two Tickets int compare(const Ticket& other) const; }; +//! Reads Ticket from stream with >> operator std::istream& operator>>(std::istream& istr, Ticket& ticket); +//! Writes Ticket to stream with << operator std::ostream& operator<<(std::ostream& ostr, const Ticket& ticket); #endif |
