diff options
Autocommit at 07.05.2022 @ 16:08
3 files changed, 42 insertions, 30 deletions
| -rw-r--r-- | src/Generic/List/List.hpp | 60 | ||||
| -rw-r--r-- | src/Services/EventService.cpp | 11 | ||||
| -rw-r--r-- | src/Services/StatusCode.h | 1 |
diff --git a/src/Generic/List/List.hpp b/src/Generic/List/List.hpp index 2569380..7bbc835 100644 --- a/src/Generic/List/List.hpp +++ b/src/Generic/List/List.hpp @@ -27,9 +27,6 @@ public: List<T>& operator+=(const List<T> other); - std::istream& read(std::istream& istr); - std::ostream& write(std::ostream& ostr) const; - unsigned get_length() const; unsigned get_count() const; @@ -42,6 +39,11 @@ public: List& operator=(List&& other); }; +template <typename T> +std::istream& operator>>(std::istream& istr, List<T>& obj); +template <typename T> +std::ostream& operator<<(std::ostream& ostr, const List<T>& obj); + /* Private */ template <class T> @@ -142,31 +144,6 @@ List<T>& List<T>::operator+=(const List<T> other) { } template <class T> -std::istream& List<T>::read(std::istream& istr) { - istr.read((char*)&length, sizeof(length)); - istr.read((char*)&count, sizeof(count)); - - delete[] elements; - elements = new T[length]; - - for (int i = 0; i < count; i++) - elements[i].read(istr); // disgusting - - return istr; -} - -template <class T> -std::ostream& List<T>::write(std::ostream& ostr) const { - ostr.write((const char*)&length, sizeof(length)); - ostr.write((const char*)&count, sizeof(count)); - - for (int i = 0; i < count; i++) - elements[i].write(ostr); // disgusting - - return ostr; -} - -template <class T> unsigned List<T>::get_length() const { return length; } @@ -222,4 +199,31 @@ List<T>& List<T>::operator=(List&& other) { return *this; } +/* Other */ + +template <typename T> +std::istream& operator>>(std::istream& istr, List<T>& obj) { + istr.read((char*)&length, sizeof(length)); + istr.read((char*)&count, sizeof(count)); + + delete[] elements; + elements = new T[length]; + + for (int i = 0; i < count; i++) + elements[i].read(istr); // disgusting + + return istr; +} + +template <typename T> +std::ostream& operator<<(std::ostream& ostr, const List<T>& obj) { + ostr.write((const char*)&length, sizeof(length)); + ostr.write((const char*)&count, sizeof(count)); + + for (int i = 0; i < count; i++) + elements[i].write(ostr); // disgusting + + return ostr; +} + #endif diff --git a/src/Services/EventService.cpp b/src/Services/EventService.cpp index 26c9bb6..926aadf 100644 --- a/src/Services/EventService.cpp +++ b/src/Services/EventService.cpp @@ -173,7 +173,7 @@ bool cond_event_date(const Event& e, const Date& date) { } StatusCode EventService::reportReservations(const char* name, const Date& date) { - List<Reservation> result; + List<Event> result; bool (*cond_name)(const Event&, const char*) = cond_event_name; bool (*cond_date)(const Event&, const Date&) = cond_event_date; @@ -182,8 +182,15 @@ StatusCode EventService::reportReservations(const char* name, const Date& date) for (unsigned i = 0; i < events.get_count(); i++) { if (cond_name(events[i], name) && cond_date(events[i], date)) - result += events[i].get_reservations(); + result.add(events[i]); } + std::ofstream outFile("report.txt"); + if (!outFile.is_open()) + return E_FileCouldNotBeOpened; + outFile << result; + outFile.close(); + + return Success; } diff --git a/src/Services/StatusCode.h b/src/Services/StatusCode.h index a1eaa17..79c9a7e 100644 --- a/src/Services/StatusCode.h +++ b/src/Services/StatusCode.h @@ -10,6 +10,7 @@ enum StatusCode { E_Generic, E_DoesntExist, + E_FileCouldNotBeOpened, E_HallDoesntExist, |
