summaryrefslogtreecommitdiff
authorar <ar>2004-06-06 19:43:58 (UTC)
committer ar <ar>2004-06-06 19:43:58 (UTC)
commita1ef1c3fe8700a16329358288299276fd16c8fa0 (patch) (unidiff)
tree3db826a2b2df0fd407721aaefe03bfc61ffd35f0
parentd5f6057374caf1c81e02628f0fcca01394b1dc9d (diff)
downloadopie-a1ef1c3fe8700a16329358288299276fd16c8fa0.zip
opie-a1ef1c3fe8700a16329358288299276fd16c8fa0.tar.gz
opie-a1ef1c3fe8700a16329358288299276fd16c8fa0.tar.bz2
- solve problems with padded memory - dont use memcpy
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--library/quuid.cpp99
-rw-r--r--library/quuid.h119
2 files changed, 126 insertions, 92 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 )
69 {
67 *this = QUuid(); 70 *this = QUuid();
68 return; 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 )
76 {
73 *this = QUuid(); 77 *this = QUuid();
74 return; 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 )
82 {
78 *this = QUuid(); 83 *this = QUuid();
79 return; 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 )
88 {
83 *this = QUuid(); 89 *this = QUuid();
84 return; 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 )
94 {
88 *this = QUuid(); 95 *this = QUuid();
89 return; 96 return;
90 } 97 }
91 for ( int i = 2; i<8; i++ ) { 98 for ( int i = 2; i<8; i++ )
99 {
92 data4[i] = temp.mid( 25 + (i-2)*2, 2 ).toUShort( &ok, 16 ); 100 data4[i] = temp.mid( 25 + (i-2)*2, 2 ).toUShort( &ok, 16 );
93 if ( !ok ) { 101 if ( !ok )
102 {
94 *this = QUuid(); 103 *this = QUuid();
95 return; 104 return;
96 } 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
@@ -135,6 +144,7 @@ QString QUuid::toString() const
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*/
@@ -144,3 +154,74 @@ bool QUuid::isNull() const
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;
146} 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;
227}
diff --git a/library/quuid.h b/library/quuid.h
index 841a00f..1575711 100644
--- a/library/quuid.h
+++ b/library/quuid.h
@@ -25,27 +25,16 @@
25#include <qstring.h> 25#include <qstring.h>
26#endif // QT_H 26#endif // QT_H
27 27
28#include <memory.h>
29
30#if defined(Q_OS_WIN32)
31#ifndef GUID_DEFINED
32#define GUID_DEFINED
33typedef struct _GUID
34{
35 ulong Data1;
36 ushort Data2;
37 ushort Data3;
38 uchar Data4[ 8 ];
39} GUID;
40#endif
41#endif
42
43#if defined( Q_WS_QWS ) && !defined( UUID_H_INCLUDED )
44typedef unsigned char uuid_t[16];
45#endif
46
47struct Q_EXPORT QUuid 28struct Q_EXPORT QUuid
48{ 29{
30 enum Variant {
31 VarUnknown =-1,
32 NCS = 0, // 0 - -
33 DCE = 2, // 1 0 -
34 Microsoft = 6, // 1 1 0
35 Reserved = 7 // 1 1 1
36 };
37
49 QUuid() 38 QUuid()
50 { 39 {
51 memset( this, 0, sizeof(QUuid) ); 40 memset( this, 0, sizeof(QUuid) );
@@ -66,8 +55,15 @@ struct Q_EXPORT QUuid
66 } 55 }
67 QUuid( const QUuid &uuid ) 56 QUuid( const QUuid &uuid )
68 { 57 {
69 memcpy( this, &uuid, sizeof(QUuid) ); 58 uint i;
59
60 data1 = uuid.data1;
61 data2 = uuid.data2;
62 data3 = uuid.data3;
63 for( i = 0; i < 8; i++ )
64 data4[ i ] = uuid.data4[ i ];
70 } 65 }
66
71#ifndef QT_NO_QUUID_STRING 67#ifndef QT_NO_QUUID_STRING
72 QUuid( const QString & ); 68 QUuid( const QString & );
73 QString toString() const; 69 QString toString() const;
@@ -76,83 +72,40 @@ struct Q_EXPORT QUuid
76 72
77 QUuid &operator=(const QUuid &orig ) 73 QUuid &operator=(const QUuid &orig )
78 { 74 {
79 memcpy( this, &orig, sizeof(QUuid) ); 75 uint i;
80 return *this;
81 }
82
83 bool operator==(const QUuid &orig ) const
84 {
85 return !memcmp( this, &orig, sizeof(QUuid) );
86 }
87
88 bool operator!=(const QUuid &orig ) const
89 {
90 return !( *this == orig );
91 }
92
93 inline bool operator<(const QUuid &orig) const
94 {
95 return ( memcmp(this, &orig, sizeof(QUuid)) < 0);
96 }
97
98 inline bool operator>(const QUuid &orig) const
99 {
100 return ( memcmp(this, &orig, sizeof(QUuid) ) > 0);
101 }
102 76
103#if defined(Q_OS_WIN32) 77 data1 = orig.data1;
104 // On Windows we have a type GUID that is used by the platform API, so we 78 data2 = orig.data2;
105 // provide convenience operators to cast from and to this type. 79 data3 = orig.data3;
106 QUuid( const GUID &guid ) 80 for( i = 0; i < 8; i++ )
107 { 81 data4[ i ] = orig.data4[ i ];
108 memcpy( this, &guid, sizeof(GUID) );
109 }
110 82
111 QUuid &operator=(const GUID &orig )
112 {
113 memcpy( this, &orig, sizeof(QUuid) );
114 return *this; 83 return *this;
115 } 84 }
116 85
117 operator GUID() const 86 bool operator==(const QUuid &orig ) const
118 {
119 GUID guid = { data1, data2, data3, { data4[0], data4[1], data4[2], data4[3], data4[4], data4[5], data4[6], data4[7] } };
120 return guid;
121 }
122
123 bool operator==( const GUID &guid ) const
124 { 87 {
125 return !memcmp( this, &guid, sizeof(QUuid) ); 88 uint i;
126 } 89 if ( data1 != orig.data1 || data2 != orig.data2 ||
90 data3 != orig.data3 )
91 return FALSE;
127 92
128 bool operator!=( const GUID &guid ) const 93 for( i = 0; i < 8; i++ )
129 { 94 if ( data4[i] != orig.data4[i] )
130 return !( *this == guid ); 95 return FALSE;
131 }
132 96
133 inline bool operator<(const QUuid &orig) const 97 return TRUE;
134 {
135 return ( memcmp(this, &orig, sizeof(QUuid) ) < 0);
136 } 98 }
137 99
138 inline bool operator>(const QUuid &orig) const 100 bool operator!=(const QUuid &orig ) const
139 { 101 {
140 return ( memcmp(this, &orig, sizeof(QUuid) ) > 0); 102 return !( *this == orig );
141 } 103 }
142 104
143#endif 105 bool operator<(const QUuid &other ) const;
144#if defined (Q_WS_QWS) 106 bool operator>(const QUuid &other ) const;
145 QUuid( uuid_t uuid )
146 {
147 memcpy( this, uuid, sizeof(uuid_t) );
148 }
149 107
150 QUuid &operator=(const uuid_t &orig ) 108 QUuid::Variant variant() const;
151 {
152 memcpy( this, &orig, sizeof(uuid_t) );
153 return *this;
154 }
155#endif
156 109
157 ulong data1; 110 ulong data1;
158 ushort data2; 111 ushort data2;