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