summaryrefslogtreecommitdiff
path: root/library/quuid.h
Unidiff
Diffstat (limited to 'library/quuid.h') (more/less context) (ignore whitespace changes)
-rw-r--r--library/quuid.h147
1 files changed, 50 insertions, 97 deletions
diff --git a/library/quuid.h b/library/quuid.h
index 841a00f..1575711 100644
--- a/library/quuid.h
+++ b/library/quuid.h
@@ -25,49 +25,45 @@
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) );
52 } 41 }
53 QUuid( uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8 ) 42 QUuid( uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8 )
54 { 43 {
55 data1 = l; 44 data1 = l;
56 data2 = w1; 45 data2 = w1;
57 data3 = w2; 46 data3 = w2;
58 data4[0] = b1; 47 data4[0] = b1;
59 data4[1] = b2; 48 data4[1] = b2;
60 data4[2] = b3; 49 data4[2] = b3;
61 data4[3] = b4; 50 data4[3] = b4;
62 data4[4] = b5; 51 data4[4] = b5;
63 data4[5] = b6; 52 data4[5] = b6;
64 data4[6] = b7; 53 data4[6] = b7;
65 data4[7] = b8; 54 data4[7] = b8;
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,84 +72,41 @@ 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 76
83 bool operator==(const QUuid &orig ) const 77 data1 = orig.data1;
84 { 78 data2 = orig.data2;
85 return !memcmp( this, &orig, sizeof(QUuid) ); 79 data3 = orig.data3;
86 } 80 for( i = 0; i < 8; i++ )
81 data4[ i ] = orig.data4[ i ];
87 82
88 bool operator!=(const QUuid &orig ) const 83 return *this;
89 {
90 return !( *this == orig );
91 } 84 }
92 85
93 inline bool operator<(const QUuid &orig) const 86 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
103#if defined(Q_OS_WIN32)
104 // On Windows we have a type GUID that is used by the platform API, so we
105 // provide convenience operators to cast from and to this type.
106 QUuid( const GUID &guid )
107 { 87 {
108 memcpy( this, &guid, sizeof(GUID) ); 88 uint i;
109 } 89 if ( data1 != orig.data1 || data2 != orig.data2 ||
90 data3 != orig.data3 )
91 return FALSE;
110 92
111 QUuid &operator=(const GUID &orig ) 93 for( i = 0; i < 8; i++ )
112 { 94 if ( data4[i] != orig.data4[i] )
113 memcpy( this, &orig, sizeof(QUuid) ); 95 return FALSE;
114 return *this;
115 }
116 96
117 operator GUID() const 97 return TRUE;
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 } 98 }
122 99
123 bool operator==( const GUID &guid ) const 100 bool operator!=(const QUuid &orig ) const
124 { 101 {
125 return !memcmp( this, &guid, sizeof(QUuid) ); 102 return !( *this == orig );
126 } 103 }
127 104
128 bool operator!=( const GUID &guid ) const 105 bool operator<(const QUuid &other ) const;
129 { 106 bool operator>(const QUuid &other ) const;
130 return !( *this == guid ); 107
131 } 108 QUuid::Variant variant() const;
132
133 inline bool operator<(const QUuid &orig) const
134 {
135 return ( memcmp(this, &orig, sizeof(QUuid) ) < 0);
136 }
137
138 inline bool operator>(const QUuid &orig) const
139 {
140 return ( memcmp(this, &orig, sizeof(QUuid) ) > 0);
141 }
142
143#endif
144#if defined (Q_WS_QWS)
145 QUuid( uuid_t uuid )
146 {
147 memcpy( this, uuid, sizeof(uuid_t) );
148 }
149 109
150 QUuid &operator=(const uuid_t &orig )
151 {
152 memcpy( this, &orig, sizeof(uuid_t) );
153 return *this;
154 }
155#endif
156
157 ulong data1; 110 ulong data1;
158 ushort data2; 111 ushort data2;
159 ushort data3; 112 ushort data3;