comparison qt/core/QList.d @ 298:adae77fdc1ea signals

Native QList implementation is now used throughout QtD
author eldar
date Sun, 06 Dec 2009 17:26:37 +0000
parents bc783e20da2b
children 87db643519a4
comparison
equal deleted inserted replaced
297:bc783e20da2b 298:adae77fdc1ea
313 const (void*)* begin() const { return d.array.ptr + d.begin; } 313 const (void*)* begin() const { return d.array.ptr + d.begin; }
314 const (void*)* end() const { return d.array.ptr + d.end; } 314 const (void*)* end() const { return d.array.ptr + d.end; }
315 } 315 }
316 316
317 import std.stdio; 317 import std.stdio;
318 import std.conv;
318 319
319 alias void Dummy; // DMD bug #3538 320 alias void Dummy; // DMD bug #3538
320 321
321 struct QList(T, alias Default = Dummy) 322 struct QList(T, alias Default = Dummy)
322 { 323 {
323 static if (is(Default == Dummy)) 324 static if (is(Default == Dummy))
324 alias QTypeInfo!T TI; 325 alias QTypeInfo!T TI;
325 else 326 else
326 alias Default TI; 327 alias Default TI;
327 328
328 struct Node 329 struct Node
329 { 330 {
330 void *v; 331 void *v;
331 332
332 static if (isQObjectType!T || isObjectType!T || isValueType!T || is(T == string)) // binded Qt types 333 static if (isQObjectType!T || isObjectType!T || isValueType!T || is(T == string)) // binded Qt types
454 return (cast(Node*)(p.at(i))).t(); 455 return (cast(Node*)(p.at(i))).t();
455 } 456 }
456 } 457 }
457 else 458 else
458 { 459 {
459 ref const (T) at(int i) const 460 const (T) at(int i) const
460 { 461 {
461 assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); 462 assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range");
462 return (cast(Node*)(p.at(i))).t(); 463 return (cast(Node*)(p.at(i))).t();
463 } 464 }
464 ref T opIndex(int i) 465 ref T opIndex(int i)
526 else static if (TI.isComplex) 527 else static if (TI.isComplex)
527 while(from != to) 528 while(from != to)
528 q_new_at(from++, *cast(T*)(src++)); 529 q_new_at(from++, *cast(T*)(src++));
529 } 530 }
530 531
532 T[] toArray()
533 {
534 T[] res;
535 res.length = this.length;
536 for(int i = 0; i < res.length; ++i)
537 {
538 static if (isValueType!T)
539 res[i] = new T(T.__constructNativeCopy(this.at(i).__nativeId)); // Node should probably provide a ptr method to directly extract pointer to the native value stored in the list to avoid creating a dummy D object in t()
540 else
541 res[i] = this.opIndex(i);
542 }
543 return res;
544 }
545
531 void free(QListData.Data* data) 546 void free(QListData.Data* data)
532 { 547 {
533 writeln("QList data destroyed"); 548 writeln("QList data destroyed");
534 node_destruct(cast(Node*)(data.array.ptr + data.begin), 549 node_destruct(cast(Node*)(data.array.ptr + data.begin),
535 cast(Node*)(data.array.ptr + data.end)); 550 cast(Node*)(data.array.ptr + data.end));