source: trunk/include/quuid.h@ 138

Last change on this file since 138 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1/****************************************************************************
2** $Id: quuid.h 2 2005-11-16 15:49:26Z dmik $
3**
4** Definition of QUuid class
5**
6** Created : 010523
7**
8** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
9**
10** This file is part of the tools module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#ifndef QUUID_H
39#define QUUID_H
40
41#ifndef QT_H
42#include "qstring.h"
43#endif // QT_H
44
45#include <string.h>
46
47#if defined(Q_OS_WIN32)
48#ifndef GUID_DEFINED
49#define GUID_DEFINED
50typedef struct _GUID
51{
52 ulong Data1;
53 ushort Data2;
54 ushort Data3;
55 uchar Data4[ 8 ];
56} GUID, *REFGUID, *LPGUID;
57#endif
58#endif
59
60
61struct Q_EXPORT QUuid
62{
63 enum Variant {
64 VarUnknown =-1,
65 NCS = 0, // 0 - -
66 DCE = 2, // 1 0 -
67 Microsoft = 6, // 1 1 0
68 Reserved = 7 // 1 1 1
69 };
70
71 enum Version {
72 VerUnknown =-1,
73 Time = 1, // 0 0 0 1
74 EmbeddedPOSIX = 2, // 0 0 1 0
75 Name = 3, // 0 0 1 1
76 Random = 4 // 0 1 0 0
77 };
78
79 QUuid()
80 {
81 memset( this, 0, sizeof(QUuid) );
82 }
83 QUuid( uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8 )
84 {
85 data1 = l;
86 data2 = w1;
87 data3 = w2;
88 data4[0] = b1;
89 data4[1] = b2;
90 data4[2] = b3;
91 data4[3] = b4;
92 data4[4] = b5;
93 data4[5] = b6;
94 data4[6] = b7;
95 data4[7] = b8;
96 }
97 QUuid( const QUuid &uuid )
98 {
99 memcpy( this, &uuid, sizeof(QUuid) );
100 }
101#ifndef QT_NO_QUUID_STRING
102 QUuid( const QString & );
103 QUuid( const char * );
104 QString toString() const;
105 operator QString() const { return toString(); }
106#endif
107 bool isNull() const;
108
109 QUuid &operator=(const QUuid &orig )
110 {
111 memcpy( this, &orig, sizeof(QUuid) );
112 return *this;
113 }
114
115 bool operator==(const QUuid &orig ) const
116 {
117 uint i;
118 if ( data1 != orig.data1 || data2 != orig.data2 ||
119 data3 != orig.data3 )
120 return FALSE;
121
122 for( i = 0; i < 8; i++ )
123 if ( data4[i] != orig.data4[i] )
124 return FALSE;
125
126 return TRUE;
127 }
128
129 bool operator!=(const QUuid &orig ) const
130 {
131 return !( *this == orig );
132 }
133
134 bool operator<(const QUuid &other ) const;
135 bool operator>(const QUuid &other ) const;
136
137#if defined(Q_OS_WIN32)
138 // On Windows we have a type GUID that is used by the platform API, so we
139 // provide convenience operators to cast from and to this type.
140 QUuid( const GUID &guid )
141 {
142 memcpy( this, &guid, sizeof(GUID) );
143 }
144
145 QUuid &operator=(const GUID &orig )
146 {
147 memcpy( this, &orig, sizeof(QUuid) );
148 return *this;
149 }
150
151 operator GUID() const
152 {
153 GUID guid = { data1, data2, data3, { data4[0], data4[1], data4[2], data4[3], data4[4], data4[5], data4[6], data4[7] } };
154 return guid;
155 }
156
157 bool operator==( const GUID &guid ) const
158 {
159 uint i;
160 if ( data1 != guid.Data1 || data2 != guid.Data2 ||
161 data3 != guid.Data3 )
162 return FALSE;
163
164 for( i = 0; i < 8; i++ )
165 if ( data4[i] != guid.Data4[i] )
166 return FALSE;
167
168 return TRUE;
169 }
170
171 bool operator!=( const GUID &guid ) const
172 {
173 return !( *this == guid );
174 }
175#endif
176 static QUuid createUuid();
177 QUuid::Variant variant() const;
178 QUuid::Version version() const;
179
180 uint data1;
181 ushort data2;
182 ushort data3;
183 uchar data4[ 8 ];
184};
185
186#ifndef QT_NO_DATASTREAM
187Q_EXPORT QDataStream &operator<<( QDataStream &, const QUuid & );
188Q_EXPORT QDataStream &operator>>( QDataStream &, QUuid & );
189#endif
190
191#endif //QUUID_H
Note: See TracBrowser for help on using the repository browser.