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