5 public class Array : Container
19 // Generic iterator support
20 IteratorPointer GetFirst() { return (IteratorPointer)array; }
21 IteratorPointer GetLast() { return (IteratorPointer)(array ? (array + (count - 1)) : null); }
22 IteratorPointer GetPrev(IteratorPointer ip)
25 return (IteratorPointer)((item && item > array) ? (item - 1) : null);
27 IteratorPointer GetNext(IteratorPointer ip)
30 return (IteratorPointer)((item && item < array + count - 1) ? (item + 1) : null);
32 T GetData(IteratorPointer ip)
37 bool SetData(IteratorPointer ip, T value)
43 IteratorPointer GetAtPosition(const I pos, bool create)
45 if((int)pos > count && create)
47 if((int)pos + 1 > minAllocSize)
48 array = renew array T[(int)pos + 1];
51 return ((int)pos < count && array) ? (IteratorPointer)(array + (int)pos) : null;
53 IteratorPointer Insert(IteratorPointer ip, T value)
57 int offset = after ? (after - array) : 0;
58 if(count + 1 > minAllocSize)
60 array = renew array T[count + 1];
61 if(after) after = array + offset;
63 memmove(after ? (after + 2) : (array + 1), after ? (after + 1) : array, (count - offset) * class(T).typeSize);
69 return (IteratorPointer)(after ? (after + 1) : array);
71 uint tsize = class(T).typeSize;
72 byte * pos = ip ? ((byte *)ip + tsize) : (byte *)array;
73 if(count+1 > minAllocSize)
75 int offset = pos - (byte *)array;
76 array = renew array T[count + 1];
77 pos = (byte *)array+offset;
79 memmove(pos + tsize, pos, (byte *)array+(count++) * tsize - pos);
81 return (IteratorPointer)pos;
84 IteratorPointer Add(T value)
86 if(count + 1 > minAllocSize)
87 array = renew array T[count + 1];
89 return (IteratorPointer)(array + (count++));
92 void Remove(IteratorPointer ip)
95 memmove(it, it + 1, (count - (it - array) - 1) * class(T).typeSize);
97 if(count + 1 > minAllocSize)
98 array = renew array T[count];
101 void Move(IteratorPointer ip, IteratorPointer afterIp)
105 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) * class(T).typeSize);
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 * class(T).typeSize);
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)