10 public class Array : Container
24 // Generic iterator support
25 IteratorPointer GetFirst() { return (IteratorPointer)array; }
26 IteratorPointer GetLast() { return (IteratorPointer)(array ? (array + (count - 1)) : null); }
27 IteratorPointer GetPrev(IteratorPointer ip)
30 return (IteratorPointer)((item && item > array) ? (item - 1) : null);
32 IteratorPointer GetNext(IteratorPointer ip)
35 return (IteratorPointer)((item && item < array + count - 1) ? (item + 1) : null);
37 T GetData(IteratorPointer ip)
42 bool SetData(IteratorPointer ip, T value)
48 IteratorPointer GetAtPosition(const I pos, bool create, bool * justAdded)
50 if((int)pos > count && create)
52 if((int)pos + 1 > minAllocSize)
53 array = renew array T[(int)pos + 1];
55 if(justAdded) *justAdded = true;
57 return ((int)pos < count && array) ? (IteratorPointer)(array + (int)pos) : null;
59 IteratorPointer Insert(IteratorPointer ip, T value)
63 int offset = after ? (after - array) : 0;
64 if(count + 1 > minAllocSize)
66 array = renew array T[count + 1];
67 if(after) after = array + offset;
69 memmove(after ? (after + 2) : (array + 1), after ? (after + 1) : array, (count - offset) * class(T).typeSize);
75 return (IteratorPointer)(after ? (after + 1) : array);
77 uint tsize = class(T).typeSize;
78 byte * pos = ip ? ((byte *)ip + tsize) : (byte *)array;
79 if(count+1 > minAllocSize)
81 int offset = pos - (byte *)array;
82 array = renew array T[count + 1];
83 pos = (byte *)array+offset;
85 memmove(pos + tsize, pos, (byte *)array+(count++) * tsize - pos);
87 return (IteratorPointer)pos;
90 IteratorPointer Add(T value)
92 if(count + 1 > minAllocSize)
93 array = renew array T[count + 1];
95 return (IteratorPointer)(array + (count++));
98 void Remove(IteratorPointer ip)
101 memmove(it, it + 1, (count - (it - array) - 1) * class(T).typeSize);
103 if(count + 1 > minAllocSize)
104 array = renew array T[count];
107 void Move(IteratorPointer ip, IteratorPointer afterIp)
111 T * after = (T *)afterIp;
115 virtual void RemoveAll()
117 if(minAllocSize && array)
118 array = renew0 array T[minAllocSize];
124 virtual int GetCount() { return count; }
128 get { return count; }
133 if(value > minAllocSize)
134 array = renew0 array T[value];
135 else if(value > count)
138 void * a = array + count;
139 void * b = (byte *)array + count * class(T).typeSize;
144 //memset(array + count, 0, (value - count) * class(T).typeSize);
145 /*if(!strcmp(class(T).name, "TessPrim"))
146 printf("Memsetting to 0 from %d for %d bytes\n", count * class(T).typeSize, (value - count) * class(T).typeSize);*/
147 memset((byte *)array + count * class(T).typeSize, 0, (value - count) * class(T).typeSize);
150 #if defined(_DEBUG) && !defined(MEMINFO) && defined(MEMTRACKING)
153 MemBlock block = (MemBlock)((byte *)array - sizeof(class MemBlock));
154 block._class = class(T);
161 property uint minAllocSize
163 get { return minAllocSize; }
166 if(minAllocSize != value)
169 array = renew array T[value];
170 minAllocSize = value;
175 virtual void Copy(Container source)
177 count = source.GetCount();
178 if(count > minAllocSize)
179 array = renew array T[count];
181 // TOFIX: Precomp fails on (BuiltInContainer *)
182 if((source._class == class(BuiltInContainer) && ((struct BuiltInContainer *)source)->type.type != structClass ) ||
183 eClass_IsDerived(source._class, class(Array)))
185 memcpy(array, ((Array)source).array, count * class(T).typeSize);
191 for(c = 0, i = source.GetFirst(); i; i = source.GetNext(i), c++)
193 D data = source.GetData(i);
203 for(c = 0; c<count; c++)
213 void Delete(IteratorPointer item)