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(const 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)
107 T * after = (T *)afterIp;
111 virtual void RemoveAll()
113 if(minAllocSize && array)
114 array = renew0 array T[minAllocSize];
120 virtual int GetCount() { return count; }
124 get { return count; }
129 if(value > minAllocSize)
130 array = renew0 array T[value];
131 else if(value > count)
132 memset(array + count, 0, (value - count) * Tsize);
138 property uint minAllocSize
140 get { return minAllocSize; }
143 if(minAllocSize != value)
146 array = renew array T[value];
147 minAllocSize = value;
152 virtual void Copy(Container source)
154 count = source.GetCount();
155 if(count > minAllocSize)
156 array = renew array T[count];
158 // TOFIX: Precomp fails on (BuiltInContainer *)
159 if((source._class == class(BuiltInContainer) && ((struct BuiltInContainer *)source)->type.type != structClass ) ||
160 eClass_IsDerived(source._class, class(Array)))
162 memcpy(array, ((Array)source).array, count * Tsize);
168 for(c = 0, i = source.GetFirst(); i; i = source.GetNext(i), c++)
170 D data = source.GetData(i);
180 for(c = 0; c<count; c++)
190 void Delete(IteratorPointer item)