From 0e54657272477ad779cc5c0e3f843b9f01b5e928 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Thu, 19 Jul 2018 10:08:39 +0200 Subject: Default constructor of Identifier produces null + safety net --- common/storage/key.cpp | 6 ++++++ common/storage/key.h | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/common/storage/key.cpp b/common/storage/key.cpp index 01a3e3a..4dacca2 100644 --- a/common/storage/key.cpp +++ b/common/storage/key.cpp @@ -46,8 +46,14 @@ QDebug &operator<<(QDebug &dbg, const Key &key) // Identifier +Identifier Identifier::createIdentifier() +{ + return Identifier(QUuid::createUuid()); +} + QByteArray Identifier::toInternalByteArray() const { + Q_ASSERT(!uid.isNull()); return uid.toRfc4122(); } diff --git a/common/storage/key.h b/common/storage/key.h index 40f4aca..151c333 100644 --- a/common/storage/key.h +++ b/common/storage/key.h @@ -37,7 +37,8 @@ public: static const constexpr size_t INTERNAL_REPR_SIZE = 16; static const constexpr size_t DISPLAY_REPR_SIZE = 38; - Identifier() : uid(QUuid::createUuid()){}; + Identifier() = default; + static Identifier createIdentifier(); QByteArray toInternalByteArray() const; static Identifier fromInternalByteArray(const QByteArray &bytes); @@ -76,8 +77,6 @@ public: static const constexpr size_t INTERNAL_REPR_SIZE = Identifier::INTERNAL_REPR_SIZE + Revision::INTERNAL_REPR_SIZE; static const constexpr size_t DISPLAY_REPR_SIZE = Identifier::DISPLAY_REPR_SIZE + Revision::DISPLAY_REPR_SIZE; - // Just to be able to store keys into Qt containers - [[deprecated("Don't use the default constructor")]] Key() : id(), rev(0) {} Key(const Identifier &id, const Revision &rev) : id(id), rev(rev) {} -- cgit v1.2.3