Mercurial > projects > qtd
diff d2/qt/core/QList.d @ 357:9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Q_CLASSINFO implementation
Now Qtd can be built on Windows
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Wed, 02 Jun 2010 19:38:05 +0300 |
parents | 970332a88b72 |
children | a032df77b6ab |
line wrap: on
line diff
--- a/d2/qt/core/QList.d Tue May 25 20:14:04 2010 +0300 +++ b/d2/qt/core/QList.d Wed Jun 02 19:38:05 2010 +0300 @@ -98,17 +98,17 @@ uint sharable; void*[1] array; } - + enum { DataHeaderSize = Data.sizeof - (void*).sizeof } - + static Data shared_null; Data *d; - + static this() { shared_null = Data(Atomic!int(1), 0, 0, 0, true, [null]); } - + // Data *detach(); // remove in 5.0 @@ -128,7 +128,7 @@ return x; } - + void realloc(int alloc) { // assert(d.ref_ == 1); @@ -141,7 +141,7 @@ if (!alloc) d.begin = d.end = 0; } - + void** append() { // #TODO Q_ASSERT(d.ref_ == 1); @@ -318,10 +318,12 @@ import std.stdio; import std.conv; -alias void Dummy; // DMD bug #3538 +alias void Dummy; // DMD bug #3538 struct QList(T, alias Default = Dummy) { + alias T ElementType; + static if (is(Default == Dummy)) alias QTypeInfo!T TI; else @@ -330,7 +332,7 @@ struct Node { void *v; - + static if (isQObjectType!T || isObjectType!T || isValueType!T || is(T == string)) // binded Qt types { T t() @@ -352,7 +354,7 @@ } } else // native types - { + { ref T t() { static if(TI.isLarge || TI.isStatic) @@ -362,7 +364,7 @@ } } } - + union { QListData p; QListData.Data* d; @@ -375,15 +377,15 @@ writeln("QList atomic ", d.ref_.load()); } */ - + static QList!T opCall() { QList!T res; // writeln("QList opCall"); - + res.d = &QListData.shared_null; res.d.ref_.increment(); - + return res; } @@ -416,12 +418,12 @@ } return this; } - + int length() const { return p.size(); } int size() const { return length; } void detach() { if (d.ref_.load() != 1) detach_helper(); } - + private void detach_helper() { Node *n = cast(Node*)(p.begin()); @@ -430,7 +432,7 @@ if (!x.ref_.decrement()) free(x); } - + void append(const T t) // fix to const ref for complex types TODO { detach(); @@ -444,9 +446,9 @@ node_construct(cast(Node*)(p.append()), cpy); } } - + alias append opCatAssign; - + static if (isQObjectType!T || isObjectType!T || isValueType!T || is(T == string)) { T at(int i) const @@ -472,8 +474,8 @@ assert(i >= 0 && i < p.size(), "QList!T.at(): index out of range"); return (cast(Node*)(p.at(i))).t(); } - } - + } + static if (isQObjectType!T || isObjectType!T || isValueType!T) //binded types void node_construct(Node *n, const T t) { @@ -506,7 +508,7 @@ else *cast(T*)(n) = cast(T)(t); } - + void node_copy(Node *from, Node *to, Node *src) { // writeln("QList node_copy"); @@ -527,13 +529,13 @@ T.__constructPlacedNativeCopy(src++, from++); // new (from++) T(*reinterpret_cast<T*>(src++)); } else static if (TI.isLarge || TI.isStatic) - while(from != to) + while(from != to) (from++).v = q_new!T(*cast(T*)((src++).v)); else static if (TI.isComplex) while(from != to) q_new_at(from++, *cast(T*)(src++)); } - + T[] toArray() { T[] res; @@ -547,7 +549,7 @@ } return res; } - + void free(QListData.Data* data) { // writeln("QList data destroyed"); @@ -556,7 +558,7 @@ if (data.ref_.load() == 0) qFree(data); } - + void node_destruct(Node *from, Node *to) { static if (isQObjectType!T || isObjectType!T) //binded types @@ -583,7 +585,7 @@ while (from != to) --to, cast(T*)(to).__dtor(); } } - + //iteration support int opApply(int delegate(ref T) dg) {