Mercurial > projects > qtd
annotate qt/core/QList.d @ 295:463563fc9e17 signals
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
author | eldar |
---|---|
date | Sun, 22 Nov 2009 11:01:19 +0000 |
parents | bb37b0ed94c9 |
children | 5173835bb372 |
rev | line source |
---|---|
291 | 1 module qt.core.QList; |
2 | |
3 import qt.QGlobal; | |
293 | 4 import qt.QtdObject; |
291 | 5 import qt.qtd.Atomic; |
293 | 6 import qt.qtd.MetaMarshall; |
295
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
7 import qt.core.QTypeInfo; |
292 | 8 |
291 | 9 import core.stdc.stdlib : qRealloc = realloc, qFree = free, qMalloc = malloc; |
10 import core.stdc.string : memcpy, memmove; | |
11 | |
292 | 12 import std.traits; |
13 | |
291 | 14 enum INT_MAX = int.max; |
15 | |
292 | 16 bool isComplex(T)() |
293 | 17 if (is(T.QTypeInfo)) |
292 | 18 { |
293 | 19 return T.QTypeInfo.isComplex; |
292 | 20 } |
21 | |
22 bool isStatic(T)() | |
293 | 23 if (is(T.QTypeInfo)) |
292 | 24 { |
293 | 25 return T.QTypeInfo.isStatic; |
292 | 26 } |
27 | |
28 bool isLarge(T)() | |
293 | 29 if (is(T.QTypeInfo)) |
292 | 30 { |
293 | 31 return T.QTypeInfo.isLarge; |
292 | 32 } |
33 | |
291 | 34 int qAllocMore(int alloc, int extra) |
35 { | |
36 if (alloc == 0 && extra == 0) | |
37 return 0; | |
38 const int page = 1 << 12; | |
39 int nalloc; | |
40 alloc += extra; | |
41 if (alloc < 1<<6) { | |
42 nalloc = (1<<3) + ((alloc >>3) << 3); | |
43 } else { | |
44 // don't do anything if the loop will overflow signed int. | |
45 if (alloc >= INT_MAX/2) | |
46 return INT_MAX; | |
47 nalloc = (alloc < page) ? 1 << 3 : page; | |
48 while (nalloc < alloc) { | |
49 if (nalloc <= 0) | |
50 return INT_MAX; | |
51 nalloc *= 2; | |
52 } | |
53 } | |
54 return nalloc - extra; | |
55 } | |
56 | |
295
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
57 void q_new_at(T)(T* ptr, const ref T t) |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
58 { |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
59 memcpy(ptr, &t, T.sizeof); |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
60 /* static if (__traits(compiles, ptr.__postblit())) DMD bug #3539 |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
61 ptr.__postblit();*/ |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
62 } |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
63 |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
64 T* q_new(T)(const ref T t) |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
65 { |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
66 T* ptr = cast(T*) qMalloc(T.sizeof); |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
67 q_new_at!T(ptr, t); |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
68 return ptr; |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
69 } |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
70 |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
71 void q_delete(T)(T* t) |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
72 { |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
73 static if (__traits(compiles, t.__dtor())) |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
74 t.__dtor(); |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
75 qFree(t); |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
76 } |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
77 |
291 | 78 private int grow(int size) |
79 { | |
80 // dear compiler: don't optimize me out. | |
292 | 81 // synchronized { |
291 | 82 int x = qAllocMore(size * (void*).sizeof, QListData.DataHeaderSize) / (void*).sizeof; |
83 return x; | |
292 | 84 // } |
291 | 85 } |
86 | |
87 struct QListData { | |
88 struct Data { | |
89 Atomic!int ref_; | |
90 int alloc, begin, end; | |
91 uint sharable; | |
92 void*[1] array; | |
93 } | |
94 | |
95 enum { DataHeaderSize = Data.sizeof - (void*).sizeof } | |
96 | |
97 static Data shared_null; | |
98 Data *d; | |
99 | |
100 static this() | |
101 { | |
102 shared_null = Data(Atomic!int(1), 0, 0, 0, true, [null]); | |
103 } | |
104 | |
105 | |
106 // Data *detach(); // remove in 5.0 | |
107 | |
108 Data* detach2() | |
109 { | |
110 Data* x = d; | |
111 d = cast(Data*)(qMalloc(DataHeaderSize + x.alloc * (void*).sizeof)); | |
112 if (!d) | |
113 qFatal("QList: Out of memory"); | |
114 | |
115 memcpy(d, x, DataHeaderSize + x.alloc * (void*).sizeof); | |
116 d.alloc = x.alloc; | |
117 d.ref_.store(1); | |
118 d.sharable = true; | |
119 if (!d.alloc) | |
120 d.begin = d.end = 0; | |
121 | |
122 return x; | |
123 } | |
124 | |
125 void realloc(int alloc) | |
126 { | |
127 // assert(d.ref_ == 1); | |
128 Data* x = cast(Data*)(qRealloc(d, DataHeaderSize + alloc * (void*).sizeof)); | |
129 if (!x) | |
130 qFatal("QList: Out of memory"); | |
131 | |
132 d = x; | |
133 d.alloc = alloc; | |
134 if (!alloc) | |
135 d.begin = d.end = 0; | |
136 } | |
137 | |
138 void** append() | |
139 { | |
140 // #TODO Q_ASSERT(d.ref_ == 1); | |
141 if (d.end == d.alloc) { | |
142 int n = d.end - d.begin; | |
143 if (d.begin > 2 * d.alloc / 3) { | |
144 memcpy(d.array.ptr + n, d.array.ptr + d.begin, n * (void*).sizeof); | |
145 d.begin = n; | |
146 d.end = n * 2; | |
147 } else { | |
148 realloc(grow(d.alloc + 1)); | |
149 } | |
150 } | |
151 return d.array.ptr + d.end++; | |
152 } | |
153 | |
154 void **append(const ref QListData l) | |
155 { | |
156 // Q_ASSERT(d.ref_ == 1); | |
157 int e = d.end; | |
158 int n = l.d.end - l.d.begin; | |
159 if (n) { | |
160 if (e + n > d.alloc) | |
161 realloc(grow(e + l.d.end - l.d.begin)); | |
162 memcpy(d.array.ptr + d.end, l.d.array.ptr + l.d.begin, n * (void*).sizeof); | |
163 d.end += n; | |
164 } | |
165 return d.array.ptr + e; | |
166 } | |
167 | |
168 void **prepend() | |
169 { | |
170 // Q_ASSERT(d.ref_ == 1); | |
171 if (d.begin == 0) { | |
172 if (d.end >= d.alloc / 3) | |
173 realloc(grow(d.alloc + 1)); | |
174 | |
175 if (d.end < d.alloc / 3) | |
176 d.begin = d.alloc - 2 * d.end; | |
177 else | |
178 d.begin = d.alloc - d.end; | |
179 | |
180 memmove(d.array.ptr + d.begin, d.array.ptr, d.end * (void*).sizeof); | |
181 d.end += d.begin; | |
182 } | |
183 return d.array.ptr + --d.begin; | |
184 } | |
185 | |
186 void **insert(int i) | |
187 { | |
188 // Q_ASSERT(d.ref_ == 1); | |
189 if (i <= 0) | |
190 return prepend(); | |
191 if (i >= d.end - d.begin) | |
192 return append(); | |
193 | |
194 bool leftward = false; | |
195 int size = d.end - d.begin; | |
196 | |
197 if (d.begin == 0) { | |
198 if (d.end == d.alloc) { | |
199 // If the array is full, we expand it and move some items rightward | |
200 realloc(grow(d.alloc + 1)); | |
201 } else { | |
202 // If there is free space at the end of the array, we move some items rightward | |
203 } | |
204 } else { | |
205 if (d.end == d.alloc) { | |
206 // If there is free space at the beginning of the array, we move some items leftward | |
207 leftward = true; | |
208 } else { | |
209 // If there is free space at both ends, we move as few items as possible | |
210 leftward = (i < size - i); | |
211 } | |
212 } | |
213 | |
214 if (leftward) { | |
215 --d.begin; | |
216 memmove(d.array.ptr + d.begin, d.array.ptr + d.begin + 1, i * (void*).sizeof); | |
217 } else { | |
218 memmove(d.array.ptr + d.begin + i + 1, d.array.ptr + d.begin + i, | |
219 (size - i) * (void*).sizeof); | |
220 ++d.end; | |
221 } | |
222 return d.array.ptr + d.begin + i; | |
223 } | |
224 | |
225 void remove(int i) | |
226 { | |
227 // Q_ASSERT(d.ref_ == 1); | |
228 i += d.begin; | |
229 if (i - d.begin < d.end - i) { | |
230 if (int offset = i - d.begin) | |
231 memmove(d.array.ptr + d.begin + 1, d.array.ptr + d.begin, offset * (void*).sizeof); | |
232 d.begin++; | |
233 } else { | |
234 if (int offset = d.end - i - 1) | |
235 memmove(d.array.ptr + i, d.array.ptr + i + 1, offset * (void*).sizeof); | |
236 d.end--; | |
237 } | |
238 } | |
239 | |
240 void remove(int i, int n) | |
241 { | |
242 // Q_ASSERT(d.ref_ == 1); | |
243 i += d.begin; | |
244 int middle = i + n/2; | |
245 if (middle - d.begin < d.end - middle) { | |
246 memmove(d.array.ptr + d.begin + n, d.array.ptr + d.begin, | |
247 (i - d.begin) * (void*).sizeof); | |
248 d.begin += n; | |
249 } else { | |
250 memmove(d.array.ptr + i, d.array.ptr + i + n, | |
251 (d.end - i - n) * (void*).sizeof); | |
252 d.end -= n; | |
253 } | |
254 } | |
255 | |
256 void move(int from, int to) | |
257 { | |
258 // Q_ASSERT(d.ref_ == 1); | |
259 if (from == to) | |
260 return; | |
261 | |
262 from += d.begin; | |
263 to += d.begin; | |
264 void *t = d.array.ptr[from]; | |
265 | |
266 if (from < to) { | |
267 if (d.end == d.alloc || 3 * (to - from) < 2 * (d.end - d.begin)) { | |
268 memmove(d.array.ptr + from, d.array.ptr + from + 1, (to - from) * (void*).sizeof); | |
269 } else { | |
270 // optimization | |
271 if (int offset = from - d.begin) | |
272 memmove(d.array.ptr + d.begin + 1, d.array.ptr + d.begin, offset * (void*).sizeof); | |
273 if (int offset = d.end - (to + 1)) | |
274 memmove(d.array.ptr + to + 2, d.array.ptr + to + 1, offset * (void*).sizeof); | |
275 ++d.begin; | |
276 ++d.end; | |
277 ++to; | |
278 } | |
279 } else { | |
280 if (d.begin == 0 || 3 * (from - to) < 2 * (d.end - d.begin)) { | |
281 memmove(d.array.ptr + to + 1, d.array.ptr + to, (from - to) * (void*).sizeof); | |
282 } else { | |
283 // optimization | |
284 if (int offset = to - d.begin) | |
285 memmove(d.array.ptr + d.begin - 1, d.array.ptr + d.begin, offset * (void*).sizeof); | |
286 if (int offset = d.end - (from + 1)) | |
287 memmove(d.array.ptr + from, d.array.ptr + from + 1, offset * (void*).sizeof); | |
288 --d.begin; | |
289 --d.end; | |
290 --to; | |
291 } | |
292 } | |
293 d.array.ptr[to] = t; | |
294 } | |
295 | |
296 void **erase(void **xi) | |
297 { | |
298 // Q_ASSERT(d.ref_ == 1); | |
299 int i = xi - (d.array.ptr + d.begin); | |
300 remove(i); | |
301 return d.array.ptr + d.begin + i; | |
302 } | |
303 | |
304 int size() const { return d.end - d.begin; } | |
305 bool isEmpty() const { return d.end == d.begin; } | |
306 const (void*)* at(int i) const { return d.array.ptr + d.begin + i; } | |
307 const (void*)* begin() const { return d.array.ptr + d.begin; } | |
308 const (void*)* end() const { return d.array.ptr + d.end; } | |
309 } | |
310 | |
311 import std.stdio; | |
312 | |
295
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
313 alias void Dummy; // DMD bug #3538 |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
314 |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
315 struct QList(T, alias Default = Dummy) |
291 | 316 { |
295
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
317 static if (is(Default == Dummy)) |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
318 alias QTypeInfo!T TI; |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
319 else |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
320 alias Default TI; |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
321 |
291 | 322 struct Node |
323 { | |
324 void *v; | |
292 | 325 |
293 | 326 static if (isQObjectType!T || isObjectType!T || isValueType!T) // binded Qt types |
292 | 327 { |
328 T t() | |
329 { | |
293 | 330 static if (isValueType!T) |
331 { | |
332 void* ptr = cast(void*)(isLarge!T() || isStatic!T() ? v : &this); | |
333 return new T(ptr, QtdObjectFlags.nativeOwnership); | |
334 } | |
335 else | |
336 { | |
337 return T.__getObject( *cast(void**)(&this) ); | |
338 } | |
292 | 339 } |
340 } | |
293 | 341 else // native types |
292 | 342 { |
343 ref T t() | |
344 { | |
295
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
345 static if(TI.isLarge || TI.isStatic) |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
346 return *cast(T*)(v); |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
347 else |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
348 return *cast(T*)(&this); |
292 | 349 } |
350 } | |
291 | 351 } |
352 | |
353 union { | |
354 QListData p; | |
355 QListData.Data* d; | |
356 } | |
357 | |
358 public: | |
359 void output() | |
360 { | |
361 writeln("QList atomic ", d.ref_.load()); | |
362 } | |
363 | |
364 static QList!T opCall() | |
365 { | |
366 QList!T res; | |
367 writeln("QList opCall"); | |
368 | |
369 res.d = &QListData.shared_null; | |
370 res.d.ref_.increment(); | |
371 | |
372 return res; | |
373 } | |
374 | |
375 this(this) | |
376 { | |
377 writeln("QList postblit"); | |
378 d.ref_.increment(); | |
379 if (!d.sharable) | |
380 detach_helper(); | |
381 } | |
382 | |
383 ~this() | |
384 { | |
385 writeln("QList ~this"); | |
386 if (d && !d.ref_.decrement()) | |
387 free(d); | |
388 } | |
389 | |
390 ref QList!T opAssign(const ref QList!T l) | |
391 { | |
392 writeln("QList opAssign"); | |
393 if (d != l.d) { | |
394 l.d.ref_.increment(); | |
395 if (!d.ref_.decrement()) | |
396 free(d); | |
397 d = cast(QListData.Data*)l.d; | |
398 if (!d.sharable) | |
399 detach_helper(); | |
400 } | |
401 return this; | |
402 } | |
403 | |
292 | 404 int length() const { return p.size(); } |
405 int size() const { return length; } | |
406 | |
291 | 407 void detach() { if (d.ref_.load() != 1) detach_helper(); } |
408 | |
409 private void detach_helper() | |
410 { | |
411 Node *n = cast(Node*)(p.begin()); | |
412 QListData.Data* x = p.detach2(); | |
413 node_copy(cast(Node*)(p.begin()), cast(Node*)(p.end()), n); | |
414 if (!x.ref_.decrement()) | |
415 free(x); | |
416 } | |
417 | |
293 | 418 |
291 | 419 void append(const T t) // fix to const ref for complex types TODO |
420 { | |
421 detach(); | |
293 | 422 static if (isQObjectType!T || isObjectType!T || isValueType!T) |
291 | 423 { |
424 node_construct(cast(Node*)(p.append()), t); | |
425 } | |
292 | 426 else |
291 | 427 { |
428 const T cpy = t; | |
429 node_construct(cast(Node*)(p.append()), cpy); | |
430 } | |
431 } | |
292 | 432 |
293 | 433 static if (isQObjectType!T || isObjectType!T || isValueType!T) |
291 | 434 { |
292 | 435 T at(int i) const |
436 { | |
437 assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); | |
438 return (cast(Node*)(p.at(i))).t(); | |
439 } | |
291 | 440 } |
292 | 441 else |
291 | 442 { |
292 | 443 ref const (T) at(int i) const |
444 { | |
445 assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); | |
446 return (cast(Node*)(p.at(i))).t(); | |
447 } | |
448 } | |
449 | |
293 | 450 static if (isQObjectType!T || isObjectType!T || isValueType!T) //binded types |
451 void node_construct(Node *n, const T t) | |
452 { | |
453 static if (isValueType!T) | |
454 { | |
455 if (isLarge!T() || isStatic!T()) // TODO should be static if | |
294 | 456 n.v = T.__constructNativeCopy(t.__nativeId); // n.v = new T(t); |
293 | 457 else if (isComplex!T()) |
294 | 458 T.__constructPlacedNativeCopy(t.__nativeId, n); // new (n) T(t); |
293 | 459 else |
294 | 460 T.__constructPlacedNativeCopy(t.__nativeId, n); // TODO should be *cast(T*)(n) = cast(T)(t); as it is a primitive type. fix when they are implemented with structs |
293 | 461 } |
462 else // in case of QObject or Object Qt types we place a pointer to a native object in the node | |
463 n = cast(Node*) t.__nativeId; | |
464 } | |
465 else // native types | |
292 | 466 void node_construct(Node *n, const ref T t) |
467 { | |
295
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
468 static if (TI.isLarge || TI.isStatic) { pragma(msg, "node construct, large " ~ T.stringof); |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
469 n.v = q_new!T(t); // n.v = new T(t); |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
470 } else static if (TI.isComplex) {pragma(msg, "node construct, complex " ~ T.stringof); |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
471 q_new_at(n, t); // new (n) T(t); |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
472 } else {pragma(msg, "node construct, other " ~ T.stringof); |
293 | 473 *cast(T*)(n) = cast(T)(t); |
295
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
474 } |
292 | 475 } |
291 | 476 |
477 void node_copy(Node *from, Node *to, Node *src) | |
478 { | |
294 | 479 writeln("QList node_copy"); |
295
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
480 static if (isQObjectType!T || isObjectType!T) |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
481 {} // ensure to do nothing. copying only a pointer |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
482 else static if (isValueType!T) |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
483 { |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
484 if (TI.isLarge || TI.isStatic) // TODO should be static if |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
485 while(from != to) |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
486 (from++).v = T.__constructNativeCopy((src++).v); // (from++)->v = new T(*reinterpret_cast<T*>((src++)->v)); |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
487 else if (TI.isComplex) |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
488 while(from != to) |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
489 T.__constructPlacedNativeCopy(src++, from++); // new (from++) T(*reinterpret_cast<T*>(src++)); |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
490 } |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
491 else static if (TI.isLarge || TI.isStatic) |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
492 while(from != to) |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
493 (from++).v = q_new!T(*cast(T*)((src++).v)); |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
494 else static if (TI.isComplex) |
291 | 495 while(from != to) |
295
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
496 q_new_at(from++, *cast(T*)(src++)); |
291 | 497 } |
498 | |
499 void free(QListData.Data* data) | |
500 { | |
292 | 501 writeln("QList data destroyed"); |
291 | 502 node_destruct(cast(Node*)(data.array.ptr + data.begin), |
503 cast(Node*)(data.array.ptr + data.end)); | |
504 if (data.ref_.load() == 0) | |
293 | 505 qFree(data); |
291 | 506 } |
507 | |
508 void node_destruct(Node *from, Node *to) | |
293 | 509 { |
510 static if (isQObjectType!T || isObjectType!T) //binded types | |
511 {} // removing just pointers, do nothing | |
512 static if (isValueType!T) //binded value types | |
513 { | |
514 if (isLarge!T() || isStatic!T()) // TODO should be static if | |
515 while (from != to) | |
294 | 516 --to, T.__deleteNativeObject(to.v); |
517 else if (isComplex!T()) | |
518 while (from != to) | |
519 --to, T.__callNativeDestructor(to); | |
293 | 520 } |
521 else | |
295
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
522 { |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
523 static if (TI.isLarge || TI.isStatic) |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
524 while (from != to) --to, q_delete(cast(T*)(to.v)); |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
525 else static if (TI.isComplex) |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
526 while (from != to) --to, cast(T*)(to).__dtor(); |
293 | 527 } |
291 | 528 } |
529 } | |
530 | |
531 extern(C) void qtd_create_QList(void *nativeId); | |
295
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
532 extern(C) void qtd_create_QList_double(void *nativeId); |
463563fc9e17
more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
eldar
parents:
294
diff
changeset
|
533 |
292 | 534 extern(C) void qtd_create_QList_QObject(void *nativeId); |