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