-rw-r--r-- | qmake/tools/quuid.cpp | 230 |
1 files changed, 230 insertions, 0 deletions
diff --git a/qmake/tools/quuid.cpp b/qmake/tools/quuid.cpp new file mode 100644 index 0000000..fd99abf --- a/dev/null +++ b/qmake/tools/quuid.cpp | |||
@@ -0,0 +1,230 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** Implementation of QUuid class | ||
5 | ** | ||
6 | ** Copyright (C) 2000-2001 Trolltech AS. All rights reserved. | ||
7 | ** | ||
8 | ** This file is part of the tools module of the Qt GUI Toolkit. | ||
9 | ** | ||
10 | ** This file may be distributed under the terms of the Q Public License | ||
11 | ** as defined by Trolltech AS of Norway and appearing in the file | ||
12 | ** LICENSE.QPL included in the packaging of this file. | ||
13 | ** | ||
14 | ** This file may be distributed and/or modified under the terms of the | ||
15 | ** GNU General Public License version 2 as published by the Free Software | ||
16 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
17 | ** packaging of this file. | ||
18 | ** | ||
19 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
20 | ** licenses may use this file in accordance with the Qt Commercial License | ||
21 | ** Agreement provided with the Software. | ||
22 | ** | ||
23 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
24 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
25 | ** | ||
26 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
27 | ** information about Qt Commercial License Agreements. | ||
28 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | ||
29 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
30 | ** | ||
31 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
32 | ** not clear to you. | ||
33 | ** | ||
34 | **********************************************************************/ | ||
35 | |||
36 | #include "quuid.h" | ||
37 | |||
38 | #include <qdatastream.h> | ||
39 | |||
40 | /*! | ||
41 | \class QUuid quuid.h | ||
42 | \reentrant | ||
43 | \brief The QUuid class defines a Universally Unique Identifier (UUID). | ||
44 | |||
45 | \internal | ||
46 | |||
47 | For objects or declarations that need to be identified uniquely, UUIDs (also known as GUIDs) are widely | ||
48 | used in order to assign a fixed and easy to compare value to this object or declaration. The 128bit value | ||
49 | of an UUID is generated by an algorithm that guarantees a value that is unique in time and space. | ||
50 | |||
51 | In Qt, UUIDs are wrapped by the QUuid struct which provides convenience functions for comparing and coping | ||
52 | this value. The QUuid struct is used in Qt's component model to identify interfaces. Most platforms provide a tool to | ||
53 | generate new UUIDs (uuidgen, guidgen), and the Qt distribution includes a graphical tool \e quuidgen that generates | ||
54 | the UUIDs in a programmer friendly format. | ||
55 | |||
56 | \sa QUnknownInterface | ||
57 | */ | ||
58 | |||
59 | /*! | ||
60 | \fn QUuid::QUuid() | ||
61 | |||
62 | Creates the null UUID {00000000-0000-0000-0000-000000000000}. | ||
63 | */ | ||
64 | |||
65 | /*! | ||
66 | \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 ) | ||
67 | |||
68 | Creates an UUID with the value specified by the parameters, \a l, \a | ||
69 | w1, \a w2, \a b1, \a b2, \a b3, \a b4, \a b5, \a b6, \a b7, \a b8. | ||
70 | |||
71 | Example: | ||
72 | \code | ||
73 | // {67C8770B-44F1-410A-AB9A-F9B5446F13EE} | ||
74 | QUuid IID_MyInterface( 0x67c8770b, 0x44f1, 0x410a, 0xab, 0x9a, 0xf9, 0xb5, 0x44, 0x6f, 0x13, 0xee ) | ||
75 | \endcode | ||
76 | */ | ||
77 | |||
78 | /*! | ||
79 | \fn QUuid::QUuid( const QUuid &orig ) | ||
80 | |||
81 | Creates a copy of the QUuid \a orig. | ||
82 | */ | ||
83 | #ifndef QT_NO_QUUID_STRING | ||
84 | /*! | ||
85 | Creates a QUuid object from the string \a text. Right now, the function | ||
86 | can only convert the format {12345678-1234-1234-1234-123456789ABC} and | ||
87 | will create the null UUID when the conversion fails. | ||
88 | */ | ||
89 | QUuid::QUuid( const QString &text ) | ||
90 | { | ||
91 | bool ok; | ||
92 | QString temp = text.upper(); | ||
93 | |||
94 | data1 = temp.mid( 1, 8 ).toULong( &ok, 16 ); | ||
95 | if ( !ok ) { | ||
96 | *this = QUuid(); | ||
97 | return; | ||
98 | } | ||
99 | |||
100 | data2 = temp.mid( 10, 4 ).toUInt( &ok, 16 ); | ||
101 | if ( !ok ) { | ||
102 | *this = QUuid(); | ||
103 | return; | ||
104 | } | ||
105 | data3 = temp.mid( 15, 4 ).toUInt( &ok, 16 ); | ||
106 | if ( !ok ) { | ||
107 | *this = QUuid(); | ||
108 | return; | ||
109 | } | ||
110 | data4[0] = temp.mid( 20, 2 ).toUInt( &ok, 16 ); | ||
111 | if ( !ok ) { | ||
112 | *this = QUuid(); | ||
113 | return; | ||
114 | } | ||
115 | data4[1] = temp.mid( 22, 2 ).toUInt( &ok, 16 ); | ||
116 | if ( !ok ) { | ||
117 | *this = QUuid(); | ||
118 | return; | ||
119 | } | ||
120 | for ( int i = 2; i<8; i++ ) { | ||
121 | data4[i] = temp.mid( 25 + (i-2)*2, 2 ).toUShort( &ok, 16 ); | ||
122 | if ( !ok ) { | ||
123 | *this = QUuid(); | ||
124 | return; | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | |||
129 | /*! | ||
130 | \overload | ||
131 | */ | ||
132 | QUuid::QUuid( const char *text ) | ||
133 | { | ||
134 | *this = QUuid( QString(text) ); | ||
135 | } | ||
136 | #endif | ||
137 | /*! | ||
138 | \fn QUuid QUuid::operator=(const QUuid &uuid ) | ||
139 | |||
140 | Assigns the value of \a uuid to this QUuid object. | ||
141 | */ | ||
142 | |||
143 | /*! | ||
144 | \fn bool QUuid::operator==(const QUuid &other) const | ||
145 | |||
146 | Returns TRUE if this QUuid and the \a other QUuid are identical, otherwise returns FALSE. | ||
147 | */ | ||
148 | |||
149 | /*! | ||
150 | \fn bool QUuid::operator!=(const QUuid &other) const | ||
151 | |||
152 | Returns TRUE if this QUuid and the \a other QUuid are different, otherwise returns FALSE. | ||
153 | */ | ||
154 | #ifndef QT_NO_QUUID_STRING | ||
155 | /*! | ||
156 | \fn QUuid::operator QString() const | ||
157 | |||
158 | Returns the string representation of the uuid. | ||
159 | |||
160 | \sa toString() | ||
161 | */ | ||
162 | |||
163 | /*! | ||
164 | QString QUuid::toString() const | ||
165 | |||
166 | Returns the string representation of the uuid. | ||
167 | */ | ||
168 | QString QUuid::toString() const | ||
169 | { | ||
170 | QString result; | ||
171 | |||
172 | result = "{" + QString::number( data1, 16 ).rightJustify( 8, '0' ) + "-"; | ||
173 | result += QString::number( (int)data2, 16 ).rightJustify( 4, '0' ) + "-"; | ||
174 | result += QString::number( (int)data3, 16 ).rightJustify( 4, '0' ) + "-"; | ||
175 | result += QString::number( (int)data4[0], 16 ).rightJustify( 2, '0' ); | ||
176 | result += QString::number( (int)data4[1], 16 ).rightJustify( 2, '0' ) + "-"; | ||
177 | for ( int i = 2; i < 8; i++ ) | ||
178 | result += QString::number( (int)data4[i], 16 ).rightJustify( 2, '0' ); | ||
179 | |||
180 | return result + "}"; | ||
181 | } | ||
182 | #endif | ||
183 | |||
184 | #ifndef QT_NO_DATASTREAM | ||
185 | /*! | ||
186 | \relates QUuid | ||
187 | Writes the \a id to the datastream \a s. | ||
188 | */ | ||
189 | QDataStream &operator<<( QDataStream &s, const QUuid &id ) | ||
190 | { | ||
191 | s << (Q_UINT32)id.data1; | ||
192 | s << (Q_UINT16)id.data2; | ||
193 | s << (Q_UINT16)id.data3; | ||
194 | for (int i = 0; i < 8; i++ ) | ||
195 | s << (Q_UINT8)id.data4[i]; | ||
196 | return s; | ||
197 | } | ||
198 | |||
199 | /*! | ||
200 | \relates QUuid | ||
201 | Reads a universally unique id from from the stream \a s into \a id. | ||
202 | */ | ||
203 | QDataStream &operator>>( QDataStream &s, QUuid &id ) | ||
204 | { | ||
205 | Q_UINT32 u32; | ||
206 | Q_UINT16 u16; | ||
207 | Q_UINT8 u8; | ||
208 | s >> u32; | ||
209 | id.data1 = u32; | ||
210 | s >> u16; | ||
211 | id.data2 = u16; | ||
212 | s >> u16; | ||
213 | id.data3 = u16; | ||
214 | for (int i = 0; i < 8; i++ ) { | ||
215 | s >> u8; | ||
216 | id.data4[i] = u8; | ||
217 | } | ||
218 | return s; | ||
219 | } | ||
220 | #endif | ||
221 | |||
222 | /*! | ||
223 | Returns TRUE if this is the null UUID {00000000-0000-0000-0000-000000000000}, otherwise returns FALSE. | ||
224 | */ | ||
225 | bool QUuid::isNull() const | ||
226 | { | ||
227 | return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 && | ||
228 | data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 && | ||
229 | data1 == 0 && data2 == 0 && data3 == 0; | ||
230 | } | ||