2010-08-07 15:10:44 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Uuid.h"
|
|
|
|
|
2010-08-14 12:28:52 +02:00
|
|
|
#include <QtCore/QHash>
|
|
|
|
|
2010-08-12 21:38:59 +02:00
|
|
|
const int Uuid::length = 16;
|
|
|
|
|
2010-08-24 23:12:01 +02:00
|
|
|
Uuid::Uuid()
|
|
|
|
: m_data(length, 0)
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Uuid::Uuid(const QByteArray& data)
|
|
|
|
{
|
|
|
|
Q_ASSERT(data.size() == 16);
|
|
|
|
|
|
|
|
m_data = data;
|
|
|
|
}
|
|
|
|
|
2010-08-14 12:44:55 +02:00
|
|
|
Uuid Uuid::random() {
|
|
|
|
QByteArray randomAray;
|
|
|
|
// TODO fill with random data
|
2010-08-15 15:03:47 +02:00
|
|
|
randomAray.fill(1, 16);
|
2010-08-14 12:44:55 +02:00
|
|
|
return Uuid(randomAray);
|
|
|
|
}
|
|
|
|
|
2010-08-13 18:08:06 +02:00
|
|
|
QString Uuid::toBase64() const
|
2010-08-07 15:10:44 +02:00
|
|
|
{
|
2010-08-13 18:08:06 +02:00
|
|
|
return m_data.toBase64();
|
2010-08-07 15:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray Uuid::toByteArray() const
|
|
|
|
{
|
|
|
|
return m_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Uuid::isNull() const
|
|
|
|
{
|
|
|
|
for (int i=0; i<m_data.size(); ++i) {
|
|
|
|
if (m_data[i] != 0)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Uuid::operator==(const Uuid& other) const
|
|
|
|
{
|
|
|
|
return m_data == other.m_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Uuid::operator!=(const Uuid& other) const
|
|
|
|
{
|
|
|
|
return !operator==(other);
|
|
|
|
}
|
|
|
|
|
2010-08-25 21:14:41 +02:00
|
|
|
Uuid Uuid::fromBase64(const QString& str)
|
|
|
|
{
|
|
|
|
QByteArray data = QByteArray::fromBase64(str.toAscii());
|
|
|
|
return Uuid(data);
|
|
|
|
}
|
|
|
|
|
2010-08-07 15:10:44 +02:00
|
|
|
uint qHash(const Uuid& key)
|
|
|
|
{
|
|
|
|
return qHash(key.toByteArray());
|
|
|
|
}
|