plugin/quuid.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtCore module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "quuid.h" -
43 -
44#include "qdatastream.h" -
45#include "qendian.h" -
46#include "qdebug.h" -
47 -
48#ifndef QT_BOOTSTRAPPED -
49#include "qcryptographichash.h" -
50#endif -
51QT_BEGIN_NAMESPACE -
52 -
53template <class Char, class Integral> -
54void _q_toHex(Char *&dst, Integral value) -
55{ -
56 static const char digits[] = "0123456789abcdef"; -
57 -
58 value = qToBigEndian(value);
executed (the execution status of this line is deduced): value = qToBigEndian(value);
-
59 -
60 const char* p = reinterpret_cast<const char*>(&value);
executed (the execution status of this line is deduced): const char* p = reinterpret_cast<const char*>(&value);
-
61 -
62 for (uint i = 0; i < sizeof(Integral); ++i, dst += 2) {
evaluated: i < sizeof(Integral)
TRUEFALSE
yes
Evaluation Count:20128
yes
Evaluation Count:13838
13838-20128
63 uint j = (p[i] >> 4) & 0xf;
executed (the execution status of this line is deduced): uint j = (p[i] >> 4) & 0xf;
-
64 dst[0] = Char(digits[j]);
executed (the execution status of this line is deduced): dst[0] = Char(digits[j]);
-
65 j = p[i] & 0xf;
executed (the execution status of this line is deduced): j = p[i] & 0xf;
-
66 dst[1] = Char(digits[j]);
executed (the execution status of this line is deduced): dst[1] = Char(digits[j]);
-
67 }
executed: }
Execution Count:20128
20128
68}
executed: }
Execution Count:13838
13838
69 -
70template <class Char, class Integral> -
71bool _q_fromHex(const Char *&src, Integral &value) -
72{ -
73 value = 0;
executed (the execution status of this line is deduced): value = 0;
-
74 -
75 for (uint i = 0; i < sizeof(Integral) * 2; ++i) {
evaluated: i < sizeof(Integral) * 2
TRUEFALSE
yes
Evaluation Count:714
yes
Evaluation Count:236
236-714
76 int ch = *src++;
executed (the execution status of this line is deduced): int ch = *src++;
-
77 int tmp;
executed (the execution status of this line is deduced): int tmp;
-
78 if (ch >= '0' && ch <= '9')
evaluated: ch >= '0'
TRUEFALSE
yes
Evaluation Count:711
yes
Evaluation Count:3
evaluated: ch <= '9'
TRUEFALSE
yes
Evaluation Count:435
yes
Evaluation Count:276
3-711
79 tmp = ch - '0';
executed: tmp = ch - '0';
Execution Count:435
435
80 else if (ch >= 'a' && ch <= 'f')
evaluated: ch >= 'a'
TRUEFALSE
yes
Evaluation Count:276
yes
Evaluation Count:3
partially evaluated: ch <= 'f'
TRUEFALSE
yes
Evaluation Count:276
no
Evaluation Count:0
0-276
81 tmp = ch - 'a' + 10;
executed: tmp = ch - 'a' + 10;
Execution Count:276
276
82 else if (ch >= 'A' && ch <= 'F')
partially evaluated: ch >= 'A'
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
never evaluated: ch <= 'F'
0-3
83 tmp = ch - 'A' + 10;
never executed: tmp = ch - 'A' + 10;
0
84 else -
85 return false;
executed: return false;
Execution Count:3
3
86 -
87 value = value * 16 + tmp;
executed (the execution status of this line is deduced): value = value * 16 + tmp;
-
88 }
executed: }
Execution Count:711
711
89 -
90 return true;
executed: return true;
Execution Count:236
236
91} -
92 -
93template <class Char> -
94void _q_uuidToHex(Char *&dst, const uint &d1, const ushort &d2, const ushort &d3, const uchar (&d4)[8]) -
95{ -
96 *dst++ = Char('{');
executed (the execution status of this line is deduced): *dst++ = Char('{');
-
97 _q_toHex(dst, d1);
executed (the execution status of this line is deduced): _q_toHex(dst, d1);
-
98 *dst++ = Char('-');
executed (the execution status of this line is deduced): *dst++ = Char('-');
-
99 _q_toHex(dst, d2);
executed (the execution status of this line is deduced): _q_toHex(dst, d2);
-
100 *dst++ = Char('-');
executed (the execution status of this line is deduced): *dst++ = Char('-');
-
101 _q_toHex(dst, d3);
executed (the execution status of this line is deduced): _q_toHex(dst, d3);
-
102 *dst++ = Char('-');
executed (the execution status of this line is deduced): *dst++ = Char('-');
-
103 for (int i = 0; i < 2; i++)
evaluated: i < 2
TRUEFALSE
yes
Evaluation Count:2516
yes
Evaluation Count:1258
1258-2516
104 _q_toHex(dst, d4[i]);
executed: _q_toHex(dst, d4[i]);
Execution Count:2516
2516
105 *dst++ = Char('-');
executed (the execution status of this line is deduced): *dst++ = Char('-');
-
106 for (int i = 2; i < 8; i++)
evaluated: i < 8
TRUEFALSE
yes
Evaluation Count:7548
yes
Evaluation Count:1258
1258-7548
107 _q_toHex(dst, d4[i]);
executed: _q_toHex(dst, d4[i]);
Execution Count:7548
7548
108 *dst = Char('}');
executed (the execution status of this line is deduced): *dst = Char('}');
-
109}
executed: }
Execution Count:1258
1258
110 -
111template <class Char> -
112bool _q_uuidFromHex(const Char *&src, uint &d1, ushort &d2, ushort &d3, uchar (&d4)[8]) -
113{ -
114 if (*src == Char('{'))
evaluated: *src == Char('{')
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:9
9-16
115 src++;
executed: src++;
Execution Count:16
16
116 if (!_q_fromHex(src, d1)
evaluated: !_q_fromHex(src, d1)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:24
1-24
117 || *src++ != Char('-')
partially evaluated: *src++ != Char('-')
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:24
0-24
118 || !_q_fromHex(src, d2)
partially evaluated: !_q_fromHex(src, d2)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:24
0-24
119 || *src++ != Char('-')
evaluated: *src++ != Char('-')
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:22
2-22
120 || !_q_fromHex(src, d3)
evaluated: !_q_fromHex(src, d3)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:21
1-21
121 || *src++ != Char('-')
partially evaluated: *src++ != Char('-')
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21
0-21
122 || !_q_fromHex(src, d4[0])
partially evaluated: !_q_fromHex(src, d4[0])
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21
0-21
123 || !_q_fromHex(src, d4[1])
partially evaluated: !_q_fromHex(src, d4[1])
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21
0-21
124 || *src++ != Char('-')
partially evaluated: *src++ != Char('-')
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21
0-21
125 || !_q_fromHex(src, d4[2])
partially evaluated: !_q_fromHex(src, d4[2])
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21
0-21
126 || !_q_fromHex(src, d4[3])
partially evaluated: !_q_fromHex(src, d4[3])
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21
0-21
127 || !_q_fromHex(src, d4[4])
partially evaluated: !_q_fromHex(src, d4[4])
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21
0-21
128 || !_q_fromHex(src, d4[5])
partially evaluated: !_q_fromHex(src, d4[5])
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21
0-21
129 || !_q_fromHex(src, d4[6])
partially evaluated: !_q_fromHex(src, d4[6])
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:21
0-21
130 || !_q_fromHex(src, d4[7])) {
evaluated: !_q_fromHex(src, d4[7])
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:20
1-20
131 return false;
executed: return false;
Execution Count:5
5
132 } -
133 -
134 return true;
executed: return true;
Execution Count:20
20
135} -
136 -
137#ifndef QT_BOOTSTRAPPED -
138static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCryptographicHash::Algorithm algorithm, int version) -
139{ -
140 QByteArray hashResult;
executed (the execution status of this line is deduced): QByteArray hashResult;
-
141 -
142 // create a scope so later resize won't reallocate -
143 { -
144 QCryptographicHash hash(algorithm);
executed (the execution status of this line is deduced): QCryptographicHash hash(algorithm);
-
145 hash.addData(ns.toRfc4122());
executed (the execution status of this line is deduced): hash.addData(ns.toRfc4122());
-
146 hash.addData(baseData);
executed (the execution status of this line is deduced): hash.addData(baseData);
-
147 hashResult = hash.result();
executed (the execution status of this line is deduced): hashResult = hash.result();
-
148 } -
149 hashResult.resize(16); // Sha1 will be too long
executed (the execution status of this line is deduced): hashResult.resize(16);
-
150 -
151 QUuid result = QUuid::fromRfc4122(hashResult);
executed (the execution status of this line is deduced): QUuid result = QUuid::fromRfc4122(hashResult);
-
152 -
153 result.data3 &= 0x0FFF;
executed (the execution status of this line is deduced): result.data3 &= 0x0FFF;
-
154 result.data3 |= (version << 12);
executed (the execution status of this line is deduced): result.data3 |= (version << 12);
-
155 result.data4[0] &= 0x3F;
executed (the execution status of this line is deduced): result.data4[0] &= 0x3F;
-
156 result.data4[0] |= 0x80;
executed (the execution status of this line is deduced): result.data4[0] |= 0x80;
-
157 -
158 return result;
executed: return result;
Execution Count:4
4
159} -
160#endif -
161 -
162/*! -
163 \class QUuid -
164 \inmodule QtCore -
165 \brief The QUuid class stores a Universally Unique Identifier (UUID). -
166 -
167 \reentrant -
168 -
169 Using \e{U}niversally \e{U}nique \e{ID}entifiers (UUID) is a -
170 standard way to uniquely identify entities in a distributed -
171 computing environment. A UUID is a 16-byte (128-bit) number -
172 generated by some algorithm that is meant to guarantee that the -
173 UUID will be unique in the distributed computing environment where -
174 it is used. The acronym GUID is often used instead, \e{G}lobally -
175 \e{U}nique \e{ID}entifiers, but it refers to the same thing. -
176 -
177 \target Variant field -
178 Actually, the GUID is one \e{variant} of UUID. Multiple variants -
179 are in use. Each UUID contains a bit field that specifies which -
180 type (variant) of UUID it is. Call variant() to discover which -
181 type of UUID an instance of QUuid contains. It extracts the three -
182 most significant bits of byte 8 of the 16 bytes. In QUuid, byte 8 -
183 is \c{QUuid::data4[0]}. If you create instances of QUuid using the -
184 constructor that accepts all the numeric values as parameters, use -
185 the following table to set the three most significant bits of -
186 parameter \c{b1}, which becomes \c{QUuid::data4[0]} and contains -
187 the variant field in its three most significant bits. In the -
188 table, 'x' means \e {don't care}. -
189 -
190 \table -
191 \header -
192 \li msb0 -
193 \li msb1 -
194 \li msb2 -
195 \li Variant -
196 -
197 \row -
198 \li 0 -
199 \li x -
200 \li x -
201 \li NCS (Network Computing System) -
202 -
203 \row -
204 \li 1 -
205 \li 0 -
206 \li x -
207 \li DCE (Distributed Computing Environment) -
208 -
209 \row -
210 \li 1 -
211 \li 1 -
212 \li 0 -
213 \li Microsoft (GUID) -
214 -
215 \row -
216 \li 1 -
217 \li 1 -
218 \li 1 -
219 \li Reserved for future expansion -
220 -
221 \endtable -
222 -
223 \target Version field -
224 If variant() returns QUuid::DCE, the UUID also contains a -
225 \e{version} field in the four most significant bits of -
226 \c{QUuid::data3}, and you can call version() to discover which -
227 version your QUuid contains. If you create instances of QUuid -
228 using the constructor that accepts all the numeric values as -
229 parameters, use the following table to set the four most -
230 significant bits of parameter \c{w2}, which becomes -
231 \c{QUuid::data3} and contains the version field in its four most -
232 significant bits. -
233 -
234 \table -
235 \header -
236 \li msb0 -
237 \li msb1 -
238 \li msb2 -
239 \li msb3 -
240 \li Version -
241 -
242 \row -
243 \li 0 -
244 \li 0 -
245 \li 0 -
246 \li 1 -
247 \li Time -
248 -
249 \row -
250 \li 0 -
251 \li 0 -
252 \li 1 -
253 \li 0 -
254 \li Embedded POSIX -
255 -
256 \row -
257 \li 0 -
258 \li 0 -
259 \li 1 -
260 \li 1 -
261 \li Md5(Name) -
262 -
263 \row -
264 \li 0 -
265 \li 1 -
266 \li 0 -
267 \li 0 -
268 \li Random -
269 -
270 \row -
271 \li 0 -
272 \li 1 -
273 \li 0 -
274 \li 1 -
275 \li Sha1 -
276 -
277 \endtable -
278 -
279 The field layouts for the DCE versions listed in the table above -
280 are specified in the \l{http://www.ietf.org/rfc/rfc4122.txt} -
281 {Network Working Group UUID Specification}. -
282 -
283 Most platforms provide a tool for generating new UUIDs, e.g. \c -
284 uuidgen and \c guidgen. You can also use createUuid(). UUIDs -
285 generated by createUuid() are of the random type. Their -
286 QUuid::Version bits are set to QUuid::Random, and their -
287 QUuid::Variant bits are set to QUuid::DCE. The rest of the UUID is -
288 composed of random numbers. Theoretically, this means there is a -
289 small chance that a UUID generated by createUuid() will not be -
290 unique. But it is -
291 \l{http://en.wikipedia.org/wiki/Universally_Unique_Identifier#Random_UUID_probability_of_duplicates} -
292 {a \e{very} small chance}. -
293 -
294 UUIDs can be constructed from numeric values or from strings, or -
295 using the static createUuid() function. They can be converted to a -
296 string with toString(). UUIDs have a variant() and a version(), -
297 and null UUIDs return true from isNull(). -
298*/ -
299 -
300/*! -
301 \fn QUuid::QUuid(const GUID &guid) -
302 -
303 Casts a Windows \a guid to a Qt QUuid. -
304 -
305 \warning This function is only for Windows platforms. -
306*/ -
307 -
308/*! -
309 \fn QUuid &QUuid::operator=(const GUID &guid) -
310 -
311 Assigns a Windows \a guid to a Qt QUuid. -
312 -
313 \warning This function is only for Windows platforms. -
314*/ -
315 -
316/*! -
317 \fn QUuid::operator GUID() const -
318 -
319 Returns a Windows GUID from a QUuid. -
320 -
321 \warning This function is only for Windows platforms. -
322*/ -
323 -
324/*! -
325 \fn QUuid::QUuid() -
326 -
327 Creates the null UUID. toString() will output the null UUID -
328 as "{00000000-0000-0000-0000-000000000000}". -
329*/ -
330 -
331/*! -
332 \fn QUuid::QUuid(uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8) -
333 -
334 Creates a UUID with the value specified by the parameters, \a l, -
335 \a w1, \a w2, \a b1, \a b2, \a b3, \a b4, \a b5, \a b6, \a b7, \a -
336 b8. -
337 -
338 Example: -
339 \snippet code/src_corelib_plugin_quuid.cpp 0 -
340*/ -
341 -
342/*! -
343 Creates a QUuid object from the string \a text, which must be -
344 formatted as five hex fields separated by '-', e.g., -
345 "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where 'x' is a hex -
346 digit. The curly braces shown here are optional, but it is normal to -
347 include them. If the conversion fails, a null UUID is created. See -
348 toString() for an explanation of how the five hex fields map to the -
349 public data members in QUuid. -
350 -
351 \sa toString(), QUuid() -
352*/ -
353QUuid::QUuid(const QString &text) -
354{ -
355 if (text.length() < 36) {
partially evaluated: text.length() < 36
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9
0-9
356 *this = QUuid();
never executed (the execution status of this line is deduced): *this = QUuid();
-
357 return;
never executed: return;
0
358 } -
359 -
360 const ushort *data = reinterpret_cast<const ushort *>(text.unicode());
executed (the execution status of this line is deduced): const ushort *data = reinterpret_cast<const ushort *>(text.unicode());
-
361 -
362 if (*data == '{' && text.length() < 37) {
evaluated: *data == '{'
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:2
evaluated: text.length() < 37
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:6
1-7
363 *this = QUuid();
executed (the execution status of this line is deduced): *this = QUuid();
-
364 return;
executed: return;
Execution Count:1
1
365 } -
366 -
367 if (!_q_uuidFromHex(data, data1, data2, data3, data4)) {
partially evaluated: !_q_uuidFromHex(data, data1, data2, data3, data4)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
368 *this = QUuid();
never executed (the execution status of this line is deduced): *this = QUuid();
-
369 return;
never executed: return;
0
370 } -
371}
executed: }
Execution Count:8
8
372 -
373/*! -
374 \internal -
375*/ -
376QUuid::QUuid(const char *text) -
377{ -
378 if (!text) {
evaluated: !text
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:12
1-12
379 *this = QUuid();
executed (the execution status of this line is deduced): *this = QUuid();
-
380 return;
executed: return;
Execution Count:1
1
381 } -
382 -
383 if (!_q_uuidFromHex(text, data1, data2, data3, data4)) {
evaluated: !_q_uuidFromHex(text, data1, data2, data3, data4)
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:7
5-7
384 *this = QUuid();
executed (the execution status of this line is deduced): *this = QUuid();
-
385 return;
executed: return;
Execution Count:5
5
386 } -
387}
executed: }
Execution Count:7
7
388 -
389/*! -
390 Creates a QUuid object from the QByteArray \a text, which must be -
391 formatted as five hex fields separated by '-', e.g., -
392 "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where 'x' is a hex -
393 digit. The curly braces shown here are optional, but it is normal to -
394 include them. If the conversion fails, a null UUID is created. See -
395 toByteArray() for an explanation of how the five hex fields map to the -
396 public data members in QUuid. -
397 -
398 \since 4.8 -
399 -
400 \sa toByteArray(), QUuid() -
401*/ -
402QUuid::QUuid(const QByteArray &text) -
403{ -
404 if (text.length() < 36) {
partially evaluated: text.length() < 36
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
405 *this = QUuid();
never executed (the execution status of this line is deduced): *this = QUuid();
-
406 return;
never executed: return;
0
407 } -
408 -
409 const char *data = text.constData();
executed (the execution status of this line is deduced): const char *data = text.constData();
-
410 -
411 if (*data == '{' && text.length() < 37) {
evaluated: *data == '{'
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:2
evaluated: text.length() < 37
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:3
1-4
412 *this = QUuid();
executed (the execution status of this line is deduced): *this = QUuid();
-
413 return;
executed: return;
Execution Count:1
1
414 } -
415 -
416 if (!_q_uuidFromHex(data, data1, data2, data3, data4)) {
partially evaluated: !_q_uuidFromHex(data, data1, data2, data3, data4)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-5
417 *this = QUuid();
never executed (the execution status of this line is deduced): *this = QUuid();
-
418 return;
never executed: return;
0
419 } -
420}
executed: }
Execution Count:5
5
421 -
422/*! -
423 \since 5.0 -
424 \fn QUuid QUuid::createUuidV3(const QUuid &ns, const QByteArray &baseData); -
425 -
426 This function returns a new UUID with variant QUuid::DCE and version QUuid::Md5. -
427 \a ns is the namespace and \a baseData is the basic data as described by RFC 4122. -
428 -
429 \sa variant(), version(), createUuidV5() -
430*/ -
431 -
432/*! -
433 \since 5.0 -
434 \fn QUuid QUuid::createUuidV3(const QUuid &ns, const QString &baseData); -
435 -
436 This function returns a new UUID with variant QUuid::DCE and version QUuid::Md5. -
437 \a ns is the namespace and \a baseData is the basic data as described by RFC 4122. -
438 -
439 \sa variant(), version(), createUuidV5() -
440*/ -
441 -
442/*! -
443 \since 5.0 -
444 \fn QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData); -
445 -
446 This function returns a new UUID with variant QUuid::DCE and version QUuid::Sha1. -
447 \a ns is the namespace and \a baseData is the basic data as described by RFC 4122. -
448 -
449 \sa variant(), version(), createUuidV3() -
450*/ -
451 -
452/*! -
453 \since 5.0 -
454 \fn QUuid QUuid::createUuidV5(const QUuid &ns, const QString &baseData); -
455 -
456 This function returns a new UUID with variant QUuid::DCE and version QUuid::Sha1. -
457 \a ns is the namespace and \a baseData is the basic data as described by RFC 4122. -
458 -
459 \sa variant(), version(), createUuidV3() -
460*/ -
461#ifndef QT_BOOTSTRAPPED -
462QUuid QUuid::createUuidV3(const QUuid &ns, const QByteArray &baseData) -
463{ -
464 return createFromName(ns, baseData, QCryptographicHash::Md5, 3);
executed: return createFromName(ns, baseData, QCryptographicHash::Md5, 3);
Execution Count:2
2
465} -
466 -
467QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData) -
468{ -
469 return createFromName(ns, baseData, QCryptographicHash::Sha1, 5);
executed: return createFromName(ns, baseData, QCryptographicHash::Sha1, 5);
Execution Count:2
2
470} -
471#endif -
472 -
473/*! -
474 Creates a QUuid object from the binary representation of the UUID, as -
475 specified by RFC 4122 section 4.1.2. See toRfc4122() for a further -
476 explanation of the order of \a bytes required. -
477 -
478 The byte array accepted is NOT a human readable format. -
479 -
480 If the conversion fails, a null UUID is created. -
481 -
482 \since 4.8 -
483 -
484 \sa toRfc4122(), QUuid() -
485*/ -
486QUuid QUuid::fromRfc4122(const QByteArray &bytes) -
487{ -
488 if (bytes.isEmpty() || bytes.length() != 16)
partially evaluated: bytes.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
partially evaluated: bytes.length() != 16
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
0-10
489 return QUuid();
never executed: return QUuid();
0
490 -
491 uint d1;
executed (the execution status of this line is deduced): uint d1;
-
492 ushort d2, d3;
executed (the execution status of this line is deduced): ushort d2, d3;
-
493 uchar d4[8];
executed (the execution status of this line is deduced): uchar d4[8];
-
494 -
495 const uchar *data = reinterpret_cast<const uchar *>(bytes.constData());
executed (the execution status of this line is deduced): const uchar *data = reinterpret_cast<const uchar *>(bytes.constData());
-
496 -
497 d1 = qFromBigEndian<quint32>(data);
executed (the execution status of this line is deduced): d1 = qFromBigEndian<quint32>(data);
-
498 data += sizeof(quint32);
executed (the execution status of this line is deduced): data += sizeof(quint32);
-
499 d2 = qFromBigEndian<quint16>(data);
executed (the execution status of this line is deduced): d2 = qFromBigEndian<quint16>(data);
-
500 data += sizeof(quint16);
executed (the execution status of this line is deduced): data += sizeof(quint16);
-
501 d3 = qFromBigEndian<quint16>(data);
executed (the execution status of this line is deduced): d3 = qFromBigEndian<quint16>(data);
-
502 data += sizeof(quint16);
executed (the execution status of this line is deduced): data += sizeof(quint16);
-
503 -
504 for (int i = 0; i < 8; ++i) {
evaluated: i < 8
TRUEFALSE
yes
Evaluation Count:80
yes
Evaluation Count:10
10-80
505 d4[i] = *(data);
executed (the execution status of this line is deduced): d4[i] = *(data);
-
506 data++;
executed (the execution status of this line is deduced): data++;
-
507 }
executed: }
Execution Count:80
80
508 -
509 return QUuid(d1, d2, d3, d4[0], d4[1], d4[2], d4[3], d4[4], d4[5], d4[6], d4[7]);
executed: return QUuid(d1, d2, d3, d4[0], d4[1], d4[2], d4[3], d4[4], d4[5], d4[6], d4[7]);
Execution Count:10
10
510} -
511 -
512/*! -
513 \fn bool QUuid::operator==(const QUuid &other) const -
514 -
515 Returns true if this QUuid and the \a other QUuid are identical; -
516 otherwise returns false. -
517*/ -
518 -
519/*! -
520 \fn bool QUuid::operator!=(const QUuid &other) const -
521 -
522 Returns true if this QUuid and the \a other QUuid are different; -
523 otherwise returns false. -
524*/ -
525 -
526/*! -
527 Returns the string representation of this QUuid. The string is -
528 formatted as five hex fields separated by '-' and enclosed in -
529 curly braces, i.e., "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where -
530 'x' is a hex digit. From left to right, the five hex fields are -
531 obtained from the four public data members in QUuid as follows: -
532 -
533 \table -
534 \header -
535 \li Field # -
536 \li Source -
537 -
538 \row -
539 \li 1 -
540 \li data1 -
541 -
542 \row -
543 \li 2 -
544 \li data2 -
545 -
546 \row -
547 \li 3 -
548 \li data3 -
549 -
550 \row -
551 \li 4 -
552 \li data4[0] .. data4[1] -
553 -
554 \row -
555 \li 5 -
556 \li data4[2] .. data4[7] -
557 -
558 \endtable -
559*/ -
560QString QUuid::toString() const -
561{ -
562 QString result(38, Qt::Uninitialized);
executed (the execution status of this line is deduced): QString result(38, Qt::Uninitialized);
-
563 ushort *data = (ushort *)result.unicode();
executed (the execution status of this line is deduced): ushort *data = (ushort *)result.unicode();
-
564 -
565 _q_uuidToHex(data, data1, data2, data3, data4);
executed (the execution status of this line is deduced): _q_uuidToHex(data, data1, data2, data3, data4);
-
566 -
567 return result;
executed: return result;
Execution Count:9
9
568} -
569 -
570/*! -
571 Returns the binary representation of this QUuid. The byte array is -
572 formatted as five hex fields separated by '-' and enclosed in -
573 curly braces, i.e., "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where -
574 'x' is a hex digit. From left to right, the five hex fields are -
575 obtained from the four public data members in QUuid as follows: -
576 -
577 \table -
578 \header -
579 \li Field # -
580 \li Source -
581 -
582 \row -
583 \li 1 -
584 \li data1 -
585 -
586 \row -
587 \li 2 -
588 \li data2 -
589 -
590 \row -
591 \li 3 -
592 \li data3 -
593 -
594 \row -
595 \li 4 -
596 \li data4[0] .. data4[1] -
597 -
598 \row -
599 \li 5 -
600 \li data4[2] .. data4[7] -
601 -
602 \endtable -
603 -
604 \since 4.8 -
605*/ -
606QByteArray QUuid::toByteArray() const -
607{ -
608 QByteArray result(38, Qt::Uninitialized);
executed (the execution status of this line is deduced): QByteArray result(38, Qt::Uninitialized);
-
609 char *data = result.data();
executed (the execution status of this line is deduced): char *data = result.data();
-
610 -
611 _q_uuidToHex(data, data1, data2, data3, data4);
executed (the execution status of this line is deduced): _q_uuidToHex(data, data1, data2, data3, data4);
-
612 -
613 return result;
executed: return result;
Execution Count:1249
1249
614} -
615 -
616/*! -
617 Returns the binary representation of this QUuid. The byte array is in big -
618 endian format, and formatted according to RFC 4122, section 4.1.2 - -
619 "Layout and byte order". -
620 -
621 The order is as follows: -
622 -
623 \table -
624 \header -
625 \li Field # -
626 \li Source -
627 -
628 \row -
629 \li 1 -
630 \li data1 -
631 -
632 \row -
633 \li 2 -
634 \li data2 -
635 -
636 \row -
637 \li 3 -
638 \li data3 -
639 -
640 \row -
641 \li 4 -
642 \li data4[0] .. data4[7] -
643 -
644 \endtable -
645 -
646 \since 4.8 -
647*/ -
648QByteArray QUuid::toRfc4122() const -
649{ -
650 // we know how many bytes a UUID has, I hope :) -
651 QByteArray bytes(16, Qt::Uninitialized);
executed (the execution status of this line is deduced): QByteArray bytes(16, Qt::Uninitialized);
-
652 uchar *data = reinterpret_cast<uchar*>(bytes.data());
executed (the execution status of this line is deduced): uchar *data = reinterpret_cast<uchar*>(bytes.data());
-
653 -
654 qToBigEndian(data1, data);
executed (the execution status of this line is deduced): qToBigEndian(data1, data);
-
655 data += sizeof(quint32);
executed (the execution status of this line is deduced): data += sizeof(quint32);
-
656 qToBigEndian(data2, data);
executed (the execution status of this line is deduced): qToBigEndian(data2, data);
-
657 data += sizeof(quint16);
executed (the execution status of this line is deduced): data += sizeof(quint16);
-
658 qToBigEndian(data3, data);
executed (the execution status of this line is deduced): qToBigEndian(data3, data);
-
659 data += sizeof(quint16);
executed (the execution status of this line is deduced): data += sizeof(quint16);
-
660 -
661 for (int i = 0; i < 8; ++i) {
evaluated: i < 8
TRUEFALSE
yes
Evaluation Count:72
yes
Evaluation Count:9
9-72
662 *(data) = data4[i];
executed (the execution status of this line is deduced): *(data) = data4[i];
-
663 data++;
executed (the execution status of this line is deduced): data++;
-
664 }
executed: }
Execution Count:72
72
665 -
666 return bytes;
executed: return bytes;
Execution Count:9
9
667} -
668 -
669#ifndef QT_NO_DATASTREAM -
670/*! -
671 \relates QUuid -
672 Writes the UUID \a id to the data stream \a s. -
673*/ -
674QDataStream &operator<<(QDataStream &s, const QUuid &id) -
675{ -
676 QByteArray bytes;
executed (the execution status of this line is deduced): QByteArray bytes;
-
677 if (s.byteOrder() == QDataStream::BigEndian) {
evaluated: s.byteOrder() == QDataStream::BigEndian
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1
1-3
678 bytes = id.toRfc4122();
executed (the execution status of this line is deduced): bytes = id.toRfc4122();
-
679 } else {
executed: }
Execution Count:3
3
680 // we know how many bytes a UUID has, I hope :) -
681 bytes = QByteArray(16, Qt::Uninitialized);
executed (the execution status of this line is deduced): bytes = QByteArray(16, Qt::Uninitialized);
-
682 uchar *data = reinterpret_cast<uchar*>(bytes.data());
executed (the execution status of this line is deduced): uchar *data = reinterpret_cast<uchar*>(bytes.data());
-
683 -
684 qToLittleEndian(id.data1, data);
executed (the execution status of this line is deduced): qToLittleEndian(id.data1, data);
-
685 data += sizeof(quint32);
executed (the execution status of this line is deduced): data += sizeof(quint32);
-
686 qToLittleEndian(id.data2, data);
executed (the execution status of this line is deduced): qToLittleEndian(id.data2, data);
-
687 data += sizeof(quint16);
executed (the execution status of this line is deduced): data += sizeof(quint16);
-
688 qToLittleEndian(id.data3, data);
executed (the execution status of this line is deduced): qToLittleEndian(id.data3, data);
-
689 data += sizeof(quint16);
executed (the execution status of this line is deduced): data += sizeof(quint16);
-
690 -
691 for (int i = 0; i < 8; ++i) {
evaluated: i < 8
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:1
1-8
692 *(data) = id.data4[i];
executed (the execution status of this line is deduced): *(data) = id.data4[i];
-
693 data++;
executed (the execution status of this line is deduced): data++;
-
694 }
executed: }
Execution Count:8
8
695 }
executed: }
Execution Count:1
1
696 -
697 if (s.writeRawData(bytes.data(), 16) != 16) {
partially evaluated: s.writeRawData(bytes.data(), 16) != 16
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
698 s.setStatus(QDataStream::WriteFailed);
never executed (the execution status of this line is deduced): s.setStatus(QDataStream::WriteFailed);
-
699 }
never executed: }
0
700 return s;
executed: return s;
Execution Count:4
4
701} -
702 -
703/*! -
704 \relates QUuid -
705 Reads a UUID from the stream \a s into \a id. -
706*/ -
707QDataStream &operator>>(QDataStream &s, QUuid &id) -
708{ -
709 QByteArray bytes(16, Qt::Uninitialized);
executed (the execution status of this line is deduced): QByteArray bytes(16, Qt::Uninitialized);
-
710 if (s.readRawData(bytes.data(), 16) != 16) {
evaluated: s.readRawData(bytes.data(), 16) != 16
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:5
2-5
711 s.setStatus(QDataStream::ReadPastEnd);
executed (the execution status of this line is deduced): s.setStatus(QDataStream::ReadPastEnd);
-
712 return s;
executed: return s;
Execution Count:2
2
713 } -
714 -
715 if (s.byteOrder() == QDataStream::BigEndian) {
evaluated: s.byteOrder() == QDataStream::BigEndian
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:1
1-4
716 id = QUuid::fromRfc4122(bytes);
executed (the execution status of this line is deduced): id = QUuid::fromRfc4122(bytes);
-
717 } else {
executed: }
Execution Count:4
4
718 const uchar *data = reinterpret_cast<const uchar *>(bytes.constData());
executed (the execution status of this line is deduced): const uchar *data = reinterpret_cast<const uchar *>(bytes.constData());
-
719 -
720 id.data1 = qFromLittleEndian<quint32>(data);
executed (the execution status of this line is deduced): id.data1 = qFromLittleEndian<quint32>(data);
-
721 data += sizeof(quint32);
executed (the execution status of this line is deduced): data += sizeof(quint32);
-
722 id.data2 = qFromLittleEndian<quint16>(data);
executed (the execution status of this line is deduced): id.data2 = qFromLittleEndian<quint16>(data);
-
723 data += sizeof(quint16);
executed (the execution status of this line is deduced): data += sizeof(quint16);
-
724 id.data3 = qFromLittleEndian<quint16>(data);
executed (the execution status of this line is deduced): id.data3 = qFromLittleEndian<quint16>(data);
-
725 data += sizeof(quint16);
executed (the execution status of this line is deduced): data += sizeof(quint16);
-
726 -
727 for (int i = 0; i < 8; ++i) {
evaluated: i < 8
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:1
1-8
728 id.data4[i] = *(data);
executed (the execution status of this line is deduced): id.data4[i] = *(data);
-
729 data++;
executed (the execution status of this line is deduced): data++;
-
730 }
executed: }
Execution Count:8
8
731 }
executed: }
Execution Count:1
1
732 -
733 return s;
executed: return s;
Execution Count:5
5
734} -
735#endif // QT_NO_DATASTREAM -
736 -
737/*! -
738 Returns true if this is the null UUID -
739 {00000000-0000-0000-0000-000000000000}; otherwise returns false. -
740*/ -
741bool QUuid::isNull() const -
742{ -
743 return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 &&
executed: return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 && data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 && data1 == 0 && data2 == 0 && data3 == 0;
Execution Count:29
29
744 data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 &&
executed: return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 && data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 && data1 == 0 && data2 == 0 && data3 == 0;
Execution Count:29
29
745 data1 == 0 && data2 == 0 && data3 == 0;
executed: return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 && data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 && data1 == 0 && data2 == 0 && data3 == 0;
Execution Count:29
29
746} -
747 -
748/*! -
749 \enum QUuid::Variant -
750 -
751 This enum defines the values used in the \l{Variant field} -
752 {variant field} of the UUID. The value in the variant field -
753 determines the layout of the 128-bit value. -
754 -
755 \value VarUnknown Variant is unknown -
756 \value NCS Reserved for NCS (Network Computing System) backward compatibility -
757 \value DCE Distributed Computing Environment, the scheme used by QUuid -
758 \value Microsoft Reserved for Microsoft backward compatibility (GUID) -
759 \value Reserved Reserved for future definition -
760*/ -
761 -
762/*! -
763 \enum QUuid::Version -
764 -
765 This enum defines the values used in the \l{Version field} -
766 {version field} of the UUID. The version field is meaningful -
767 only if the value in the \l{Variant field} {variant field} -
768 is QUuid::DCE. -
769 -
770 \value VerUnknown Version is unknown -
771 \value Time Time-based, by using timestamp, clock sequence, and -
772 MAC network card address (if available) for the node sections -
773 \value EmbeddedPOSIX DCE Security version, with embedded POSIX UUIDs -
774 \value Name Name-based, by using values from a name for all sections -
775 \value Md5 Alias for Name -
776 \value Random Random-based, by using random numbers for all sections -
777 \value Sha1 -
778*/ -
779 -
780/*! -
781 \fn QUuid::Variant QUuid::variant() const -
782 -
783 Returns the value in the \l{Variant field} {variant field} of the -
784 UUID. If the return value is QUuid::DCE, call version() to see -
785 which layout it uses. The null UUID is considered to be of an -
786 unknown variant. -
787 -
788 \sa version() -
789*/ -
790QUuid::Variant QUuid::variant() const -
791{ -
792 if (isNull())
evaluated: isNull()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:15
4-15
793 return VarUnknown;
executed: return VarUnknown;
Execution Count:4
4
794 // Check the 3 MSB of data4[0] -
795 if ((data4[0] & 0x80) == 0x00) return NCS;
executed: return NCS;
Execution Count:2
evaluated: (data4[0] & 0x80) == 0x00
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:13
2-13
796 else if ((data4[0] & 0xC0) == 0x80) return DCE;
executed: return DCE;
Execution Count:13
partially evaluated: (data4[0] & 0xC0) == 0x80
TRUEFALSE
yes
Evaluation Count:13
no
Evaluation Count:0
0-13
797 else if ((data4[0] & 0xE0) == 0xC0) return Microsoft;
never executed: return Microsoft;
never evaluated: (data4[0] & 0xE0) == 0xC0
0
798 else if ((data4[0] & 0xE0) == 0xE0) return Reserved;
never executed: return Reserved;
never evaluated: (data4[0] & 0xE0) == 0xE0
0
799 return VarUnknown;
never executed: return VarUnknown;
0
800} -
801 -
802/*! -
803 \fn QUuid::Version QUuid::version() const -
804 -
805 Returns the \l{Version field} {version field} of the UUID, if the -
806 UUID's \l{Variant field} {variant field} is QUuid::DCE. Otherwise -
807 it returns QUuid::VerUnknown. -
808 -
809 \sa variant() -
810*/ -
811QUuid::Version QUuid::version() const -
812{ -
813 // Check the 4 MSB of data3 -
814 Version ver = (Version)(data3>>12);
executed (the execution status of this line is deduced): Version ver = (Version)(data3>>12);
-
815 if (isNull()
partially evaluated: isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
816 || (variant() != DCE)
evaluated: (variant() != DCE)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:3
1-3
817 || ver < Time
partially evaluated: ver < Time
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
818 || ver > Sha1)
partially evaluated: ver > Sha1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
819 return VerUnknown;
executed: return VerUnknown;
Execution Count:1
1
820 return ver;
executed: return ver;
Execution Count:3
3
821} -
822 -
823/*! -
824 \fn bool QUuid::operator<(const QUuid &other) const -
825 -
826 Returns true if this QUuid has the same \l{Variant field} -
827 {variant field} as the \a other QUuid and is lexicographically -
828 \e{before} the \a other QUuid. If the \a other QUuid has a -
829 different variant field, the return value is determined by -
830 comparing the two \l{QUuid::Variant} {variants}. -
831 -
832 \sa variant() -
833*/ -
834#define ISLESS(f1, f2) if (f1!=f2) return (f1<f2); -
835bool QUuid::operator<(const QUuid &other) const -
836{ -
837 if (variant() != other.variant())
evaluated: variant() != other.variant()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
838 return variant() < other.variant();
executed: return variant() < other.variant();
Execution Count:1
1
839 -
840 ISLESS(data1, other.data1);
executed: return (data1<other.data1);
Execution Count:1
partially evaluated: data1!=other.data1
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
841 ISLESS(data2, other.data2);
never executed: return (data2<other.data2);
never evaluated: data2!=other.data2
0
842 ISLESS(data3, other.data3);
never executed: return (data3<other.data3);
never evaluated: data3!=other.data3
0
843 for (int n = 0; n < 8; n++) {
never evaluated: n < 8
0
844 ISLESS(data4[n], other.data4[n]);
never executed: return (data4[n]<other.data4[n]);
never evaluated: data4[n]!=other.data4[n]
0
845 }
never executed: }
0
846 return false;
never executed: return false;
0
847} -
848 -
849/*! -
850 \fn bool QUuid::operator>(const QUuid &other) const -
851 -
852 Returns true if this QUuid has the same \l{Variant field} -
853 {variant field} as the \a other QUuid and is lexicographically -
854 \e{after} the \a other QUuid. If the \a other QUuid has a -
855 different variant field, the return value is determined by -
856 comparing the two \l{QUuid::Variant} {variants}. -
857 -
858 \sa variant() -
859*/ -
860#define ISMORE(f1, f2) if (f1!=f2) return (f1>f2); -
861bool QUuid::operator>(const QUuid &other) const -
862{ -
863 if (variant() != other.variant())
evaluated: variant() != other.variant()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
864 return variant() > other.variant();
executed: return variant() > other.variant();
Execution Count:1
1
865 -
866 ISMORE(data1, other.data1);
executed: return (data1>other.data1);
Execution Count:1
partially evaluated: data1!=other.data1
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
867 ISMORE(data2, other.data2);
never executed: return (data2>other.data2);
never evaluated: data2!=other.data2
0
868 ISMORE(data3, other.data3);
never executed: return (data3>other.data3);
never evaluated: data3!=other.data3
0
869 for (int n = 0; n < 8; n++) {
never evaluated: n < 8
0
870 ISMORE(data4[n], other.data4[n]);
never executed: return (data4[n]>other.data4[n]);
never evaluated: data4[n]!=other.data4[n]
0
871 }
never executed: }
0
872 return false;
never executed: return false;
0
873} -
874 -
875/*! -
876 \fn QUuid QUuid::createUuid() -
877 -
878 On any platform other than Windows, this function returns a new -
879 UUID with variant QUuid::DCE and version QUuid::Random. If -
880 the /dev/urandom device exists, then the numbers used to construct -
881 the UUID will be of cryptographic quality, which will make the UUID -
882 unique. Otherwise, the numbers of the UUID will be obtained from -
883 the local pseudo-random number generator (qrand(), which is seeded -
884 by qsrand()) which is usually not of cryptograhic quality, which -
885 means that the UUID can't be guaranteed to be unique. -
886 -
887 On a Windows platform, a GUID is generated, which almost certainly -
888 \e{will} be unique, on this or any other system, networked or not. -
889 -
890 \sa variant(), version() -
891*/ -
892#if defined(Q_OS_WIN32) -
893 -
894QT_BEGIN_INCLUDE_NAMESPACE -
895#include <objbase.h> // For CoCreateGuid -
896QT_END_INCLUDE_NAMESPACE -
897 -
898QUuid QUuid::createUuid() -
899{ -
900 GUID guid; -
901 CoCreateGuid(&guid); -
902 QUuid result = guid; -
903 return result; -
904} -
905 -
906#else // !Q_OS_WIN32 -
907 -
908QT_BEGIN_INCLUDE_NAMESPACE -
909#include "qdatetime.h" -
910#include "qfile.h" -
911#include "qthreadstorage.h" -
912#include <stdlib.h> // for RAND_MAX -
913QT_END_INCLUDE_NAMESPACE -
914 -
915#if !defined(QT_BOOTSTRAPPED) && defined(Q_OS_UNIX) -
916Q_GLOBAL_STATIC(QThreadStorage<QFile *>, devUrandomStorage);
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:1267
partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1265
partially evaluated: !thisGlobalStatic.destroyed
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-1267
917#endif -
918 -
919QUuid QUuid::createUuid() -
920{ -
921 QUuid result;
executed (the execution status of this line is deduced): QUuid result;
-
922 uint *data = &(result.data1);
executed (the execution status of this line is deduced): uint *data = &(result.data1);
-
923 -
924#if defined(Q_OS_UNIX) -
925 QFile *devUrandom;
executed (the execution status of this line is deduced): QFile *devUrandom;
-
926# if !defined(QT_BOOTSTRAPPED) -
927 devUrandom = devUrandomStorage()->localData();
executed (the execution status of this line is deduced): devUrandom = devUrandomStorage()->localData();
-
928 if (!devUrandom) {
evaluated: !devUrandom
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:1249
10-1249
929 devUrandom = new QFile(QLatin1String("/dev/urandom"));
executed (the execution status of this line is deduced): devUrandom = new QFile(QLatin1String("/dev/urandom"));
-
930 devUrandom->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
executed (the execution status of this line is deduced): devUrandom->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
-
931 devUrandomStorage()->setLocalData(devUrandom);
executed (the execution status of this line is deduced): devUrandomStorage()->setLocalData(devUrandom);
-
932 }
executed: }
Execution Count:10
10
933# else -
934 QFile file(QLatin1String("/dev/urandom")); -
935 devUrandom = &file; -
936 devUrandom->open(QIODevice::ReadOnly | QIODevice::Unbuffered); -
937# endif -
938 enum { AmountToRead = 4 * sizeof(uint) };
executed (the execution status of this line is deduced): enum { AmountToRead = 4 * sizeof(uint) };
-
939 if (devUrandom->isOpen()
partially evaluated: devUrandom->isOpen()
TRUEFALSE
yes
Evaluation Count:1259
no
Evaluation Count:0
0-1259
940 && devUrandom->read((char *) data, AmountToRead) == AmountToRead) {
partially evaluated: devUrandom->read((char *) data, AmountToRead) == AmountToRead
TRUEFALSE
yes
Evaluation Count:1259
no
Evaluation Count:0
0-1259
941 // we got what we wanted, nothing more to do -
942 ; -
943 } else
executed: }
Execution Count:1259
1259
944#endif -
945 { -
946 static const int intbits = sizeof(int)*8; -
947 static int randbits = 0; -
948 if (!randbits) {
never evaluated: !randbits
0
949 int r = 0;
never executed (the execution status of this line is deduced): int r = 0;
-
950 int max = RAND_MAX;
never executed (the execution status of this line is deduced): int max = 2147483647;
-
951 do { ++r; } while ((max=max>>1));
never executed: }
never evaluated: (max=max>>1)
0
952 randbits = r;
never executed (the execution status of this line is deduced): randbits = r;
-
953 }
never executed: }
0
954 -
955 // Seed the PRNG once per thread with a combination of current time, a -
956 // stack address and a serial counter (since thread stack addresses are -
957 // re-used). -
958#ifndef QT_BOOTSTRAPPED -
959 static QThreadStorage<int *> uuidseed; -
960 if (!uuidseed.hasLocalData())
never evaluated: !uuidseed.hasLocalData()
0
961 { -
962 int *pseed = new int;
never executed (the execution status of this line is deduced): int *pseed = new int;
-
963 static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(2); -
964 qsrand(*pseed = QDateTime::currentDateTime().toTime_t()
never executed (the execution status of this line is deduced): qsrand(*pseed = QDateTime::currentDateTime().toTime_t()
-
965 + quintptr(&pseed)
never executed (the execution status of this line is deduced): + quintptr(&pseed)
-
966 + serial.fetchAndAddRelaxed(1));
never executed (the execution status of this line is deduced): + serial.fetchAndAddRelaxed(1));
-
967 uuidseed.setLocalData(pseed);
never executed (the execution status of this line is deduced): uuidseed.setLocalData(pseed);
-
968 }
never executed: }
0
969#else -
970 static bool seeded = false; -
971 if (!seeded) -
972 qsrand(QDateTime::currentDateTime().toTime_t() -
973 + quintptr(&seeded)); -
974#endif -
975 -
976 int chunks = 16 / sizeof(uint);
never executed (the execution status of this line is deduced): int chunks = 16 / sizeof(uint);
-
977 while (chunks--) {
never evaluated: chunks--
0
978 uint randNumber = 0;
never executed (the execution status of this line is deduced): uint randNumber = 0;
-
979 for (int filled = 0; filled < intbits; filled += randbits)
never evaluated: filled < intbits
0
980 randNumber |= qrand()<<filled;
never executed: randNumber |= qrand()<<filled;
0
981 *(data+chunks) = randNumber;
never executed (the execution status of this line is deduced): *(data+chunks) = randNumber;
-
982 }
never executed: }
0
983 }
never executed: }
0
984 -
985 result.data4[0] = (result.data4[0] & 0x3F) | 0x80; // UV_DCE
executed (the execution status of this line is deduced): result.data4[0] = (result.data4[0] & 0x3F) | 0x80;
-
986 result.data3 = (result.data3 & 0x0FFF) | 0x4000; // UV_Random
executed (the execution status of this line is deduced): result.data3 = (result.data3 & 0x0FFF) | 0x4000;
-
987 -
988 return result;
executed: return result;
Execution Count:1259
1259
989} -
990#endif // !Q_OS_WIN32 -
991 -
992/*! -
993 \fn bool QUuid::operator==(const GUID &guid) const -
994 -
995 Returns true if this UUID is equal to the Windows GUID \a guid; -
996 otherwise returns false. -
997*/ -
998 -
999/*! -
1000 \fn bool QUuid::operator!=(const GUID &guid) const -
1001 -
1002 Returns true if this UUID is not equal to the Windows GUID \a -
1003 guid; otherwise returns false. -
1004*/ -
1005 -
1006#ifndef QT_NO_DEBUG_STREAM -
1007/*! -
1008 \relates QUuid -
1009 Writes the UUID \a id to the output stream for debugging information \a dbg. -
1010*/ -
1011QDebug operator<<(QDebug dbg, const QUuid &id) -
1012{ -
1013 dbg.nospace() << "QUuid(" << id.toString() << ')';
executed (the execution status of this line is deduced): dbg.nospace() << "QUuid(" << id.toString() << ')';
-
1014 return dbg.space();
executed: return dbg.space();
Execution Count:1
1
1015} -
1016#endif -
1017 -
1018/*! -
1019 \since 5.0 -
1020 \relates QUuid -
1021 Returns a hash of the UUID \a uuid, using \a seed to seed the calculation. -
1022*/ -
1023uint qHash(const QUuid &uuid, uint seed) Q_DECL_NOTHROW -
1024{ -
1025 return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16)
executed: return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]) ^ seed;
Execution Count:3
3
1026 ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3])
executed: return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]) ^ seed;
Execution Count:3
3
1027 ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7])
executed: return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]) ^ seed;
Execution Count:3
3
1028 ^ seed;
executed: return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]) ^ seed;
Execution Count:3
3
1029} -
1030 -
1031 -
1032QT_END_NAMESPACE -
1033 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial