311
|
1 module qt.QGlobal;
|
|
2
|
|
3 public import qt.qtd.Str;
|
|
4 public import qt.QDefines;
|
|
5
|
|
6 version (D_Version2)
|
|
7 {
|
|
8 import std.stdio;
|
|
9 package import std.c.stdlib,
|
|
10 core.memory;
|
|
11 }
|
|
12 else
|
|
13 {
|
|
14 import tango.io.Stdout;
|
|
15 import tango.core.Thread;
|
|
16
|
|
17 void writeln(string s)
|
|
18 {
|
|
19 Stdout(s).newline;
|
|
20 }
|
|
21 package import tango.stdc.stdlib,
|
|
22 tango.core.Memory;
|
|
23 }
|
|
24
|
|
25 private enum : size_t { stackSize = 1024 * 1024 }
|
|
26
|
|
27 template QT_BEGIN_NAMESPACE() {
|
|
28 }
|
|
29
|
|
30 template QT_END_NAMESPACE() {
|
|
31 }
|
|
32
|
|
33 template QT_BEGIN_HEADER() {
|
|
34 }
|
|
35
|
|
36 template QT_END_HEADER() {
|
|
37 }
|
|
38
|
|
39 mixin QT_BEGIN_HEADER;
|
|
40 mixin QT_BEGIN_NAMESPACE;
|
|
41
|
|
42 extern(C) void qtd_dummy() {}
|
|
43 // Defined in QtdObject.d
|
|
44 extern(C) void qtd_delete_d_object(void* dPtr);
|
|
45
|
|
46 version(cpp_shared)
|
|
47 {
|
|
48 extern (C) void qtd_core_initCallBacks(void* toUtf8, void* dummy, void* del_d_obj);
|
|
49 static this() {
|
|
50 qtd_core_initCallBacks(&qtd_toUtf8, &qtd_dummy, &qtd_delete_d_object);
|
|
51 }
|
|
52 }
|
|
53
|
|
54 string tr(string arg) {
|
|
55 return arg;
|
|
56 }
|
|
57
|
|
58 /*
|
|
59 can be used like #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
|
|
60 */
|
|
61 bool QT_VERSION_CHECK( ushort major, ushort minor, ushort patch )
|
|
62 {
|
|
63 return cast(bool)((major<<16)|(minor<<8)|(patch));
|
|
64 }
|
|
65 //TODO(katrina) get this from the C++ side
|
|
66 const char[] QT_PACKAGEDATE_STR = "2008-09-27";
|
|
67 //TODO(katrina) get this from the C++ side
|
|
68 const char[] QT_PACKAGE_TAG = "gc9953de622c6a0f655322e0d9f5bd6dc2803b470";
|
|
69
|
|
70 /*
|
|
71 Size-dependent types (architechture-dependent byte order)
|
|
72
|
|
73 Make sure to update QMetaType when changing these typedefs
|
|
74 */
|
|
75
|
|
76 alias char qint8; /* 8 bit signed */
|
|
77 alias char quint8; /* 8 bit unsigned */
|
|
78 alias short qint16; /* 16 bit signed */
|
|
79 alias ushort quint16; /* 16 bit unsigned */
|
|
80 alias int qint32; /* 32 bit signed */
|
|
81 alias uint quint32; /* 32 bit unsigned */
|
|
82 alias long qint64; /* 64 bit signed */
|
|
83 alias ulong quint64; /* 64 bit unsigned */
|
|
84
|
|
85 version (X86)
|
|
86 {
|
|
87 alias quint32 quintptr;
|
|
88 alias qint32 qptrdiff;
|
|
89 }
|
|
90 else version (X86_64)
|
|
91 {
|
|
92 alias quint64 quintptr;
|
|
93 alias qint64 qptrdiff;
|
|
94 }
|
|
95
|
|
96 const byte QT_POINTER_SIZE = 8;
|
|
97
|
|
98 alias int QNoImplicitBoolCast;
|
|
99
|
|
100 alias double qreal;
|
|
101
|
|
102
|
|
103 /*
|
|
104 Utility macros and inline functions
|
|
105 TODO(katrina) see if we need to do anything to make these
|
|
106 able to be evaluated at compile time
|
|
107 */
|
|
108
|
|
109 T qAbs(T)(T t) { return t >= 0 ? t : -t; }
|
|
110
|
|
111 int qRound(qreal d)
|
|
112 { return d >= 0.0 ? cast(int)(d + 0.5) : cast(int)(d - cast(int)(d-1) + 0.5) + cast(int)(d-1); }
|
|
113
|
|
114 qint64 qRound64(qreal d)
|
|
115 { return d >= 0.0 ? cast(qint64)(d + 0.5) : cast(qint64)(d - cast(qint64)(d-1) + 0.5) + cast(qint64)(d-1); }
|
|
116
|
|
117 T qMin(T)(T a,T b) { if (a < b) return a; return b; }
|
|
118 T qMax(T)(T a, T b) { if (a < b) return b; return a; }
|
|
119 T qBound(T)(T min, T val,T max) { return qMax(min, qMin(max, val)); }
|
|
120
|
|
121 /*
|
|
122 Data stream functions are provided by many classes (defined in qdatastream.h)
|
|
123 */
|
|
124
|
|
125 //class QDataStream;
|
|
126
|
|
127 /*
|
|
128 System information
|
|
129 */
|
|
130
|
|
131 class QSysInfo {
|
|
132 public:
|
|
133 enum Sizes {
|
|
134 WordSize = ((void *).sizeof<<3)
|
|
135 };
|
|
136
|
|
137 enum Endian {
|
|
138 BigEndian,
|
|
139 LittleEndian,
|
|
140 ByteOrder = BigEndian
|
|
141 };
|
|
142 /* needed to bootstrap qmake */
|
|
143 static const int ByteOrder;
|
|
144
|
|
145 enum WinVersion {
|
|
146 WV_32s = 0x0001,
|
|
147 WV_95 = 0x0002,
|
|
148 WV_98 = 0x0003,
|
|
149 WV_Me = 0x0004,
|
|
150 WV_DOS_based= 0x000f,
|
|
151
|
|
152 WV_NT = 0x0010,
|
|
153 WV_2000 = 0x0020,
|
|
154 WV_XP = 0x0030,
|
|
155 WV_2003 = 0x0040,
|
|
156 WV_VISTA = 0x0080,
|
|
157 WV_NT_based = 0x00f0,
|
|
158
|
|
159 WV_CE = 0x0100,
|
|
160 WV_CENET = 0x0200,
|
|
161 WV_CE_5 = 0x0300,
|
|
162 WV_CE_6 = 0x0400,
|
|
163 WV_CE_based = 0x0f00
|
|
164 };
|
|
165 static const WinVersion WindowsVersion;
|
|
166 static WinVersion windowsVersion();
|
|
167
|
|
168 enum MacVersion {
|
|
169 MV_Unknown = 0x0000,
|
|
170
|
|
171 /* version */
|
|
172 MV_9 = 0x0001,
|
|
173 MV_10_0 = 0x0002,
|
|
174 MV_10_1 = 0x0003,
|
|
175 MV_10_2 = 0x0004,
|
|
176 MV_10_3 = 0x0005,
|
|
177 MV_10_4 = 0x0006,
|
|
178 MV_10_5 = 0x0007,
|
|
179
|
|
180 /* codenames */
|
|
181 MV_CHEETAH = MV_10_0,
|
|
182 MV_PUMA = MV_10_1,
|
|
183 MV_JAGUAR = MV_10_2,
|
|
184 MV_PANTHER = MV_10_3,
|
|
185 MV_TIGER = MV_10_4,
|
|
186 MV_LEOPARD = MV_10_5
|
|
187 };
|
|
188 static const MacVersion MacintoshVersion;
|
|
189 };
|
|
190
|
|
191
|
|
192 extern(C) stringz qtd_qVersion();
|
|
193 ///
|
|
194 string qVersion()
|
|
195 {
|
|
196 return fromStringz(qtd_qVersion);
|
|
197 }
|
|
198
|
|
199 extern(C) bool qtd_qSharedBuild();
|
|
200 ///
|
|
201 bool qSharedBuild()
|
|
202 {
|
|
203 return qtd_qSharedBuild;
|
|
204 }
|
|
205
|
|
206 ///
|
|
207 int qMacVersion() { return QSysInfo.MacintoshVersion; }
|
|
208
|
|
209 ///
|
|
210 void qUnused(T)(T x) { cast(void) x; }
|
|
211 ///
|
|
212 void Q_UNUSED(T)(T x) { qUnused(x); }
|
|
213
|
|
214 /*
|
|
215 Debugging and error handling
|
|
216 */
|
|
217
|
|
218 //class QString;
|
|
219 //char[] qPrintable(QString string) { string.toLocal8Bit().constData(); }
|
|
220 //TODO(katrina) These should probably actually call into the c++ functions
|
|
221 void qDebug(string str) /* print debug message */
|
|
222 { writeln(str); }
|
|
223
|
|
224 extern (C) void Qt_qWarning( char * );
|
|
225
|
|
226 void qWarning(char[] str) /* print warning message */
|
|
227 { writeln(str); }
|
|
228
|
|
229 //QString qt_error_string(int errorCode = -1);
|
|
230 void qCritical(char[] str) /* print critical message */
|
|
231 { writeln(str); }
|
|
232
|
|
233 /*
|
|
234 Forward declarations only.
|
|
235
|
|
236 In order to use the qDebug() stream, you must #include<QDebug>
|
|
237 */
|
|
238 //class QDebug;
|
|
239 //class QNoDebug;
|
|
240 //QDebug qDebug();
|
|
241 //QDebug qWarning();
|
|
242 //QDebug qCritical();
|
|
243
|
|
244 void qt_noop() {}
|
|
245 //TODO(katrina) Implement these
|
|
246 void qt_assert(char[] assertion, char[] file, int line);
|
|
247
|
|
248 void qt_assert_x(char[] where, char[] what, char[] file, int line);
|
|
249
|
|
250 void qt_check_pointer(char[], int);
|
|
251
|
|
252 enum QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, QtSystemMsg = QtCriticalMsg };
|
|
253
|
|
254 void qt_message_output(QtMsgType, char[] buf);
|
|
255 //class QtMsgHandler;
|
|
256 //QtMsgHandler qInstallMsgHandler(QtMsgHandler);
|
|
257
|
|
258 // forward declaration, since qatomic.h needs qglobal.h
|
|
259 class QBasicAtomicPointer(T);
|
|
260
|
|
261 // POD for Q_GLOBAL_STATIC
|
|
262 class QGlobalStatic(T)
|
|
263 {
|
|
264 public:
|
|
265 QBasicAtomicPointer!(T) pointer;
|
|
266 bool destroyed;
|
|
267 };
|
|
268
|
|
269 // Created as a function-local static to delete a QGlobalStatic<T>
|
|
270 class QGlobalStaticDeleter(T)
|
|
271 {
|
|
272 public:
|
|
273 QGlobalStatic!(T) globalStatic;
|
|
274 this(QGlobalStatic!(T) _globalStatic) {
|
|
275 globalStatic(_globalStatic);
|
|
276 }
|
|
277
|
|
278 ~this()
|
|
279 {
|
|
280 delete globalStatic.pointer;
|
|
281 globalStatic.pointer = 0;
|
|
282 globalStatic.destroyed = true;
|
|
283 }
|
|
284 };
|
|
285
|
|
286 class QBool
|
|
287 {
|
|
288 bool b;
|
|
289
|
|
290 public:
|
|
291 this(bool B) { b = B; }
|
|
292 // void *() const
|
|
293 // { return b ? static_cast<const void *>(this) : static_cast<const void *>(0); }
|
|
294 }
|
|
295
|
|
296 bool qFuzzyCompare(double p1, double p2)
|
|
297 {
|
|
298 return (qAbs(p1 - p2) <= 0.000000000001 * qMin(qAbs(p1), qAbs(p2)));
|
|
299 }
|
|
300
|
|
301 bool qFuzzyCompare(float p1, float p2)
|
|
302 {
|
|
303 return (qAbs(p1 - p2) <= 0.00001f * qMin(qAbs(p1), qAbs(p2)));
|
|
304 }
|
|
305
|
|
306 /*
|
|
307 This function tests a double for a null value. It doesn't
|
|
308 check whether the actual value is 0 or close to 0, but whether
|
|
309 it is binary 0.
|
|
310 */
|
|
311 bool qIsNull(double d)
|
|
312 {
|
|
313 union U {
|
|
314 double d;
|
|
315 quint64 u;
|
|
316 };
|
|
317 U val;
|
|
318 val.d = d;
|
|
319 return val.u == cast(quint64)(0);
|
|
320 }
|
|
321
|
|
322 /*
|
|
323 This function tests a float for a null value. It doesn't
|
|
324 check whether the actual value is 0 or close to 0, but whether
|
|
325 it is binary 0.
|
|
326 */
|
|
327 bool qIsNull(float f)
|
|
328 {
|
|
329 union U {
|
|
330 float f;
|
|
331 quint32 u;
|
|
332 };
|
|
333 U val;
|
|
334 val.f = f;
|
|
335 return val.u == 0u;
|
|
336 }
|
|
337
|
|
338 /*
|
|
339 Compilers which follow outdated template instantiation rules
|
|
340 require a class to have a comparison operator to exist when
|
|
341 a QList of this type is instantiated. It's not actually
|
|
342 used in the list, though. Hence the dummy implementation.
|
|
343 Just in case other code relies on it we better trigger a warning
|
|
344 mandating a real implementation.
|
|
345 */
|
|
346
|
|
347
|
|
348 /*
|
|
349 QTypeInfo - type trait functionality
|
|
350 qIsDetached - data sharing functionality
|
|
351 */
|
|
352
|
|
353 /*
|
|
354 The catch-all template.
|
|
355 */
|
|
356
|
|
357 bool qIsDetached(T)(T) { return true; }
|
|
358
|
|
359 class QTypeInfossss(T)
|
|
360 {
|
|
361 public:
|
|
362 enum {
|
|
363 isPointer = false,
|
|
364 isComplex = true,
|
|
365 isStatic = true,
|
|
366 isLarge = ((T).sizeof>(void*).sizeof),
|
|
367 isDummy = false
|
|
368 };
|
|
369 };
|
|
370
|
|
371 class QTypeInfo(T)
|
|
372 {
|
|
373 public:
|
|
374 enum {
|
|
375 isPointer = true,
|
|
376 isComplex = false,
|
|
377 isStatic = false,
|
|
378 isLarge = false,
|
|
379 isDummy = false
|
|
380 };
|
|
381 };
|
|
382
|
|
383
|
|
384 /*
|
|
385 Specialize a specific type with:
|
|
386
|
|
387 Q_DECLARE_TYPEINFO(type, flags);
|
|
388
|
|
389 where 'type' is the name of the type to specialize and 'flags' is
|
|
390 logically-OR'ed combination of the flags below.
|
|
391 */
|
|
392 enum { /* TYPEINFO flags */
|
|
393 Q_COMPLEX_TYPE = 0,
|
|
394 Q_PRIMITIVE_TYPE = 0x1,
|
|
395 Q_STATIC_TYPE = 0,
|
|
396 Q_MOVABLE_TYPE = 0x2,
|
|
397 Q_DUMMY_TYPE = 0x4
|
|
398 };
|
|
399
|
|
400 /*
|
|
401 Specialize a shared type with:
|
|
402
|
|
403 Q_DECLARE_SHARED(type);
|
|
404
|
|
405 where 'type' is the name of the type to specialize. NOTE: shared
|
|
406 types must declare a 'bool isDetached(void) const;' member for this
|
|
407 to work.
|
|
408 */
|
|
409 void qSwap_helper(T)(ref T value1, ref T value2, T*)
|
|
410 {
|
|
411 T t = value1;
|
|
412 value1 = value2;
|
|
413 value2 = t;
|
|
414 }
|
|
415 bool qIsDetached(T)(ref T t) { return t.isDetached(); }
|
|
416 void qSwap_helper(T)(ref T value1, ref T value2, T*)
|
|
417 {
|
|
418 const T.DataPtr t = value1.data_ptr();
|
|
419 value1.data_ptr() = value2.data_ptr();
|
|
420 value2.data_ptr() = t;
|
|
421 }
|
|
422
|
|
423 void qSwap(T)(ref T value1, ref T value2)
|
|
424 {
|
|
425 T t = value1;
|
|
426 value1 = value2;
|
|
427 value2 = t;
|
|
428 }
|
|
429
|
|
430 /*
|
|
431 QTypeInfo primitive specializations
|
|
432 TODO(katrina) Find out what we need to do here
|
|
433 */
|
|
434 /*
|
|
435 Q_DECLARE_TYPEINFO(bool, Q_PRIMITIVE_TYPE);
|
|
436 Q_DECLARE_TYPEINFO(char, Q_PRIMITIVE_TYPE);
|
|
437 Q_DECLARE_TYPEINFO(signed char, Q_PRIMITIVE_TYPE);
|
|
438 Q_DECLARE_TYPEINFO(uchar, Q_PRIMITIVE_TYPE);
|
|
439 Q_DECLARE_TYPEINFO(short, Q_PRIMITIVE_TYPE);
|
|
440 Q_DECLARE_TYPEINFO(ushort, Q_PRIMITIVE_TYPE);
|
|
441 Q_DECLARE_TYPEINFO(int, Q_PRIMITIVE_TYPE);
|
|
442 Q_DECLARE_TYPEINFO(uint, Q_PRIMITIVE_TYPE);
|
|
443 Q_DECLARE_TYPEINFO(long, Q_PRIMITIVE_TYPE);
|
|
444 Q_DECLARE_TYPEINFO(ulong, Q_PRIMITIVE_TYPE);
|
|
445 Q_DECLARE_TYPEINFO(qint64, Q_PRIMITIVE_TYPE);
|
|
446 Q_DECLARE_TYPEINFO(quint64, Q_PRIMITIVE_TYPE);
|
|
447 Q_DECLARE_TYPEINFO(float, Q_PRIMITIVE_TYPE);
|
|
448 Q_DECLARE_TYPEINFO(double, Q_PRIMITIVE_TYPE);
|
|
449 #ifndef Q_OS_DARWIN
|
|
450 Q_DECLARE_TYPEINFO(long double, Q_PRIMITIVE_TYPE);
|
|
451 #endif
|
|
452 */
|
|
453 /*
|
|
454 These functions make it possible to use standard C++ functions with
|
|
455 a similar name from Qt header files (especially template classes).
|
|
456 TODO(katrina) Implement these
|
|
457 */
|
|
458 void * qMalloc(size_t size);
|
|
459 void qFree(void * ptr);
|
|
460 void * qRealloc(void * ptr, size_t size);
|
|
461 void * qMemCopy(void * dest, void * src, size_t n);
|
|
462 void * qMemSet(void * dest, int c, size_t n);
|
|
463
|
|
464 struct QFlags(Enum)
|
|
465 {
|
|
466 private:
|
|
467 alias void **Zero;
|
|
468 int i;
|
|
469
|
|
470 public:
|
|
471 alias Enum enum_type;
|
|
472
|
|
473 public static QFlags!(Enum) opCall(Enum)(QFlags f) {
|
|
474 QFlags!(Enum) res;
|
|
475 res.i = f.i;
|
|
476 return res;
|
|
477 }
|
|
478
|
|
479 public static QFlags opCall(Enum)(Enum f) {
|
|
480 QFlags!(Enum) res;
|
|
481 res.i = f;
|
|
482 return res;
|
|
483 }
|
|
484
|
|
485 public static QFlags opCall(Enum)(int f) {
|
|
486 QFlags!(Enum) res;
|
|
487 res.i = cast(Enum) f;
|
|
488 return res;
|
|
489 }
|
|
490
|
|
491 // this(Zero = 0) : i(0) {}
|
|
492 // this(QFlag f) : i(f) {}
|
|
493
|
|
494 // QFlags!(Enum) opAssign(QFlags f) { i = f.i; return *this; }
|
|
495 QFlags!(Enum) opAssign(int f) { i = f; return *this; }
|
|
496 QFlags!(Enum) opAndAssign(int mask) { i &= mask; return *this; }
|
|
497 QFlags!(Enum) opAndAssign(uint mask) { i &= mask; return *this; }
|
|
498 QFlags!(Enum) opOrAssign(QFlags f) { i |= f.i; return *this; }
|
|
499 QFlags!(Enum) opOrAssign(Enum f) { i |= f; return *this; }
|
|
500 QFlags!(Enum) opXorAssign(QFlags f) { i ^= f.i; return *this; }
|
|
501 QFlags!(Enum) opXorAssign(Enum f) { i ^= f; return *this; }
|
|
502
|
|
503 int toInt() { return i; }
|
|
504
|
|
505 QFlags!(Enum) opOr(QFlags f) { QFlags g; g.i = i | f.i; return g; }
|
|
506 QFlags!(Enum) opOr(Enum f) { QFlags g; g.i = i | f; return g; }
|
|
507 QFlags!(Enum) opXor(QFlags f) { QFlags g; g.i = i ^ f.i; return g; }
|
|
508 QFlags!(Enum) opXor(Enum f) { QFlags g; g.i = i ^ f; return g; }
|
|
509 QFlags!(Enum) opAnd(int mask) { QFlags g; g.i = i & mask; return g; }
|
|
510 QFlags!(Enum) opAnd(uint mask) { QFlags g; g.i = i & mask; return g; }
|
|
511 QFlags!(Enum) opAnd(Enum f) { QFlags g; g.i = i & f; return g; }
|
|
512 QFlags!(Enum) opCom() { QFlags g; g.i = ~i; return g; }
|
|
513
|
|
514 // bool operator!() { return !i; }
|
|
515
|
|
516 // bool testFlag(Enum f) { return i & f; }
|
|
517 }
|
|
518
|
|
519 /* TODO typesafety
|
|
520 #define Q_DECLARE_FLAGS(Flags, Enum)\
|
|
521 typedef QFlags<Enum> Flags;
|
|
522 #define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags) \
|
|
523 QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) \
|
|
524 { return QFlags<Flags::enum_type>(f1) | f2; } \
|
|
525 QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) \
|
|
526 { return f2 | f1; }
|
|
527 */
|
|
528
|
|
529 char[] QT_TR_NOOP(char[] x) { return x; }
|
|
530 char[] QT_TRANSLATE_NOOP(char[] s, char[] x) { return x; }
|
|
531 char[] QT_TRANSLATE_NOOP3(char[] s, char[] x, char[] comment) { return x; }
|
|
532
|
|
533 //class QByteArray;
|
|
534 //QByteArray qgetenv(char[] varName);
|
|
535 //bool qputenv(char[] varName, QByteArray value);
|
|
536
|
|
537 int qIntCast(double f) { return cast(int)(f); }
|
|
538 int qIntCast(float f) { return cast(int)(f); }
|
|
539
|
|
540 /*
|
|
541 Reentrant versions of basic rand() functions for random number generation
|
|
542 */
|
|
543 void qsrand(uint seed);
|
|
544 int qrand();
|
|
545
|
|
546
|
|
547 /*
|
|
548 This gives us the possibility to check which modules the user can
|
|
549 use. These are purely compile time checks and will generate no code.
|
|
550 */
|
|
551
|
|
552 /* Qt modules */
|
|
553
|
|
554 const ushort QT_MODULE_CORE = 0x0001;
|
|
555 const ushort QT_MODULE_GUI = 0x0002;
|
|
556 const ushort QT_MODULE_NETWORK = 0x0004;
|
|
557 const ushort QT_MODULE_OPENGL = 0x0008;
|
|
558 const ushort QT_MODULE_SQL = 0x0010;
|
|
559 const ushort QT_MODULE_XML = 0x0020;
|
|
560 const ushort QT_MODULE_QT3SUPPORTLIGHT = 0x0040;
|
|
561 const ushort QT_MODULE_QT3SUPPORT = 0x0080;
|
|
562 const ushort QT_MODULE_SVG = 0x0100;
|
|
563 const ushort QT_MODULE_ACTIVEQT = 0x0200;
|
|
564 const ushort QT_MODULE_GRAPHICSVIEW = 0x0400;
|
|
565 const ushort QT_MODULE_SCRIPT = 0x0800;
|
|
566 const ushort QT_MODULE_XMLPATTERNS = 0x1000;
|
|
567 const ushort QT_MODULE_HELP = 0x2000;
|
|
568 const ushort QT_MODULE_TEST = 0x4000;
|
|
569 const ushort QT_MODULE_DBUS = 0x8000;
|
|
570
|
|
571 /* Qt editions */
|
|
572
|
|
573 const ushort QT_EDITION_CONSOLE = (QT_MODULE_CORE
|
|
574 | QT_MODULE_NETWORK
|
|
575 | QT_MODULE_SQL
|
|
576 | QT_MODULE_SCRIPT
|
|
577 | QT_MODULE_XML
|
|
578 | QT_MODULE_XMLPATTERNS
|
|
579 | QT_MODULE_TEST
|
|
580 | QT_MODULE_DBUS);
|
|
581 const ushort QT_EDITION_DESKTOPLIGHT = (QT_MODULE_CORE
|
|
582 | QT_MODULE_GUI
|
|
583 | QT_MODULE_QT3SUPPORTLIGHT
|
|
584 | QT_MODULE_TEST
|
|
585 | QT_MODULE_DBUS);
|
|
586 const ushort QT_EDITION_OPENSOURCE = (QT_MODULE_CORE
|
|
587 | QT_MODULE_GUI
|
|
588 | QT_MODULE_NETWORK
|
|
589 | QT_MODULE_OPENGL
|
|
590 | QT_MODULE_SQL
|
|
591 | QT_MODULE_XML
|
|
592 | QT_MODULE_XMLPATTERNS
|
|
593 | QT_MODULE_SCRIPT
|
|
594 | QT_MODULE_QT3SUPPORTLIGHT
|
|
595 | QT_MODULE_QT3SUPPORT
|
|
596 | QT_MODULE_SVG
|
|
597 | QT_MODULE_GRAPHICSVIEW
|
|
598 | QT_MODULE_HELP
|
|
599 | QT_MODULE_TEST
|
|
600 | QT_MODULE_DBUS);
|
|
601 const ushort QT_EDITION_DESKTOP = (QT_EDITION_OPENSOURCE
|
|
602 | QT_MODULE_ACTIVEQT);
|
|
603 const ushort QT_EDITION_UNIVERSAL = QT_EDITION_DESKTOP;
|
|
604 const ushort QT_EDITION_ACADEMIC = QT_EDITION_DESKTOP;
|
|
605 const ushort QT_EDITION_EDUCATIONAL = QT_EDITION_DESKTOP;
|
|
606 const ushort QT_EDITION_EVALUATION = QT_EDITION_DESKTOP;
|
|
607
|
|
608 mixin QT_END_NAMESPACE;
|
|
609
|
|
610 private
|
|
611 struct Align
|
|
612 {
|
|
613 ubyte a;
|
|
614 void* b;
|
|
615 }
|
|
616
|
|
617 private
|
|
618 const PTR_ALIGN = Align.tupleof[1].alignof;
|
|
619
|
|
620 private
|
|
621 template AlignPad(size_t base, size_t aligned)
|
|
622 {
|
|
623 static if( aligned == 0 )
|
|
624 const AlignPad = base;
|
|
625 else
|
|
626 const AlignPad = ((base+PTR_ALIGN-1)/PTR_ALIGN)*PTR_ALIGN
|
|
627 + aligned;
|
|
628 }
|
|
629
|
|
630 template InstanceSize(T)
|
|
631 {
|
|
632 static if( is( T == Object ) )
|
|
633 const InstanceSize = 2*(void*).sizeof;
|
|
634 else
|
|
635 const InstanceSize = Max!(
|
|
636 AlignPad!(
|
|
637 InstanceSize!(Super!(T)),
|
|
638 InterfaceCount!(T)*(void*).sizeof),
|
|
639
|
|
640 AlignPad!(
|
|
641 InstanceSizeImpl!(T, 0),
|
|
642 + InterfaceCount!(T)*(void*).sizeof));
|
|
643 }
|
|
644
|
|
645 private
|
|
646 template Super(T)
|
|
647 {
|
|
648 static if( is( T S == super ) )
|
|
649 alias First!(S) Super;
|
|
650 else
|
|
651 static assert(false, "Can't get super of "~T.mangleof);
|
|
652 }
|
|
653
|
|
654 private
|
|
655 template First(T)
|
|
656 {
|
|
657 alias T First;
|
|
658 }
|
|
659
|
|
660 private
|
|
661 template First(T, Ts...)
|
|
662 {
|
|
663 alias T First;
|
|
664 }
|
|
665
|
|
666 private
|
|
667 template InstanceSizeImpl(T, size_t i)
|
|
668 {
|
|
669 static if( i < T.tupleof.length )
|
|
670 const InstanceSizeImpl = Max!(
|
|
671 T.tupleof[i].offsetof + T.tupleof[i].sizeof,
|
|
672 InstanceSizeImpl!(T, i+1));
|
|
673 else
|
|
674 // This is necessary to account for classes without member
|
|
675 // variables.
|
|
676 const InstanceSizeImpl = 2*(void*).sizeof;
|
|
677 }
|
|
678
|
|
679 private
|
|
680 template Max(size_t a, size_t b)
|
|
681 {
|
|
682 static if( a > b )
|
|
683 const Max = a;
|
|
684 else
|
|
685 const Max = b;
|
|
686 }
|
|
687
|
|
688 private
|
|
689 template InterfaceCount(T)
|
|
690 {
|
|
691 static if( is( T == Object ) )
|
|
692 const InterfaceCount = 0u;
|
|
693 else static if( is( T S == super ) )
|
|
694 const InterfaceCount = InterfaceCountImpl!(S);
|
|
695 }
|
|
696
|
|
697 private
|
|
698 template InterfaceCountImpl(TBase, TInterfaces...)
|
|
699 {
|
|
700 const InterfaceCountImpl = TInterfaces.length;
|
|
701 }
|
|
702
|
|
703 /+
|
|
704 scope class StackObject(C)
|
|
705 {
|
|
706 byte[InstanceSize!(C)] data;
|
|
707 bool constructed;
|
|
708
|
|
709 C opCall(A...)(A args)
|
|
710 {
|
|
711 assert(!constructed);
|
|
712
|
|
713 auto r = new(&data)C(args);
|
|
714 r.__stackAllocated = true;
|
|
715 constructed = true;
|
|
716
|
|
717 return r;
|
|
718 }
|
|
719
|
|
720 ~this()
|
|
721 {
|
|
722 if (constructed)
|
|
723 {
|
|
724 auto obj = cast(C)&data;
|
|
725 delete obj;
|
|
726 }
|
|
727 }
|
|
728 }
|
|
729 +/
|
|
730
|
|
731 mixin QT_END_HEADER;
|
|
732
|