Changeset View
Changeset View
Standalone View
Standalone View
common/storage/key.cpp
Show All 40 Lines | |||||
41 | QDebug &operator<<(QDebug &dbg, const Key &key) | 41 | QDebug &operator<<(QDebug &dbg, const Key &key) | ||
42 | { | 42 | { | ||
43 | dbg << key.toDisplayString(); | 43 | dbg << key.toDisplayString(); | ||
44 | return dbg; | 44 | return dbg; | ||
45 | } | 45 | } | ||
46 | 46 | | |||
47 | // Identifier | 47 | // Identifier | ||
48 | 48 | | |||
49 | Identifier Identifier::createIdentifier() | ||||
50 | { | ||||
51 | return Identifier(QUuid::createUuid()); | ||||
52 | } | ||||
53 | | ||||
49 | QByteArray Identifier::toInternalByteArray() const | 54 | QByteArray Identifier::toInternalByteArray() const | ||
50 | { | 55 | { | ||
56 | Q_ASSERT(!uid.isNull()); | ||||
51 | return uid.toRfc4122(); | 57 | return uid.toRfc4122(); | ||
52 | } | 58 | } | ||
53 | 59 | | |||
54 | Identifier Identifier::fromInternalByteArray(const QByteArray &bytes) | 60 | Identifier Identifier::fromInternalByteArray(const QByteArray &bytes) | ||
55 | { | 61 | { | ||
56 | Q_ASSERT(bytes.size() == INTERNAL_REPR_SIZE); | 62 | Q_ASSERT(bytes.size() == INTERNAL_REPR_SIZE); | ||
57 | return Identifier(QUuid::fromRfc4122(bytes)); | 63 | return Identifier(QUuid::fromRfc4122(bytes)); | ||
58 | } | 64 | } | ||
Show All 9 Lines | |||||
68 | } | 74 | } | ||
69 | 75 | | |||
70 | Identifier Identifier::fromDisplayByteArray(const QByteArray &bytes) | 76 | Identifier Identifier::fromDisplayByteArray(const QByteArray &bytes) | ||
71 | { | 77 | { | ||
72 | Q_ASSERT(bytes.size() == DISPLAY_REPR_SIZE); | 78 | Q_ASSERT(bytes.size() == DISPLAY_REPR_SIZE); | ||
73 | return Identifier(QUuid(bytes)); | 79 | return Identifier(QUuid(bytes)); | ||
74 | } | 80 | } | ||
75 | 81 | | |||
82 | bool Identifier::isNull() const | ||||
83 | { | ||||
84 | return uid.isNull(); | ||||
85 | } | ||||
86 | | ||||
87 | bool Identifier::operator==(const Identifier &other) const | ||||
88 | { | ||||
89 | return uid == other.uid; | ||||
90 | } | ||||
91 | | ||||
92 | bool Identifier::operator!=(const Identifier &other) const | ||||
93 | { | ||||
94 | return !(*this == other); | ||||
95 | } | ||||
96 | | ||||
76 | // Revision | 97 | // Revision | ||
77 | 98 | | |||
78 | QByteArray Revision::toInternalByteArray() const | 99 | QByteArray Revision::toInternalByteArray() const | ||
79 | { | 100 | { | ||
80 | return padNumber(rev); | 101 | return padNumber(rev); | ||
81 | } | 102 | } | ||
82 | 103 | | |||
83 | Revision Revision::fromInternalByteArray(const QByteArray &bytes) | 104 | Revision Revision::fromInternalByteArray(const QByteArray &bytes) | ||
Show All 18 Lines | 121 | { | |||
102 | return fromInternalByteArray(bytes); | 123 | return fromInternalByteArray(bytes); | ||
103 | } | 124 | } | ||
104 | 125 | | |||
105 | qint64 Revision::toQint64() const | 126 | qint64 Revision::toQint64() const | ||
106 | { | 127 | { | ||
107 | return rev; | 128 | return rev; | ||
108 | } | 129 | } | ||
109 | 130 | | |||
131 | bool Revision::operator==(const Revision &other) const | ||||
132 | { | ||||
133 | return rev == other.rev; | ||||
134 | } | ||||
135 | | ||||
136 | bool Revision::operator!=(const Revision &other) const | ||||
137 | { | ||||
138 | return !(*this == other); | ||||
139 | } | ||||
140 | | ||||
110 | // Key | 141 | // Key | ||
111 | 142 | | |||
112 | QByteArray Key::toInternalByteArray() const | 143 | QByteArray Key::toInternalByteArray() const | ||
113 | { | 144 | { | ||
114 | return id.toInternalByteArray() + rev.toInternalByteArray(); | 145 | return id.toInternalByteArray() + rev.toInternalByteArray(); | ||
115 | } | 146 | } | ||
116 | 147 | | |||
117 | Key Key::fromInternalByteArray(const QByteArray &bytes) | 148 | Key Key::fromInternalByteArray(const QByteArray &bytes) | ||
Show All 31 Lines | |||||
149 | { | 180 | { | ||
150 | return rev; | 181 | return rev; | ||
151 | } | 182 | } | ||
152 | 183 | | |||
153 | void Key::setRevision(const Revision &newRev) | 184 | void Key::setRevision(const Revision &newRev) | ||
154 | { | 185 | { | ||
155 | rev = newRev; | 186 | rev = newRev; | ||
156 | } | 187 | } | ||
188 | | ||||
189 | bool Key::isNull() const | ||||
190 | { | ||||
191 | return id.isNull(); | ||||
192 | } | ||||
193 | | ||||
194 | bool Key::operator==(const Key &other) const | ||||
195 | { | ||||
196 | return (id == other.id) && (rev == other.rev); | ||||
197 | } | ||||
198 | | ||||
199 | bool Key::operator!=(const Key &other) const | ||||
200 | { | ||||
201 | return !(*this == other); | ||||
202 | } | ||||
203 | |