Mercurial > projects > qtd
comparison 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 |
comparison
equal
deleted
inserted
replaced
294:bb37b0ed94c9 | 295:463563fc9e17 |
---|---|
2 | 2 |
3 import qt.QGlobal; | 3 import qt.QGlobal; |
4 import qt.QtdObject; | 4 import qt.QtdObject; |
5 import qt.qtd.Atomic; | 5 import qt.qtd.Atomic; |
6 import qt.qtd.MetaMarshall; | 6 import qt.qtd.MetaMarshall; |
7 //import qt.core.QTypeInfo; | 7 import qt.core.QTypeInfo; |
8 | 8 |
9 import core.stdc.stdlib : qRealloc = realloc, qFree = free, qMalloc = malloc; | 9 import core.stdc.stdlib : qRealloc = realloc, qFree = free, qMalloc = malloc; |
10 import core.stdc.string : memcpy, memmove; | 10 import core.stdc.string : memcpy, memmove; |
11 | 11 |
12 import std.traits; | 12 import std.traits; |
52 } | 52 } |
53 } | 53 } |
54 return nalloc - extra; | 54 return nalloc - extra; |
55 } | 55 } |
56 | 56 |
57 void q_new_at(T)(T* ptr, const ref T t) | |
58 { | |
59 memcpy(ptr, &t, T.sizeof); | |
60 /* static if (__traits(compiles, ptr.__postblit())) DMD bug #3539 | |
61 ptr.__postblit();*/ | |
62 } | |
63 | |
64 T* q_new(T)(const ref T t) | |
65 { | |
66 T* ptr = cast(T*) qMalloc(T.sizeof); | |
67 q_new_at!T(ptr, t); | |
68 return ptr; | |
69 } | |
70 | |
71 void q_delete(T)(T* t) | |
72 { | |
73 static if (__traits(compiles, t.__dtor())) | |
74 t.__dtor(); | |
75 qFree(t); | |
76 } | |
77 | |
57 private int grow(int size) | 78 private int grow(int size) |
58 { | 79 { |
59 // dear compiler: don't optimize me out. | 80 // dear compiler: don't optimize me out. |
60 // synchronized { | 81 // synchronized { |
61 int x = qAllocMore(size * (void*).sizeof, QListData.DataHeaderSize) / (void*).sizeof; | 82 int x = qAllocMore(size * (void*).sizeof, QListData.DataHeaderSize) / (void*).sizeof; |
287 const (void*)* end() const { return d.array.ptr + d.end; } | 308 const (void*)* end() const { return d.array.ptr + d.end; } |
288 } | 309 } |
289 | 310 |
290 import std.stdio; | 311 import std.stdio; |
291 | 312 |
292 struct QList(T) | 313 alias void Dummy; // DMD bug #3538 |
293 { | 314 |
315 struct QList(T, alias Default = Dummy) | |
316 { | |
317 static if (is(Default == Dummy)) | |
318 alias QTypeInfo!T TI; | |
319 else | |
320 alias Default TI; | |
321 | |
294 struct Node | 322 struct Node |
295 { | 323 { |
296 void *v; | 324 void *v; |
297 | 325 |
298 static if (isQObjectType!T || isObjectType!T || isValueType!T) // binded Qt types | 326 static if (isQObjectType!T || isObjectType!T || isValueType!T) // binded Qt types |
299 { | 327 { |
300 T t() | 328 T t() |
301 { | 329 { |
302 static if (isValueType!T) | 330 static if (isValueType!T) |
303 { | 331 { |
304 pragma(msg, "value " ~ T.stringof); | |
305 void* ptr = cast(void*)(isLarge!T() || isStatic!T() ? v : &this); | 332 void* ptr = cast(void*)(isLarge!T() || isStatic!T() ? v : &this); |
306 return new T(ptr, QtdObjectFlags.nativeOwnership); | 333 return new T(ptr, QtdObjectFlags.nativeOwnership); |
307 } | 334 } |
308 else | 335 else |
309 { | 336 { |
310 pragma(msg, T.stringof); | |
311 | |
312 return T.__getObject( *cast(void**)(&this) ); | 337 return T.__getObject( *cast(void**)(&this) ); |
313 } | 338 } |
314 } | 339 } |
315 } | 340 } |
316 else // native types | 341 else // native types |
317 { | 342 { |
318 ref T t() | 343 ref T t() |
319 { | 344 { |
320 pragma(msg, "native " ~ T.stringof); | 345 static if(TI.isLarge || TI.isStatic) |
321 | 346 return *cast(T*)(v); |
322 return *cast(T*)(&this); | 347 else |
323 } | 348 return *cast(T*)(&this); |
324 // { return *cast(T*)(QTypeInfo!T.isLarge || QTypeInfo!T.isStatic | 349 } |
325 // ? v : &this); } } | |
326 } | 350 } |
327 } | 351 } |
328 | 352 |
329 union { | 353 union { |
330 QListData p; | 354 QListData p; |
439 n = cast(Node*) t.__nativeId; | 463 n = cast(Node*) t.__nativeId; |
440 } | 464 } |
441 else // native types | 465 else // native types |
442 void node_construct(Node *n, const ref T t) | 466 void node_construct(Node *n, const ref T t) |
443 { | 467 { |
444 /* TODO static if (QTypeInfo!T.isLarge || QTypeInfo!T.isStatic) | 468 static if (TI.isLarge || TI.isStatic) { pragma(msg, "node construct, large " ~ T.stringof); |
445 n.v = new T(t); | 469 n.v = q_new!T(t); // n.v = new T(t); |
446 else static if (QTypeInfo!T.isComplex) | 470 } else static if (TI.isComplex) {pragma(msg, "node construct, complex " ~ T.stringof); |
447 new (n) T(t); | 471 q_new_at(n, t); // new (n) T(t); |
448 else*/ | 472 } else {pragma(msg, "node construct, other " ~ T.stringof); |
449 *cast(T*)(n) = cast(T)(t); | 473 *cast(T*)(n) = cast(T)(t); |
474 } | |
450 } | 475 } |
451 | 476 |
452 void node_copy(Node *from, Node *to, Node *src) | 477 void node_copy(Node *from, Node *to, Node *src) |
453 { | 478 { |
454 writeln("QList node_copy"); | 479 writeln("QList node_copy"); |
455 /* TODO if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) | 480 static if (isQObjectType!T || isObjectType!T) |
481 {} // ensure to do nothing. copying only a pointer | |
482 else static if (isValueType!T) | |
483 { | |
484 if (TI.isLarge || TI.isStatic) // TODO should be static if | |
485 while(from != to) | |
486 (from++).v = T.__constructNativeCopy((src++).v); // (from++)->v = new T(*reinterpret_cast<T*>((src++)->v)); | |
487 else if (TI.isComplex) | |
488 while(from != to) | |
489 T.__constructPlacedNativeCopy(src++, from++); // new (from++) T(*reinterpret_cast<T*>(src++)); | |
490 } | |
491 else static if (TI.isLarge || TI.isStatic) | |
492 while(from != to) | |
493 (from++).v = q_new!T(*cast(T*)((src++).v)); | |
494 else static if (TI.isComplex) | |
456 while(from != to) | 495 while(from != to) |
457 (from++)->v = new T(*reinterpret_cast<T*>((src++)->v)); | 496 q_new_at(from++, *cast(T*)(src++)); |
458 else if (QTypeInfo<T>::isComplex) | |
459 while(from != to) | |
460 new (from++) T(*reinterpret_cast<T*>(src++)); | |
461 */ | |
462 } | 497 } |
463 | 498 |
464 void free(QListData.Data* data) | 499 void free(QListData.Data* data) |
465 { | 500 { |
466 writeln("QList data destroyed"); | 501 writeln("QList data destroyed"); |
482 else if (isComplex!T()) | 517 else if (isComplex!T()) |
483 while (from != to) | 518 while (from != to) |
484 --to, T.__callNativeDestructor(to); | 519 --to, T.__callNativeDestructor(to); |
485 } | 520 } |
486 else | 521 else |
487 { /* | 522 { |
488 if (QTypeInfo!T.isLarge || QTypeInfo!T.isStatic) | 523 static if (TI.isLarge || TI.isStatic) |
489 while (from != to) --to, delete cast(T*)(to->v); | 524 while (from != to) --to, q_delete(cast(T*)(to.v)); |
490 else if (QTypeInfo!T.isComplex) | 525 else static if (TI.isComplex) |
491 while (from != to) --to, cast(T*)(to).~T(); | 526 while (from != to) --to, cast(T*)(to).__dtor(); |
492 */ | |
493 } | 527 } |
494 } | 528 } |
495 } | 529 } |
496 | 530 |
497 extern(C) void qtd_create_QList(void *nativeId); | 531 extern(C) void qtd_create_QList(void *nativeId); |
532 extern(C) void qtd_create_QList_double(void *nativeId); | |
533 | |
498 extern(C) void qtd_create_QList_QObject(void *nativeId); | 534 extern(C) void qtd_create_QList_QObject(void *nativeId); |