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