1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.core.uuid;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.bytearray;
19 import qt.core.global;
20 import qt.core.metatype;
21 import qt.core.namespace;
22 import qt.core.string;
23 import qt.core.stringview;
24 import qt.core.typeinfo;
25 import qt.helpers;
26 version(Cygwin){}else
27 version(Windows)
28     import core.stdc.config;
29 
30 version(Cygwin){}else
31 version(Windows)
32 {
33 /+ #ifndef GUID_DEFINED +/
34 /+ #define GUID_DEFINED +/
35 struct _GUID
36 {
37     cpp_ulong   Data1;
38     ushort  Data2;
39     ushort  Data3;
40     uchar[8]   Data4;
41 }
42 alias GUID = _GUID/+ , +/;
43 alias REFGUID = _GUID */+ , +/;
44 alias LPGUID = _GUID *;
45 /+ #endif +/
46 }
47 
48 /+ #if defined(Q_OS_DARWIN) || defined(Q_CLANG_QDOC)
49 Q_FORWARD_DECLARE_CF_TYPE(CFUUID);
50 Q_FORWARD_DECLARE_OBJC_CLASS(NSUUID);
51 #endif +/
52 
53 
54 
55 @(QMetaType.Type.QUuid) @Q_PRIMITIVE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QUuid
56 {
57 private:
58     this(/+ Qt:: +/qt.core.namespace.Initialization) {}
59 public:
60     enum Variant {
61         VarUnknown        =-1,
62         NCS                = 0, // 0 - -
63         DCE                = 2, // 1 0 -
64         Microsoft        = 6, // 1 1 0
65         Reserved        = 7  // 1 1 1
66     }
67 
68     enum Version {
69         VerUnknown        =-1,
70         Time                = 1, // 0 0 0 1
71         EmbeddedPOSIX        = 2, // 0 0 1 0
72         Md5                 = 3, // 0 0 1 1
73         Name = Version.Md5,
74         Random                = 4,  // 0 1 0 0
75         Sha1                 = 5 // 0 1 0 1
76     }
77 
78     enum StringFormat {
79         WithBraces      = 0,
80         WithoutBraces   = 1,
81         Id128           = 3
82     }
83 
84 /+ #if defined(Q_COMPILER_UNIFORM_INIT) && !defined(Q_CLANG_QDOC)
85 
86     QUuid() noexcept : data1(0), data2(0), data3(0), data4{0,0,0,0,0,0,0,0} {}
87 
88     QUuid(uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3,
89                            uchar b4, uchar b5, uchar b6, uchar b7, uchar b8) noexcept
90         : data1(l), data2(w1), data3(w2), data4{b1, b2, b3, b4, b5, b6, b7, b8} {}
91 #else +/
92     @disable this();
93     /+this()/+ noexcept+/
94     {
95         data1 = 0;
96         data2 = 0;
97         data3 = 0;
98         for(int i = 0; i < 8; i++)
99             data4[i] = 0;
100     }+/
101     this(uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, uchar b4, uchar b5, uchar b6, uchar b7, uchar b8)/+ noexcept+/
102     {
103         data1 = l;
104         data2 = w1;
105         data3 = w2;
106         data4[0] = b1;
107         data4[1] = b2;
108         data4[2] = b3;
109         data4[3] = b4;
110         data4[4] = b5;
111         data4[5] = b6;
112         data4[6] = b7;
113         data4[7] = b8;
114     }
115 /+ #endif +/
116 
117     this(ref const(QString) );
118     static QUuid fromString(QStringView string)/+ noexcept+/;
119     static QUuid fromString(QLatin1String string)/+ noexcept+/;
120     this(const(char)* );
121     QString toString() const;
122     QString toString(StringFormat mode) const; // ### Qt6: merge with previous
123     this(ref const(QByteArray) );
124     QByteArray toByteArray() const;
125     QByteArray toByteArray(StringFormat mode) const; // ### Qt6: merge with previous
126     QByteArray toRfc4122() const;
127     static QUuid fromRfc4122(ref const(QByteArray) );
128     bool isNull() const/+ noexcept+/;
129 
130     /+bool operator ==(ref const(QUuid) orig) const/+ noexcept+/
131     {
132         if (data1 != orig.data1 || data2 != orig.data2 ||
133              data3 != orig.data3)
134             return false;
135 
136         for (uint i = 0; i < 8; i++)
137             if (data4[i] != orig.data4[i])
138                 return false;
139 
140         return true;
141     }+/
142 
143     /+bool operator !=(ref const(QUuid) orig) const/+ noexcept+/
144     {
145         return !(this == orig);
146     }+/
147 
148     /+bool operator <(ref const(QUuid) other) const/+ noexcept+/;+/
149     /+bool operator >(ref const(QUuid) other) const/+ noexcept+/;+/
150 
151 /+ #if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC)
152     // On Windows we have a type GUID that is used by the platform API, so we
153     // provide convenience operators to cast from and to this type.
154 #if defined(Q_COMPILER_UNIFORM_INIT) && !defined(Q_CLANG_QDOC)
155     QUuid(const GUID &guid) noexcept
156         : data1(guid.Data1), data2(guid.Data2), data3(guid.Data3),
157           data4{guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
158                 guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]} {}
159 #else +/
160     static if((versionIsSet!("Windows") && !versionIsSet!("Cygwin")))
161     {
162         this(ref const(GUID) guid)/+ noexcept+/
163         {
164             data1 = cast(uint)(guid.Data1);
165             data2 = guid.Data2;
166             data3 = guid.Data3;
167             for(int i = 0; i < 8; i++)
168                 data4[i] = guid.Data4[i];
169         }
170     /+ #endif +/
171 
172         /+ref QUuid operator =(ref const(GUID) guid)/+ noexcept+/
173         {
174             this = QUuid(guid);
175             return this;
176         }+/
177 
178         /+ auto opCast(T : GUID)() const/+ noexcept+/
179         {
180             GUID guid = _GUID( data1, data2, data3, [ data4[0], data4[1], data4[2], data4[3], data4[4], data4[5], data4[6], data4[7]] ) ;
181             return guid;
182         }+/
183 
184         /+bool operator ==(ref const(GUID) guid) const/+ noexcept+/
185         {
186             return this == QUuid(guid);
187         }+/
188 
189         /+bool operator !=(ref const(GUID) guid) const/+ noexcept+/
190         {
191             return !(this == guid);
192         }+/
193     }
194 /+ #endif +/
195     static QUuid createUuid();
196 /+ #ifndef QT_BOOTSTRAPPED +/
197     static QUuid createUuidV3(ref const(QUuid) ns, ref const(QByteArray) baseData);
198 /+ #endif +/
199     static QUuid createUuidV5(ref const(QUuid) ns, ref const(QByteArray) baseData);
200 /+ #ifndef QT_BOOTSTRAPPED +/
201     pragma(inline, true) static QUuid createUuidV3(ref const(QUuid) ns, ref const(QString) baseData)
202     {
203         auto tmp = baseData.toUtf8(); return QUuid.createUuidV3(ns, tmp);
204     }
205 /+ #endif +/
206 
207     pragma(inline, true) static QUuid createUuidV5(ref const(QUuid) ns, ref const(QString) baseData)
208     {
209         auto tmp = baseData.toUtf8(); return QUuid.createUuidV5(ns, tmp);
210     }
211 
212 
213     QUuid.Variant variant() const/+ noexcept+/;
214     QUuid.Version version_() const/+ noexcept+/;
215 
216     static if((versionIsSet!("OSX") || versionIsSet!("iOS") || versionIsSet!("TVOS") || versionIsSet!("WatchOS")))
217     {
218         /+ static QUuid fromCFUUID(CFUUIDRef uuid); +/
219         /+ CFUUIDRef toCFUUID() const Q_DECL_CF_RETURNS_RETAINED; +/
220         /+ static QUuid fromNSUUID(const NSUUID *uuid); +/
221         /+ NSUUID *toNSUUID() const Q_DECL_NS_RETURNS_AUTORELEASED; +/
222     }
223 
224     uint    data1;
225     ushort  data2;
226     ushort  data3;
227     uchar[8]   data4;
228 }
229 
230 /+ Q_DECLARE_TYPEINFO(QUuid, Q_PRIMITIVE_TYPE);
231 
232 #ifndef QT_NO_DATASTREAM
233 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QUuid &);
234 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QUuid &);
235 #endif
236 
237 #ifndef QT_NO_DEBUG_STREAM
238 Q_CORE_EXPORT QDebug operator<<(QDebug, const QUuid &);
239 #endif
240 
241 Q_CORE_EXPORT uint qHash(const QUuid &uuid, uint seed = 0) noexcept; +/
242 
243 /+pragma(inline, true) bool operator <=(ref const(QUuid) lhs, ref const(QUuid) rhs)/+ noexcept+/
244 { return !(rhs < lhs); }+/
245 /+pragma(inline, true) bool operator >=(ref const(QUuid) lhs, ref const(QUuid) rhs)/+ noexcept+/
246 { return !(lhs < rhs); }+/
247