From 9e0a6ad2d87b36440aea19b81654743c9e845ed3 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Wed, 25 Apr 2012 00:15:40 +0200 Subject: [PATCH] Add an assignment operator to Uuid and support serialization with QDataStream. --- src/core/Uuid.cpp | 23 +++++++++++++++++++++++ src/core/Uuid.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/src/core/Uuid.cpp b/src/core/Uuid.cpp index a97b9585a..eba0d7fdb 100644 --- a/src/core/Uuid.cpp +++ b/src/core/Uuid.cpp @@ -60,6 +60,13 @@ bool Uuid::isNull() const return true; } +Uuid& Uuid::operator=(const Uuid& other) +{ + m_data = other.m_data; + + return *this; +} + bool Uuid::operator==(const Uuid& other) const { return m_data == other.m_data; @@ -80,3 +87,19 @@ uint qHash(const Uuid& key) { return qHash(key.toByteArray()); } + +QDataStream& operator<<(QDataStream& stream, const Uuid& uuid) +{ + return stream << uuid.toByteArray(); +} + +QDataStream& operator>>(QDataStream& stream, Uuid& uuid) +{ + QByteArray data; + stream >> data; + if (data.size() == Uuid::LENGTH) { + uuid = Uuid(data); + } + + return stream; +} diff --git a/src/core/Uuid.h b/src/core/Uuid.h index 3af28119c..2d4223973 100644 --- a/src/core/Uuid.h +++ b/src/core/Uuid.h @@ -30,6 +30,7 @@ public: QString toBase64() const; QByteArray toByteArray() const; bool isNull() const; + Uuid& operator=(const Uuid& other); bool operator==(const Uuid& other) const; bool operator!=(const Uuid& other) const; static const int LENGTH; @@ -43,4 +44,7 @@ Q_DECLARE_TYPEINFO(Uuid, Q_MOVABLE_TYPE); uint qHash(const Uuid& key); +QDataStream& operator<<(QDataStream& stream, const Uuid& uuid); +QDataStream& operator>>(QDataStream& stream, Uuid& uuid); + #endif // KEEPASSX_UUID_H