summaryrefslogtreecommitdiff
path: root/library/quuid.cpp
authorar <ar>2004-06-06 19:43:58 (UTC)
committer ar <ar>2004-06-06 19:43:58 (UTC)
commita1ef1c3fe8700a16329358288299276fd16c8fa0 (patch) (unidiff)
tree3db826a2b2df0fd407721aaefe03bfc61ffd35f0 /library/quuid.cpp
parentd5f6057374caf1c81e02628f0fcca01394b1dc9d (diff)
downloadopie-a1ef1c3fe8700a16329358288299276fd16c8fa0.zip
opie-a1ef1c3fe8700a16329358288299276fd16c8fa0.tar.gz
opie-a1ef1c3fe8700a16329358288299276fd16c8fa0.tar.bz2
- solve problems with padded memory - dont use memcpy
Diffstat (limited to 'library/quuid.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/quuid.cpp133
1 files changed, 107 insertions, 26 deletions
diff --git a/library/quuid.cpp b/library/quuid.cpp
index 46fd816..36469a8 100644
--- a/library/quuid.cpp
+++ b/library/quuid.cpp
@@ -51,7 +51,9 @@
51 51
52 Creates a copy of the QUuid \a orig. 52 Creates a copy of the QUuid \a orig.
53*/ 53*/
54
54#ifndef QT_NO_QUUID_STRING 55#ifndef QT_NO_QUUID_STRING
56
55/*! 57/*!
56 Creates a QUuid object from the string \a text. Right now, the function 58 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 59 can only convert the format {12345678-1234-1234-1234-123456789ABC} and
@@ -63,40 +65,47 @@ QUuid::QUuid( const QString &text )
63 QString temp = text.upper(); 65 QString temp = text.upper();
64 66
65 data1 = temp.mid( 1, 8 ).toULong( &ok, 16 ); 67 data1 = temp.mid( 1, 8 ).toULong( &ok, 16 );
66 if ( !ok ) { 68 if ( !ok )
67 *this = QUuid(); 69 {
68 return; 70 *this = QUuid();
71 return;
69 } 72 }
70 73
71 data2 = temp.mid( 10, 4 ).toUInt( &ok, 16 ); 74 data2 = temp.mid( 10, 4 ).toUInt( &ok, 16 );
72 if ( !ok ) { 75 if ( !ok )
73 *this = QUuid(); 76 {
74 return; 77 *this = QUuid();
78 return;
75 } 79 }
76 data3 = temp.mid( 15, 4 ).toUInt( &ok, 16 ); 80 data3 = temp.mid( 15, 4 ).toUInt( &ok, 16 );
77 if ( !ok ) { 81 if ( !ok )
78 *this = QUuid(); 82 {
79 return; 83 *this = QUuid();
84 return;
80 } 85 }
81 data4[0] = temp.mid( 20, 2 ).toUInt( &ok, 16 ); 86 data4[0] = temp.mid( 20, 2 ).toUInt( &ok, 16 );
82 if ( !ok ) { 87 if ( !ok )
83 *this = QUuid(); 88 {
84 return; 89 *this = QUuid();
90 return;
85 } 91 }
86 data4[1] = temp.mid( 22, 2 ).toUInt( &ok, 16 ); 92 data4[1] = temp.mid( 22, 2 ).toUInt( &ok, 16 );
87 if ( !ok ) { 93 if ( !ok )
88 *this = QUuid(); 94 {
89 return; 95 *this = QUuid();
96 return;
90 } 97 }
91 for ( int i = 2; i<8; i++ ) { 98 for ( int i = 2; i<8; i++ )
92 data4[i] = temp.mid( 25 + (i-2)*2, 2 ).toUShort( &ok, 16 ); 99 {
93 if ( !ok ) { 100 data4[i] = temp.mid( 25 + (i-2)*2, 2 ).toUShort( &ok, 16 );
94 *this = QUuid(); 101 if ( !ok )
95 return; 102 {
96 } 103 *this = QUuid();
104 return;
105 }
97 } 106 }
98} 107}
99#endif 108
100/*! 109/*!
101 \fn QUuid QUuid::operator=(const QUuid &uuid ) 110 \fn QUuid QUuid::operator=(const QUuid &uuid )
102 111
@@ -114,7 +123,7 @@ QUuid::QUuid( const QString &text )
114 123
115 Returns TRUE if this QUuid and the \a other QUuid are different, otherwise returns FALSE. 124 Returns TRUE if this QUuid and the \a other QUuid are different, otherwise returns FALSE.
116*/ 125*/
117#ifndef QT_NO_QUUID_STRING 126
118/*! 127/*!
119 QString QUuid::toString() const 128 QString QUuid::toString() const
120 129
@@ -130,17 +139,89 @@ QString QUuid::toString() const
130 result += QString::number( (int)data4[0], 16 ).rightJustify( 2, '0' ); 139 result += QString::number( (int)data4[0], 16 ).rightJustify( 2, '0' );
131 result += QString::number( (int)data4[1], 16 ).rightJustify( 2, '0' ) + "-"; 140 result += QString::number( (int)data4[1], 16 ).rightJustify( 2, '0' ) + "-";
132 for ( int i = 2; i < 8; i++ ) 141 for ( int i = 2; i < 8; i++ )
133 result += QString::number( (int)data4[i], 16 ).rightJustify( 2, '0' ); 142 result += QString::number( (int)data4[i], 16 ).rightJustify( 2, '0' );
134 143
135 return result + "}"; 144 return result + "}";
136} 145}
137#endif 146#endif
147
138/*! 148/*!
139 Returns TRUE if this is the null UUID {00000000-0000-0000-0000-000000000000}, otherwise returns FALSE. 149 Returns TRUE if this is the null UUID {00000000-0000-0000-0000-000000000000}, otherwise returns FALSE.
140*/ 150*/
141bool QUuid::isNull() const 151bool QUuid::isNull() const
142{ 152{
143 return data4[0] == 0 && data4[1] == 0 && data4[2] == 0 && data4[3] == 0 && 153 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 && 154 data4[4] == 0 && data4[5] == 0 && data4[6] == 0 && data4[7] == 0 &&
145 data1 == 0 && data2 == 0 && data3 == 0; 155 data1 == 0 && data2 == 0 && data3 == 0;
156}
157
158
159/*!
160 \fn QUuid::Variant QUuid::variant() const
161
162 Returns the variant of the UUID.
163 The null UUID is considered to be of an unknown variant.
164
165 \sa version()
166*/
167QUuid::Variant QUuid::variant() const
168{
169 if ( isNull() )
170 return VarUnknown;
171 // Check the 3 MSB of data4[0]
172 if ( (data4[0] & 0x80) == 0x00 ) return NCS;
173 else if ( (data4[0] & 0xC0) == 0x80 ) return DCE;
174 else if ( (data4[0] & 0xE0) == 0xC0 ) return Microsoft;
175 else if ( (data4[0] & 0xE0) == 0xE0 ) return Reserved;
176 return VarUnknown;
177}
178
179/*!
180 \fn bool QUuid::operator<(const QUuid &other) const
181
182 Returns TRUE if this QUuid is of the same variant,
183 and lexicographically before the \a other QUuid;
184 otherwise returns FALSE.
185
186 \sa variant()
187*/
188#define ISLESS(f1, f2) if (f1!=f2) return (f1<f2);
189bool QUuid::operator<(const QUuid &other ) const
190{
191 if ( variant() != other.variant() )
192 return FALSE;
193
194 ISLESS( data1, other.data1 );
195 ISLESS( data2, other.data2 );
196 ISLESS( data3, other.data3 );
197 for ( int n = 0; n < 8; n++ )
198 {
199 ISLESS( data4[n], other.data4[n] );
200 }
201 return FALSE;
202}
203
204/*!
205 \fn bool QUuid::operator>(const QUuid &other) const
206
207 Returns TRUE if this QUuid is of the same variant,
208 and lexicographically after the \a other QUuid;
209 otherwise returns FALSE.
210
211 \sa variant()
212*/
213#define ISMORE(f1, f2) if (f1!=f2) return (f1>f2);
214bool QUuid::operator>(const QUuid &other ) const
215{
216 if ( variant() != other.variant() )
217 return FALSE;
218
219 ISMORE( data1, other.data1 );
220 ISMORE( data2, other.data2 );
221 ISMORE( data3, other.data3 );
222 for ( int n = 0; n < 8; n++ )
223 {
224 ISMORE( data4[n], other.data4[n] );
225 }
226 return FALSE;
146} 227}