Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Generic
diff options
context:
space:
mode:
Commitc8e3d1a1a5dbaf4503df950fdae05b69d8744e70 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-07 16:18:40 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-07 16:18:40 +0300
Files7199559b62f932468b0fbb9fff4a112494048e49 /src/Generic
FMI-OOP-P1_TicketSystem-c8e3d1a1a5dbaf4503df950fdae05b69d8744e70.tar
FMI-OOP-P1_TicketSystem-c8e3d1a1a5dbaf4503df950fdae05b69d8744e70.tar.gz
FMI-OOP-P1_TicketSystem-c8e3d1a1a5dbaf4503df950fdae05b69d8744e70.zip
Parent3c06670e4080526ab739bb37957cde1f68c20540 (diff)
Autocommit at 07.05.2022 @ 16:18
1 files changed, 31 insertions, 4 deletions
-rw-r--r--src/Generic/List/List.hpp35
diff --git a/src/Generic/List/List.hpp b/src/Generic/List/List.hpp
index 4530083..5bbda8a 100644
--- a/src/Generic/List/List.hpp
+++ b/src/Generic/List/List.hpp
@@ -27,6 +27,9 @@ 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;
@@ -142,6 +145,31 @@ 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);
+
+ 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);
+
+ return ostr;
+}
+
+template <class T>
unsigned List<T>::get_length() const {
return length;
}
@@ -201,8 +229,7 @@ List<T>& List<T>::operator=(List&& other) {
template <typename T>
std::istream& operator>>(std::istream& istr, List<T>& obj) {
- istr.read((char*)&obj.length, sizeof(obj.length));
- istr.read((char*)&obj.count, sizeof(obj.count));
+ istr >> obj.length >> obj.count;
delete[] obj.elements;
obj.elements = new T[obj.length];
@@ -215,8 +242,7 @@ std::istream& operator>>(std::istream& istr, List<T>& obj) {
template <typename T>
std::ostream& operator<<(std::ostream& ostr, const List<T>& obj) {
- ostr.write((const char*)&obj.length, sizeof(obj.length));
- ostr.write((const char*)&obj.count, sizeof(obj.count));
+ ostr << obj.length << obj.count;
for (int i = 0; i < obj.count; i++)
ostr << obj.elements[i];
@@ -224,4 +250,5 @@ std::ostream& operator<<(std::ostream& ostr, const List<T>& obj) {
return ostr;
}
+
#endif