10 extern int __ecereVMethodID_class_OnUnserialize;
13 public class Array : Container
27 void OnUnserialize(IOChannel channel)
29 Array array = eInstance_New(_class.fullName);
31 Class Dclass = class(D);
34 //printf("%d %ss\n", count, Dclass.name);
39 for(c = 0; c < count; c++)
40 ((void (*)(void *, void *, void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnUnserialize])
41 (Dclass, ((byte *)array.array) + Dclass.typeSize * c, channel);
45 // Generic iterator support
46 IteratorPointer GetFirst() { return (IteratorPointer)array; }
47 IteratorPointer GetLast() { return (IteratorPointer)(array ? (array + (count - 1)) : null); }
48 IteratorPointer GetPrev(IteratorPointer ip)
51 return (IteratorPointer)((item && item > array) ? (item - 1) : null);
53 IteratorPointer GetNext(IteratorPointer ip)
56 return (IteratorPointer)((item && item < array + count - 1) ? (item + 1) : null);
58 T GetData(IteratorPointer ip)
63 bool SetData(IteratorPointer ip, T value)
69 IteratorPointer GetAtPosition(const I pos, bool create, bool * justAdded)
71 if((int)pos > count && create)
73 if((int)pos + 1 > minAllocSize)
74 array = renew array T[(int)pos + 1];
76 if(justAdded) *justAdded = true;
77 #if !defined(MEMINFO) && defined(MEMTRACKING)
80 MemBlock block = (MemBlock)((byte *)array - sizeof(class MemBlock));
81 block._class = class(T);
85 return ((int)pos < count && array) ? (IteratorPointer)(array + (int)pos) : null;
87 IteratorPointer Insert(IteratorPointer ip, T value)
91 int offset = after ? (after - array) : 0;
92 if(count + 1 > minAllocSize)
94 array = renew array T[count + 1];
95 if(after) after = array + offset;
97 memmove(after ? (after + 2) : (array + 1), after ? (after + 1) : array, (count - offset) * class(T).typeSize);
103 return (IteratorPointer)(after ? (after + 1) : array);
105 uint tsize = class(T).typeSize;
106 byte * pos = ip ? ((byte *)ip + tsize) : (byte *)array;
107 if(count+1 > minAllocSize)
109 int offset = pos - (byte *)array;
110 array = renew array T[count + 1];
111 pos = (byte *)array+offset;
113 memmove(pos + tsize, pos, (byte *)array+(count++) * tsize - pos);
115 return (IteratorPointer)pos;
118 IteratorPointer Add(T value)
120 if(count + 1 > minAllocSize)
121 array = renew array T[count + 1];
122 array[count] = value;
123 return (IteratorPointer)(array + (count++));
126 void Remove(IteratorPointer ip)
129 memmove(it, it + 1, (count - (it - array) - 1) * class(T).typeSize);
131 if(count + 1 > minAllocSize)
132 array = renew array T[count];
135 void Move(IteratorPointer ip, IteratorPointer afterIp)
139 T * after = (T *)afterIp;
143 virtual void RemoveAll()
145 if(minAllocSize && array)
146 array = renew0 array T[minAllocSize];
152 virtual int GetCount() { return count; }
156 get { return count; }
161 if(value > minAllocSize)
162 array = renew0 array T[value];
163 else if(value > count)
164 memset((byte *)array + count * class(T).typeSize, 0, (value - count) * class(T).typeSize);
166 #if !defined(MEMINFO) && defined(MEMTRACKING)
169 MemBlock block = (MemBlock)((byte *)array - sizeof(class MemBlock));
170 block._class = class(T);
177 property uint minAllocSize
179 get { return minAllocSize; }
182 if(minAllocSize != value)
185 array = renew array T[value];
186 minAllocSize = value;
188 #if !defined(MEMINFO) && defined(MEMTRACKING)
191 MemBlock block = (MemBlock)((byte *)array - sizeof(class MemBlock));
192 block._class = class(T);
198 virtual void Copy(Container source)
200 count = source.GetCount();
201 if(count > minAllocSize)
202 array = renew array T[count];
204 #if !defined(MEMINFO) && defined(MEMTRACKING)
207 MemBlock block = (MemBlock)((byte *)array - sizeof(class MemBlock));
208 block._class = class(T);
212 // TOFIX: Precomp fails on (BuiltInContainer *)
213 if((source._class == class(BuiltInContainer) && ((struct BuiltInContainer *)source)->type.type != structClass ) ||
214 eClass_IsDerived(source._class, class(Array)))
216 memcpy(array, ((Array)source).array, count * class(T).typeSize);
222 for(c = 0, i = source.GetFirst(); i; i = source.GetNext(i), c++)
224 D data = source.GetData(i);
234 for(c = 0; c<count; c++)
244 void Delete(IteratorPointer item)