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, bool * justAdded)
45 if((int)pos > count && create)
47 if((int)pos + 1 > minAllocSize)
48 array = renew array T[(int)pos + 1];
50 if(justAdded) *justAdded = true;
52 return ((int)pos < count && array) ? (IteratorPointer)(array + (int)pos) : null;
54 IteratorPointer Insert(IteratorPointer ip, T value)
58 int offset = after ? (after - array) : 0;
59 if(count + 1 > minAllocSize)
61 array = renew array T[count + 1];
62 if(after) after = array + offset;
64 memmove(after ? (after + 2) : (array + 1), after ? (after + 1) : array, (count - offset) * class(T).typeSize);
70 return (IteratorPointer)(after ? (after + 1) : array);
72 uint tsize = class(T).typeSize;
73 byte * pos = ip ? ((byte *)ip + tsize) : (byte *)array;
74 if(count+1 > minAllocSize)
76 int offset = pos - (byte *)array;
77 array = renew array T[count + 1];
78 pos = (byte *)array+offset;
80 memmove(pos + tsize, pos, (byte *)array+(count++) * tsize - pos);
82 return (IteratorPointer)pos;
85 IteratorPointer Add(T value)
87 if(count + 1 > minAllocSize)
88 array = renew array T[count + 1];
90 return (IteratorPointer)(array + (count++));
93 void Remove(IteratorPointer ip)
96 memmove(it, it + 1, (count - (it - array) - 1) * class(T).typeSize);
98 if(count + 1 > minAllocSize)
99 array = renew array T[count];
102 void Move(IteratorPointer ip, IteratorPointer afterIp)
106 T * after = (T *)afterIp;
110 virtual void RemoveAll()
112 if(minAllocSize && array)
113 array = renew0 array T[minAllocSize];
119 virtual int GetCount() { return count; }
123 get { return count; }
128 if(value > minAllocSize)
129 array = renew0 array T[value];
130 else if(value > count)
131 memset(array + count, 0, (value - count) * class(T).typeSize);
137 property uint minAllocSize
139 get { return minAllocSize; }
142 if(minAllocSize != value)
145 array = renew array T[value];
146 minAllocSize = value;
151 virtual void Copy(Container source)
153 count = source.GetCount();
154 if(count > minAllocSize)
155 array = renew array T[count];
157 // TOFIX: Precomp fails on (BuiltInContainer *)
158 if((source._class == class(BuiltInContainer) && ((struct BuiltInContainer *)source)->type.type != structClass ) ||
159 eClass_IsDerived(source._class, class(Array)))
161 memcpy(array, ((Array)source).array, count * class(T).typeSize);
167 for(c = 0, i = source.GetFirst(); i; i = source.GetNext(i), c++)
169 D data = source.GetData(i);
179 for(c = 0; c<count; c++)
189 void Delete(IteratorPointer item)