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;
76 return ((int)pos < count && array) ? (IteratorPointer)(array + (int)pos) : null;
78 IteratorPointer Insert(IteratorPointer ip, T value)
82 int offset = after ? (after - array) : 0;
83 if(count + 1 > minAllocSize)
85 array = renew array T[count + 1];
86 if(after) after = array + offset;
88 memmove(after ? (after + 2) : (array + 1), after ? (after + 1) : array, (count - offset) * class(T).typeSize);
94 return (IteratorPointer)(after ? (after + 1) : array);
96 uint tsize = class(T).typeSize;
97 byte * pos = ip ? ((byte *)ip + tsize) : (byte *)array;
98 if(count+1 > minAllocSize)
100 int offset = pos - (byte *)array;
101 array = renew array T[count + 1];
102 pos = (byte *)array+offset;
104 memmove(pos + tsize, pos, (byte *)array+(count++) * tsize - pos);
106 return (IteratorPointer)pos;
109 IteratorPointer Add(T value)
111 if(count + 1 > minAllocSize)
112 array = renew array T[count + 1];
113 array[count] = value;
114 return (IteratorPointer)(array + (count++));
117 void Remove(IteratorPointer ip)
120 memmove(it, it + 1, (count - (it - array) - 1) * class(T).typeSize);
122 if(count + 1 > minAllocSize)
123 array = renew array T[count];
126 void Move(IteratorPointer ip, IteratorPointer afterIp)
130 T * after = (T *)afterIp;
134 virtual void RemoveAll()
136 if(minAllocSize && array)
137 array = renew0 array T[minAllocSize];
143 virtual int GetCount() { return count; }
147 get { return count; }
152 if(value > minAllocSize)
153 array = renew0 array T[value];
154 else if(value > count)
155 memset((byte *)array + count * class(T).typeSize, 0, (value - count) * class(T).typeSize);
157 #if defined(_DEBUG) && !defined(MEMINFO) && defined(MEMTRACKING)
160 MemBlock block = (MemBlock)((byte *)array - sizeof(class MemBlock));
161 block._class = class(T);
168 property uint minAllocSize
170 get { return minAllocSize; }
173 if(minAllocSize != value)
176 array = renew array T[value];
177 minAllocSize = value;
182 virtual void Copy(Container source)
184 count = source.GetCount();
185 if(count > minAllocSize)
186 array = renew array T[count];
188 // TOFIX: Precomp fails on (BuiltInContainer *)
189 if((source._class == class(BuiltInContainer) && ((struct BuiltInContainer *)source)->type.type != structClass ) ||
190 eClass_IsDerived(source._class, class(Array)))
192 memcpy(array, ((Array)source).array, count * class(T).typeSize);
198 for(c = 0, i = source.GetFirst(); i; i = source.GetNext(i), c++)
200 D data = source.GetData(i);
210 for(c = 0; c<count; c++)
220 void Delete(IteratorPointer item)