6 extern int __ecereVMethodID_class_OnUnserialize;
9 public class Array : Container
23 void OnUnserialize(IOChannel channel)
25 Array array = eInstance_New(_class.fullName);
27 Class Dclass = class(D);
29 //printf("%d %ss\n", count, Dclass.name);
33 for(c = 0; c < count; c++)
34 ((void (*)(void *, void *, void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnUnserialize])
35 (Dclass, ((byte *)array.array) + Dclass.typeSize * c, channel);
39 // Generic iterator support
40 IteratorPointer GetFirst() { return (IteratorPointer)array; }
41 IteratorPointer GetLast() { return (IteratorPointer)(array ? (array + (count - 1)) : null); }
42 IteratorPointer GetPrev(IteratorPointer ip)
45 return (IteratorPointer)((item && item > array) ? (item - 1) : null);
47 IteratorPointer GetNext(IteratorPointer ip)
50 return (IteratorPointer)((item && item < array + count - 1) ? (item + 1) : null);
52 T GetData(IteratorPointer ip)
57 bool SetData(IteratorPointer ip, T value)
63 IteratorPointer GetAtPosition(const I pos, bool create, bool * justAdded)
65 if((int)pos > count && create)
67 if((int)pos + 1 > minAllocSize)
68 array = renew array T[(int)pos + 1];
70 if(justAdded) *justAdded = true;
72 return ((int)pos < count && array) ? (IteratorPointer)(array + (int)pos) : null;
74 IteratorPointer Insert(IteratorPointer ip, T value)
78 int offset = after ? (after - array) : 0;
79 if(count + 1 > minAllocSize)
81 array = renew array T[count + 1];
82 if(after) after = array + offset;
84 memmove(after ? (after + 2) : (array + 1), after ? (after + 1) : array, (count - offset) * class(T).typeSize);
90 return (IteratorPointer)(after ? (after + 1) : array);
92 uint tsize = class(T).typeSize;
93 byte * pos = ip ? ((byte *)ip + tsize) : (byte *)array;
94 if(count+1 > minAllocSize)
96 int offset = pos - (byte *)array;
97 array = renew array T[count + 1];
98 pos = (byte *)array+offset;
100 memmove(pos + tsize, pos, (byte *)array+(count++) * tsize - pos);
102 return (IteratorPointer)pos;
105 IteratorPointer Add(T value)
107 if(count + 1 > minAllocSize)
108 array = renew array T[count + 1];
109 array[count] = value;
110 return (IteratorPointer)(array + (count++));
113 void Remove(IteratorPointer ip)
116 memmove(it, it + 1, (count - (it - array) - 1) * class(T).typeSize);
118 if(count + 1 > minAllocSize)
119 array = renew array T[count];
122 void Move(IteratorPointer ip, IteratorPointer afterIp)
126 T * after = (T *)afterIp;
130 virtual void RemoveAll()
132 if(minAllocSize && array)
133 array = renew0 array T[minAllocSize];
139 virtual int GetCount() { return count; }
143 get { return count; }
148 if(value > minAllocSize)
149 array = renew0 array T[value];
150 else if(value > count)
151 memset((byte *)array + count * class(T).typeSize, 0, (value - count) * class(T).typeSize);
157 property uint minAllocSize
159 get { return minAllocSize; }
162 if(minAllocSize != value)
165 array = renew array T[value];
166 minAllocSize = value;
171 virtual void Copy(Container source)
173 count = source.GetCount();
174 if(count > minAllocSize)
175 array = renew array T[count];
177 // TOFIX: Precomp fails on (BuiltInContainer *)
178 if((source._class == class(BuiltInContainer) && ((struct BuiltInContainer *)source)->type.type != structClass ) ||
179 eClass_IsDerived(source._class, class(Array)))
181 memcpy(array, ((Array)source).array, count * class(T).typeSize);
187 for(c = 0, i = source.GetFirst(); i; i = source.GetNext(i), c++)
189 D data = source.GetData(i);
199 for(c = 0; c<count; c++)
209 void Delete(IteratorPointer item)