annotate qt/QGlobal.d @ 194:ba7abb5c9e03

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