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