diff --git a/entities/ISerializable.h b/entities/ISerializable.h index b1d5022..f116eee 100644 --- a/entities/ISerializable.h +++ b/entities/ISerializable.h @@ -8,16 +8,6 @@ class ISerializable { public: virtual void serialize(QDataStream &output) = 0; virtual void deserialize(QDataStream &input) = 0; - - friend QDataStream &operator<<(QDataStream &output, ISerializable &s) { - s.serialize(output); - return output; - } - - friend QDataStream &operator>>(QDataStream &input, ISerializable &s) { - s.deserialize(input); - return input; - } }; #endif // ISERIALIZABLE_H diff --git a/entities/cargo_entity.cpp b/entities/cargo_entity.cpp index b24a177..27d37f8 100644 --- a/entities/cargo_entity.cpp +++ b/entities/cargo_entity.cpp @@ -1,6 +1,6 @@ #include "cargo_entity.h" -cargo_entity::cargo_entity(const QString &title, int volume) : _title(title), _volume(volume) { +cargo_entity::cargo_entity(const QString &title, unsigned int volume) : _title(title), _volume(volume) { this->_id = volume; auto hash = QCryptographicHash::hash(title.toLocal8Bit(), QCryptographicHash::Md5); for (auto bit : hash) { diff --git a/entities/cargo_entity.h b/entities/cargo_entity.h index cbf00c8..ab5e043 100644 --- a/entities/cargo_entity.h +++ b/entities/cargo_entity.h @@ -15,7 +15,7 @@ private: public: cargo_entity() = default; - cargo_entity(const QString &title, int volume); + cargo_entity(const QString &title, unsigned int volume); unsigned long long id(); QString title(); diff --git a/entities/storage_entity.cpp b/entities/storage_entity.cpp index 83f65a1..31f34d6 100644 --- a/entities/storage_entity.cpp +++ b/entities/storage_entity.cpp @@ -21,9 +21,17 @@ const QVector storage_entity::cargo() { } void storage_entity::serialize(QDataStream &output) { - output << this->_id << this->_capacity << this->_cargo; + output << this->_id << this->_capacity << this->_cargo.size(); + for (auto item : this->_cargo) { + item.serialize(output); + } } void storage_entity::deserialize(QDataStream &input) { - input >> this->_id >> this->_capacity >> this->_cargo; + int icnt; + input >> this->_id >> this->_capacity >> icnt; + this->_cargo.resize(icnt); + for (int i = 0; i < icnt; i++) { + this->_cargo[i].deserialize(input); + } } diff --git a/entities/vessel_entity.cpp b/entities/vessel_entity.cpp index a5b99a0..aeafd91 100644 --- a/entities/vessel_entity.cpp +++ b/entities/vessel_entity.cpp @@ -24,9 +24,21 @@ const QVector vessel_entity::cargo() { } void vessel_entity::serialize(QDataStream &output) { - output << this->_id << this->_harbor << this->_capacity << this->_cargo; + output << this->_id; + this->_harbor.serialize(output); + output << this->_capacity << this->_cargo.size(); + for (auto item : this->_cargo) { + item.serialize(output); + } } void vessel_entity::deserialize(QDataStream &input) { - input >> this->_id >> this->_harbor >> this->_capacity >> this->_cargo; + input >> this->_id; + this->_harbor.deserialize(input); + int icnt; + input >> this->_capacity >> icnt; + this->_cargo.resize(icnt); + for (int i = 0; i < icnt; i++) { + this->_cargo[i].deserialize(input); + } }