5 #define Tsize ((class(T).type == noHeadClass || class(T).type == normalClass) ? sizeof(void *) : class(T).typeSize)
7 public class Array : Container
21 // Generic iterator support
22 IteratorPointer GetFirst() { return (IteratorPointer)array; }
23 IteratorPointer GetLast() { return (IteratorPointer)(array ? (array + (count - 1)) : null); }
24 IteratorPointer GetPrev(IteratorPointer ip)
27 return (IteratorPointer)((item && item > array) ? (item - 1) : null);
29 IteratorPointer GetNext(IteratorPointer ip)
32 return (IteratorPointer)((item && item < array + count - 1) ? (item + 1) : null);
34 T GetData(IteratorPointer ip)
39 bool SetData(IteratorPointer ip, T value)
45 IteratorPointer GetAtPosition(I pos, bool create)
47 if((int)pos > count && create)
49 if((int)pos + 1 > minAllocSize)
50 array = renew array T[(int)pos + 1];
53 return ((int)pos < count && array) ? (IteratorPointer)(array + (int)pos) : null;
55 IteratorPointer Insert(IteratorPointer ip, T value)
59 int offset = after ? (after - array) : 0;
60 if(count + 1 > minAllocSize)
62 array = renew array T[count + 1];
63 if(after) after = array + offset;
65 memmove(after ? (after + 2) : (array + 1), after ? (after + 1) : array, (count - offset) * Tsize);
71 return (IteratorPointer)(after ? (after + 1) : array);
74 byte * pos = ip ? ((byte *)ip + tsize) : (byte *)array;
75 if(count+1 > minAllocSize)
77 int offset = pos - (byte *)array;
78 array = renew array T[count + 1];
79 pos = (byte *)array+offset;
81 memmove(pos + tsize, pos, (byte *)array+(count++) * tsize - pos);
83 return (IteratorPointer)pos;
86 IteratorPointer Add(T value)
88 if(count + 1 > minAllocSize)
89 array = renew array T[count + 1];
91 return (IteratorPointer)(array + (count++));
94 void Remove(IteratorPointer ip)
97 memmove(it, it + 1, (count - (it - array) - 1) * Tsize);
99 if(count + 1 > minAllocSize)
100 array = renew array T[count];
103 void Move(IteratorPointer ip, IteratorPointer afterIp)
106 T * after = (T *)afterIp;
109 virtual void RemoveAll()
111 if(minAllocSize && array)
112 array = renew0 array T[minAllocSize];
118 virtual int GetCount() { return count; }
122 get { return count; }
127 if(value > minAllocSize)
128 array = renew0 array T[value];
129 else if(value > count)
130 memset(array + count, 0, (value - count) * Tsize);
136 property uint minAllocSize
138 get { return minAllocSize; }
141 if(minAllocSize != value)
144 array = renew array T[value];
145 minAllocSize = value;
150 virtual void Copy(Container source)
152 count = source.GetCount();
153 if(count > minAllocSize)
154 array = renew array T[count];
156 // TOFIX: Precomp fails on (BuiltInContainer *)
157 if((source._class == class(BuiltInContainer) && ((struct BuiltInContainer *)source)->type.type != structClass ) ||
158 eClass_IsDerived(source._class, class(Array)))
160 memcpy(array, ((Array)source).array, count * Tsize);
166 for(c = 0, i = source.GetFirst(); i; i = source.GetNext(i), c++)
168 D data = source.GetData(i);
178 for(c = 0; c<count; c++)
188 void Delete(IteratorPointer item)