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);
33 //printf("%d %ss\n", count, Dclass.name);
37 for(c = 0; c < count; c++)
38 ((void (*)(void *, void *, void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnUnserialize])
39 (Dclass, ((byte *)array.array) + Dclass.typeSize * c, channel);
43 // Generic iterator support
44 IteratorPointer GetFirst() { return (IteratorPointer)array; }
45 IteratorPointer GetLast() { return (IteratorPointer)(array ? (array + (count - 1)) : null); }
46 IteratorPointer GetPrev(IteratorPointer ip)
49 return (IteratorPointer)((item && item > array) ? (item - 1) : null);
51 IteratorPointer GetNext(IteratorPointer ip)
54 return (IteratorPointer)((item && item < array + count - 1) ? (item + 1) : null);
56 T GetData(IteratorPointer ip)
61 bool SetData(IteratorPointer ip, T value)
67 IteratorPointer GetAtPosition(const I pos, bool create, bool * justAdded)
69 if((int)pos > count && create)
71 if((int)pos + 1 > minAllocSize)
72 array = renew array T[(int)pos + 1];
74 if(justAdded) *justAdded = true;
75 #if !defined(MEMINFO) && defined(MEMTRACKING)
78 MemBlock block = (MemBlock)((byte *)array - sizeof(class MemBlock));
79 block._class = class(T);
83 return ((int)pos < count && array) ? (IteratorPointer)(array + (int)pos) : null;
85 IteratorPointer Insert(IteratorPointer ip, T value)
89 int offset = after ? (after - array) : 0;
90 if(count + 1 > minAllocSize)
92 array = renew array T[count + 1];
93 if(after) after = array + offset;
95 memmove(after ? (after + 2) : (array + 1), after ? (after + 1) : array, (count - offset) * class(T).typeSize);
101 return (IteratorPointer)(after ? (after + 1) : array);
103 uint tsize = class(T).typeSize;
104 byte * pos = ip ? ((byte *)ip + tsize) : (byte *)array;
105 if(count+1 > minAllocSize)
107 int offset = pos - (byte *)array;
108 array = renew array T[count + 1];
109 pos = (byte *)array+offset;
111 memmove(pos + tsize, pos, (byte *)array+(count++) * tsize - pos);
113 return (IteratorPointer)pos;
116 IteratorPointer Add(T value)
118 if(count + 1 > minAllocSize)
119 array = renew array T[count + 1];
120 array[count] = value;
121 return (IteratorPointer)(array + (count++));
124 void Remove(IteratorPointer ip)
127 memmove(it, it + 1, (count - (it - array) - 1) * class(T).typeSize);
129 if(count + 1 > minAllocSize)
130 array = renew array T[count];
133 void Move(IteratorPointer ip, IteratorPointer afterIp)
137 T * after = (T *)afterIp;
141 virtual void RemoveAll()
143 if(minAllocSize && array)
144 array = renew0 array T[minAllocSize];
150 virtual int GetCount() { return count; }
154 get { return count; }
159 if(value > minAllocSize)
160 array = renew0 array T[value];
161 else if(value > count)
162 memset((byte *)array + count * class(T).typeSize, 0, (value - count) * class(T).typeSize);
164 #if !defined(MEMINFO) && defined(MEMTRACKING)
167 MemBlock block = (MemBlock)((byte *)array - sizeof(class MemBlock));
168 block._class = class(T);
175 property uint minAllocSize
177 get { return minAllocSize; }
180 if(minAllocSize != value)
183 array = renew array T[value];
184 minAllocSize = value;
186 #if !defined(MEMINFO) && defined(MEMTRACKING)
189 MemBlock block = (MemBlock)((byte *)array - sizeof(class MemBlock));
190 block._class = class(T);
196 virtual void Copy(Container source)
198 count = source.GetCount();
199 if(count > minAllocSize)
200 array = renew array T[count];
202 #if !defined(MEMINFO) && defined(MEMTRACKING)
205 MemBlock block = (MemBlock)((byte *)array - sizeof(class MemBlock));
206 block._class = class(T);
210 // TOFIX: Precomp fails on (BuiltInContainer *)
211 if((source._class == class(BuiltInContainer) && ((struct BuiltInContainer *)source)->type.type != structClass ) ||
212 eClass_IsDerived(source._class, class(Array)))
214 memcpy(array, ((Array)source).array, count * class(T).typeSize);
220 for(c = 0, i = source.GetFirst(); i; i = source.GetNext(i), c++)
222 D data = source.GetData(i);
232 for(c = 0; c<count; c++)
242 void Delete(IteratorPointer item)