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