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