Mercurial > projects > qtd
comparison qt/core/QList.d @ 293:8627891e4556 signals
QList updates
author | eldar |
---|---|
date | Fri, 13 Nov 2009 19:09:28 +0000 |
parents | 19498f420252 |
children | bb37b0ed94c9 |
comparison
equal
deleted
inserted
replaced
292:19498f420252 | 293:8627891e4556 |
---|---|
1 module qt.core.QList; | 1 module qt.core.QList; |
2 | 2 |
3 import qt.QGlobal; | 3 import qt.QGlobal; |
4 import qt.QtdObject; | |
4 import qt.qtd.Atomic; | 5 import qt.qtd.Atomic; |
6 import qt.qtd.MetaMarshall; | |
5 //import qt.core.QTypeInfo; | 7 //import qt.core.QTypeInfo; |
6 | |
7 import qt.qtd.MetaMarshall; | |
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; |
13 | 13 |
14 enum INT_MAX = int.max; | 14 enum INT_MAX = int.max; |
15 | 15 |
16 bool isComplex(T)() | 16 bool isComplex(T)() |
17 if (is(typeof(T.QTypeInfo))) | 17 if (is(T.QTypeInfo)) |
18 { | 18 { |
19 return T.QTypeInfo.isComplex(); | 19 return T.QTypeInfo.isComplex; |
20 } | 20 } |
21 | 21 |
22 bool isStatic(T)() | 22 bool isStatic(T)() |
23 if (is(typeof(T.QTypeInfo))) | 23 if (is(T.QTypeInfo)) |
24 { | 24 { |
25 return T.QTypeInfo.isStatic(); | 25 return T.QTypeInfo.isStatic; |
26 } | 26 } |
27 | 27 |
28 bool isLarge(T)() | 28 bool isLarge(T)() |
29 if (is(typeof(T.QTypeInfo))) | 29 if (is(T.QTypeInfo)) |
30 { | 30 { |
31 return T.QTypeInfo.isLarge(); | 31 return T.QTypeInfo.isLarge; |
32 } | 32 } |
33 | |
34 | 33 |
35 int qAllocMore(int alloc, int extra) | 34 int qAllocMore(int alloc, int extra) |
36 { | 35 { |
37 if (alloc == 0 && extra == 0) | 36 if (alloc == 0 && extra == 0) |
38 return 0; | 37 return 0; |
294 { | 293 { |
295 struct Node | 294 struct Node |
296 { | 295 { |
297 void *v; | 296 void *v; |
298 | 297 |
299 static if (isQObjectType!T) | 298 static if (isQObjectType!T || isObjectType!T || isValueType!T) // binded Qt types |
300 { | 299 { |
301 T t() | 300 T t() |
302 { | 301 { |
303 return T.__getObject( *cast(void**)(&this) ); | 302 static if (isValueType!T) |
304 } | 303 { |
305 } | 304 pragma(msg, "value " ~ T.stringof); |
306 else | 305 void* ptr = cast(void*)(isLarge!T() || isStatic!T() ? v : &this); |
306 return new T(ptr, QtdObjectFlags.nativeOwnership); | |
307 } | |
308 else | |
309 { | |
310 pragma(msg, T.stringof); | |
311 | |
312 return T.__getObject( *cast(void**)(&this) ); | |
313 } | |
314 } | |
315 } | |
316 else // native types | |
307 { | 317 { |
308 ref T t() | 318 ref T t() |
309 { | 319 { |
320 pragma(msg, "native " ~ T.stringof); | |
321 | |
310 return *cast(T*)(&this); | 322 return *cast(T*)(&this); |
311 } | 323 } |
312 // { return *cast(T*)(QTypeInfo!T.isLarge || QTypeInfo!T.isStatic | 324 // { return *cast(T*)(QTypeInfo!T.isLarge || QTypeInfo!T.isStatic |
313 // ? v : &this); } } | 325 // ? v : &this); } } |
314 } | 326 } |
377 node_copy(cast(Node*)(p.begin()), cast(Node*)(p.end()), n); | 389 node_copy(cast(Node*)(p.begin()), cast(Node*)(p.end()), n); |
378 if (!x.ref_.decrement()) | 390 if (!x.ref_.decrement()) |
379 free(x); | 391 free(x); |
380 } | 392 } |
381 | 393 |
394 | |
382 void append(const T t) // fix to const ref for complex types TODO | 395 void append(const T t) // fix to const ref for complex types TODO |
383 { | 396 { |
384 detach(); | 397 detach(); |
385 /* static if (QTypeInfo!T.isLarge || QTypeInfo!T.isStatic) | 398 static if (isQObjectType!T || isObjectType!T || isValueType!T) |
386 { | 399 { |
387 node_construct(cast(Node*)(p.append()), t); | 400 node_construct(cast(Node*)(p.append()), t); |
388 } | |
389 else*/ static if (isQObjectType!T) | |
390 { | |
391 auto n = cast(Node*)(p.append()); | |
392 *cast(void**)(n) = cast(Node*) t.__nativeId; | |
393 } | 401 } |
394 else | 402 else |
395 { | 403 { |
396 const T cpy = t; | 404 const T cpy = t; |
397 node_construct(cast(Node*)(p.append()), cpy); | 405 node_construct(cast(Node*)(p.append()), cpy); |
398 } | 406 } |
399 } | 407 } |
400 | 408 |
401 static if (isQObjectType!T) | 409 static if (isQObjectType!T || isObjectType!T || isValueType!T) |
402 { | 410 { |
403 T at(int i) const | 411 T at(int i) const |
404 { | 412 { |
405 assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); | 413 assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); |
406 return (cast(Node*)(p.at(i))).t(); | 414 return (cast(Node*)(p.at(i))).t(); |
413 assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); | 421 assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); |
414 return (cast(Node*)(p.at(i))).t(); | 422 return (cast(Node*)(p.at(i))).t(); |
415 } | 423 } |
416 } | 424 } |
417 | 425 |
418 static if (isQObjectType!T) | 426 static if (isQObjectType!T || isObjectType!T || isValueType!T) //binded types |
419 { } | 427 void node_construct(Node *n, const T t) |
420 else | 428 { |
429 static if (isValueType!T) | |
430 { | |
431 if (isLarge!T() || isStatic!T()) // TODO should be static if | |
432 n.v = T.__constructNativeCopy(t.__nativeId); | |
433 else if (isComplex!T()) | |
434 T.__constructPlacedNativeCopy(t.__nativeId, n); | |
435 else | |
436 T.__constructPlacedNativeCopy(t.__nativeId, n); // TODO should be *cast(T*)(n) = cast(T)(t); as it is a primitive type. not until they are implemented with structs | |
437 } | |
438 else // in case of QObject or Object Qt types we place a pointer to a native object in the node | |
439 n = cast(Node*) t.__nativeId; | |
440 } | |
441 else // native types | |
421 void node_construct(Node *n, const ref T t) | 442 void node_construct(Node *n, const ref T t) |
422 { | 443 { |
423 /* TODO static if (QTypeInfo!T.isLarge || QTypeInfo!T.isStatic) | 444 /* TODO static if (QTypeInfo!T.isLarge || QTypeInfo!T.isStatic) |
424 n.v = new T(t); | 445 n.v = new T(t); |
425 else static if (QTypeInfo!T.isComplex) | 446 else static if (QTypeInfo!T.isComplex) |
426 new (n) T(t); | 447 new (n) T(t); |
427 else*/ | 448 else*/ |
428 { *cast(T*)(n) = cast(T)(t); } | 449 *cast(T*)(n) = cast(T)(t); |
429 } | 450 } |
430 | 451 |
431 void node_copy(Node *from, Node *to, Node *src) | 452 void node_copy(Node *from, Node *to, Node *src) |
432 { | 453 { |
433 /* TODO if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) | 454 /* TODO if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) |
443 { | 464 { |
444 writeln("QList data destroyed"); | 465 writeln("QList data destroyed"); |
445 node_destruct(cast(Node*)(data.array.ptr + data.begin), | 466 node_destruct(cast(Node*)(data.array.ptr + data.begin), |
446 cast(Node*)(data.array.ptr + data.end)); | 467 cast(Node*)(data.array.ptr + data.end)); |
447 if (data.ref_.load() == 0) | 468 if (data.ref_.load() == 0) |
448 {} // qFree(data); TODO | 469 qFree(data); |
449 } | 470 } |
450 | 471 |
451 void node_destruct(Node *from, Node *to) | 472 void node_destruct(Node *from, Node *to) |
452 {/* TODO | 473 { |
453 if (QTypeInfo!T.isLarge || QTypeInfo!T.isStatic) | 474 static if (isQObjectType!T || isObjectType!T) //binded types |
454 while (from != to) --to, delete cast(T*)(to->v); | 475 {} // removing just pointers, do nothing |
455 else if (QTypeInfo!T.isComplex) | 476 static if (isValueType!T) //binded value types |
456 while (from != to) --to, cast(T*)(to).~T(); | 477 { |
478 if (isLarge!T() || isStatic!T()) // TODO should be static if | |
479 while (from != to) | |
480 --to, delete cast(T*)(to->v); | |
481 else if (QTypeInfo!T.isComplex) | |
482 while (from != to) --to, cast(T*)(to).~T(); | |
483 } | |
484 else | |
485 { /* | |
486 if (QTypeInfo!T.isLarge || QTypeInfo!T.isStatic) | |
487 while (from != to) --to, delete cast(T*)(to->v); | |
488 else if (QTypeInfo!T.isComplex) | |
489 while (from != to) --to, cast(T*)(to).~T(); | |
457 */ | 490 */ |
491 } | |
458 } | 492 } |
459 } | 493 } |
460 | 494 |
461 extern(C) void qtd_create_QList(void *nativeId); | 495 extern(C) void qtd_create_QList(void *nativeId); |
462 extern(C) void qtd_create_QList_QObject(void *nativeId); | 496 extern(C) void qtd_create_QList_QObject(void *nativeId); |