summaryrefslogtreecommitdiff
path: root/library/quuid.cpp
authorkergoth <kergoth>2002-01-25 22:14:26 (UTC)
committer kergoth <kergoth>2002-01-25 22:14:26 (UTC)
commit15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff)
treec2fa0399a2c47fda8e2cd0092c73a809d17f68eb /library/quuid.cpp
downloadopie-15318cad33835e4e2dc620d033e43cd930676cdd.zip
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2
Initial revision
Diffstat (limited to 'library/quuid.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/quuid.cpp146
1 files changed, 146 insertions, 0 deletions
diff --git a/library/quuid.cpp b/library/quuid.cpp
new file mode 100644
index 0000000..fb4387c
--- a/dev/null
+++ b/library/quuid.cpp
@@ -0,0 +1,146 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "quuid.h"
22
23/*!
24 \class QUuid quuid.h
25 \brief The QUuid class defines a Universally Unique Identifier (UUID).
26
27 This class is temporarily copied from Qt 3.0.
28*/
29
30/*!
31 \fn QUuid::QUuid()
32
33 Creates the null UUID {00000000-0000-0000-0000-000000000000}.
34*/
35
36/*!
37 \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 )
38
39 Creates an UUID with the value specified by the parameters, \a l, \a
40 w1, \a w2, \a b1, \a b2, \a b3, \a b4, \a b5, \a b6, \a b7, \a b8.
41
42 Example:
43 \code
44 // {67C8770B-44F1-410A-AB9A-F9B5446F13EE}
45 QUuid IID_MyInterface( 0x67c8770b, 0x44f1, 0x410a, 0xab, 0x9a, 0xf9, 0xb5, 0x44, 0x6f, 0x13, 0xee )
46 \endcode
47*/
48
49/*!
50 \fn QUuid::QUuid( const QUuid &orig )
51
52 Creates a copy of the QUuid \a orig.
53*/
54#ifndef QT_NO_QUUID_STRING
55/*!
56 Creates a QUuid object from the string \a text. Right now, the function
57 can only convert the format {12345678-1234-1234-1234-123456789ABC} and
58 will create the null UUID when the conversion fails.
59*/
60QUuid::QUuid( const QString &text )
61{
62 bool ok;
63 QString temp = text.upper();
64
65 data1 = temp.mid( 1, 8 ).toULong( &ok, 16 );
66 if ( !ok ) {
67 *this = QUuid();
68 return;
69 }
70
71 data2 = temp.mid( 10, 4 ).toUInt( &ok, 16 );
72 if ( !ok ) {
73 *this = QUuid();
74 return;
75 }
76 data3 = temp.mid( 15, 4 ).toUInt( &ok, 16 );
77 if ( !ok ) {
78 *this = QUuid();
79 return;
80 }
81 data4[0] = temp.mid( 20, 2 ).toUInt( &ok, 16 );
82 if ( !ok ) {
83 *this = QUuid();
84 return;
85 }
86 data4[1] = temp.mid( 22, 2 ).toUInt( &ok, 16 );
87 if ( !ok ) {
88 *this = QUuid();
89 return;
90 }
91 for ( int i = 2; i<8; i++ ) {
92 data4[i] = temp.mid( 25 + (i-2)*2, 2 ).toUShort( &ok, 16 );
93 if ( !ok ) {
94 *this = QUuid();
95 return;
96 }
97 }
98}
99#endif
100/*!
101 \fn QUuid QUuid::operator=(const QUuid &uuid )
102
103 Assigns the value of \a uuid to this QUuid object.
104*/
105
106/*!
107 \fn bool QUuid::operator==(const QUuid &other) const
108
109 Returns TRUE if this QUuid and the \a other QUuid are identical, otherwise returns FALSE.
110*/
111
112/*!
113 \fn bool QUuid::operator!=(const QUuid &other) const
114
115 Returns TRUE if this QUuid and the \a other QUuid are different, otherwise returns FALSE.
116*/
117#ifndef QT_NO_QUUID_STRING
118/*!
119 QString QUuid::toString() const
120
121 Returns a string in {12345678-1234-1234-1234-123456789ABC} format.
122*/
123QString QUuid::toString() const
124{
125 QString result;
126
127 result = "{" + QString::number( data1, 16 ).rightJustify( 8, '0' ) + "-";
128 result += QString::number( (int)data2, 16 ).rightJustify( 4, '0' ) + "-";
129 result += QString::number( (int)data3, 16 ).rightJustify( 4, '0' ) + "-";
130 result += QString::number( (int)data4[0], 16 ).rightJustify( 2, '0' );
131 result += QString::number( (int)data4[1], 16 ).rightJustify( 2, '0' ) + "-";
132 for ( int i = 2; i < 8; i++ )
133 result += QString::number( (int)data4[i], 16 ).rightJustify( 2, '0' );
134
135 return result + "}";
136}
137#endif
138/*!
139 Returns TRUE if this is the null UUID {00000000-0000-0000-0000-000000000000}, otherwise returns FALSE.
140*/
141bool QUuid::isNull() const
142{
143 return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 &&
144 data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 &&
145 data1 == 0 && data2 == 0 && data3 == 0;
146}