Add an assignment operator to Uuid and support serialization with QDataStream.

This commit is contained in:
Felix Geyer 2012-04-25 00:15:40 +02:00
parent d5cd0dcd14
commit 9e0a6ad2d8
2 changed files with 27 additions and 0 deletions

View File

@ -60,6 +60,13 @@ bool Uuid::isNull() const
return true; return true;
} }
Uuid& Uuid::operator=(const Uuid& other)
{
m_data = other.m_data;
return *this;
}
bool Uuid::operator==(const Uuid& other) const bool Uuid::operator==(const Uuid& other) const
{ {
return m_data == other.m_data; return m_data == other.m_data;
@ -80,3 +87,19 @@ uint qHash(const Uuid& key)
{ {
return qHash(key.toByteArray()); 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;
}

View File

@ -30,6 +30,7 @@ public:
QString toBase64() const; QString toBase64() const;
QByteArray toByteArray() const; QByteArray toByteArray() const;
bool isNull() const; bool isNull() const;
Uuid& operator=(const Uuid& other);
bool operator==(const Uuid& other) const; bool operator==(const Uuid& other) const;
bool operator!=(const Uuid& other) const; bool operator!=(const Uuid& other) const;
static const int LENGTH; static const int LENGTH;
@ -43,4 +44,7 @@ Q_DECLARE_TYPEINFO(Uuid, Q_MOVABLE_TYPE);
uint qHash(const Uuid& key); uint qHash(const Uuid& key);
QDataStream& operator<<(QDataStream& stream, const Uuid& uuid);
QDataStream& operator>>(QDataStream& stream, Uuid& uuid);
#endif // KEEPASSX_UUID_H #endif // KEEPASSX_UUID_H