4 typedef long unsigned int LUint;
11 Array() : start(NULL), size(0), reserved(0) {}
12 Array(LUint newSize) : start(new T[newSize]), size(newSize), reserved(newSize) {}
13 ~Array() {delete [] start;}
15 void Empty() {size = 0;}
16 void Add(const T & add);
17 void Reserve(LUint reserve);
18 void Resize(LUint newSize);
21 LUint Size() const {return size;}
22 LUint Capacity() const {return reserved;}
24 void operator=(const Array & equ);
25 bool operator==(const Array & equ) const;
26 bool operator!=(const Array & equ) const {return !operator==(equ);}
31 Iterator(const Array & from) : parent(from), index(0) {}
32 Iterator(const Iterator & cpy) : parent(cpy.parent), index(cpy.index) {}
35 bool Good() const {return index < parent.Size();}
37 T & operator*() const {return parent.start[index];}
39 void operator++() {++index;}
40 void operator--() {--index;}
41 void operator++(int) {operator++();}
42 void operator--(int) {operator--();}
43 Iterator & operator+=(int amount) {index += amount;}
44 Iterator & operator-=(int amount) {index -= amount;}
45 Iterator operator+(int amount) {return Iterator(*this) += amount;}
46 Iterator operator-(int amount) {return Iterator(*this) -= amount;}
48 void operator=(const Iterator & set) {index = set.index;}
49 bool operator==(const Iterator & set) {return (&parent == &(set.parent) && index == set.index);}
55 Iterator First() const {return Iterator(*this);}
56 Iterator Last() const {return Iterator(*this) -= (size-1);}
59 T & operator[](LUint at) const
62 printf(" Array<T>::operator[] - called for index %lu/%lu (reserved %lu)\n", at, size, reserved);
65 assert(at < size); return start[at];
68 int Find(const T & find)
72 for (result = 0; result < size; result++)
74 //printf("%p %lu/%lu\n", (void*)(start), result, size);
75 if (start[result] == find)
83 LUint size; LUint reserved;
86 template <class T> void Array<T>::Add(const T & add)
91 reserved *= 2; ++reserved;
92 start = new T[reserved];
93 for (LUint ii=0; ii < size; ++ii)
100 template <class T> void Array<T>::RemoveBack()
106 template <class T> void Array<T>::Resize(LUint newSize)
109 start = new T[newSize];
110 for (LUint ii=0; ii < size; ++ii)
112 size = newSize; reserved = newSize;
116 template <class T> void Array<T>::Reserve(LUint newReserve)
118 if (newReserve > reserved)
121 start = new T[newReserve];
122 for (LUint ii=0; ii < size; ++ii)
124 reserved = newReserve;