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