11 extern int __ecereVMethodID_class_OnUnserialize;
14 public class Array : Container
28 void OnUnserialize(IOChannel channel)
30 Array array = eInstance_New(_class.fullName);
32 Class Dclass = class(D);
34 //printf("%d %ss\n", count, Dclass.name);
38 for(c = 0; c < count; c++)
39 ((void (*)(void *, void *, void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnUnserialize])
40 (Dclass, ((byte *)array.array) + Dclass.typeSize * c, channel);
44 // Generic iterator support
45 IteratorPointer GetFirst() { return (IteratorPointer)array; }
46 IteratorPointer GetLast() { return (IteratorPointer)(array ? (array + (count - 1)) : null); }
47 IteratorPointer GetPrev(IteratorPointer ip)
50 return (IteratorPointer)((item && item > array) ? (item - 1) : null);
52 IteratorPointer GetNext(IteratorPointer ip)
55 return (IteratorPointer)((item && item < array + count - 1) ? (item + 1) : null);
57 T GetData(IteratorPointer ip)
62 bool SetData(IteratorPointer ip, T value)
68 IteratorPointer GetAtPosition(const I pos, bool create, bool * justAdded)
70 if((int)pos > count && create)
72 if((int)pos + 1 > minAllocSize)
73 array = renew array T[(int)pos + 1];
75 if(justAdded) *justAdded = true;
77 return ((int)pos < count && array) ? (IteratorPointer)(array + (int)pos) : null;
79 IteratorPointer Insert(IteratorPointer ip, T value)
83 int offset = after ? (after - array) : 0;
84 if(count + 1 > minAllocSize)
86 array = renew array T[count + 1];
87 if(after) after = array + offset;
89 memmove(after ? (after + 2) : (array + 1), after ? (after + 1) : array, (count - offset) * class(T).typeSize);
95 return (IteratorPointer)(after ? (after + 1) : array);
97 uint tsize = class(T).typeSize;
98 byte * pos = ip ? ((byte *)ip + tsize) : (byte *)array;
99 if(count+1 > minAllocSize)
101 int offset = pos - (byte *)array;
102 array = renew array T[count + 1];
103 pos = (byte *)array+offset;
105 memmove(pos + tsize, pos, (byte *)array+(count++) * tsize - pos);
107 return (IteratorPointer)pos;
110 IteratorPointer Add(T value)
112 if(count + 1 > minAllocSize)
113 array = renew array T[count + 1];
114 array[count] = value;
115 return (IteratorPointer)(array + (count++));
118 void Remove(IteratorPointer ip)
121 memmove(it, it + 1, (count - (it - array) - 1) * class(T).typeSize);
123 if(count + 1 > minAllocSize)
124 array = renew array T[count];
127 void Move(IteratorPointer ip, IteratorPointer afterIp)
131 T * after = (T *)afterIp;
135 virtual void RemoveAll()
137 if(minAllocSize && array)
138 array = renew0 array T[minAllocSize];
144 virtual int GetCount() { return count; }
148 get { return count; }
153 if(value > minAllocSize)
154 array = renew0 array T[value];
155 else if(value > count)
158 void * a = array + count;
159 void * b = (byte *)array + count * class(T).typeSize;
164 //memset(array + count, 0, (value - count) * class(T).typeSize);
165 /*if(!strcmp(class(T).name, "TessPrim"))
166 printf("Memsetting to 0 from %d for %d bytes\n", count * class(T).typeSize, (value - count) * class(T).typeSize);*/
167 memset((byte *)array + count * class(T).typeSize, 0, (value - count) * class(T).typeSize);
170 #if defined(_DEBUG) && !defined(MEMINFO) && defined(MEMTRACKING)
173 MemBlock block = (MemBlock)((byte *)array - sizeof(class MemBlock));
174 block._class = class(T);
181 property uint minAllocSize
183 get { return minAllocSize; }
186 if(minAllocSize != value)
189 array = renew array T[value];
190 minAllocSize = value;
195 virtual void Copy(Container source)
197 count = source.GetCount();
198 if(count > minAllocSize)
199 array = renew array T[count];
201 // TOFIX: Precomp fails on (BuiltInContainer *)
202 if((source._class == class(BuiltInContainer) && ((struct BuiltInContainer *)source)->type.type != structClass ) ||
203 eClass_IsDerived(source._class, class(Array)))
205 memcpy(array, ((Array)source).array, count * class(T).typeSize);
211 for(c = 0, i = source.GetFirst(); i; i = source.GetNext(i), c++)
213 D data = source.GetData(i);
223 for(c = 0; c<count; c++)
233 void Delete(IteratorPointer item)