42 inline unsigned int num()
const {
return length;}
44 inline T*
atBoundsCheck(
unsigned int pos)
const {
return (pos<length) ? block[pos] :
nullptr; }
46 inline T*
at(
unsigned int pos)
const {
return block[pos]; }
50 inline T*
first()
const {
return at(0);}
54 inline T*
last()
const {
return at(length-1);}
56 virtual unsigned int append(
T* elem);
58 virtual void swap(
unsigned int p1,
unsigned int p2);
63 virtual void deleteAt(
unsigned int pos);
65 virtual void deleteLast();
67 virtual int remove(
T* elem);
69 virtual int lookup(
T* elem)
const;
71 virtual int removeUnSwapped(
T* elem);
74 virtual void destroy();
76 virtual void replace(
T* elem,
unsigned int pos);
78 void reserve(
unsigned int init);
85 unsigned int capacity;
86 unsigned int BLOCKSIZE;
93 virtual void expand();
96 virtual unsigned int appendUnsafe(
T* elem);
129 block =
new T * [capacity];
151 length = capacity = 0;
159 for (
unsigned int i = 0; i < length; ++i)
161 delete block[i]; block[i] =
nullptr;
171 T* *newblock =
nullptr;
172 newblock =
new T*[capacity+BLOCKSIZE];
174 for (
unsigned int i = 0; i < length; ++i)
176 newblock[i] = block[i];
182 capacity += BLOCKSIZE;
192 if (length == capacity)
196 block[length] = elem;
207 if (length == capacity)
211 block[length] = elem;
260 block[length] =
nullptr;
270 for (
unsigned int i = 0; i < length; ++i)
274 pos =
static_cast<int>(i);
286 int pos = lookup(elem);
289 deleteAt(
static_cast<unsigned int>(pos));
299 const int pos = lookup(elem);
302 for (
unsigned int i =
static_cast<unsigned int>(pos); i < length-1; ++i)
304 block[i] = block[i+1];
316 if (init <= capacity)
320 T* *newblock =
nullptr;
321 newblock =
new T*[init];
322 for (
unsigned int i = 0; i < length; ++i)
324 newblock[i] = block[i];
Dynamic templated vector.
unsigned int num() const
Returns the number of elements in the vector.
T * lastBoundsCheck() const
Returns the last element, and returns nullptr if out of range.
virtual void destroy()
Deletes all elements in the vector.
T * atBoundsCheck(unsigned int pos) const
Returns the element at the specified position, and returns nullptr when out of range.
T * firstBoundsCheck() const
Returns the first element, and return nullptr if out of range.
T * at(unsigned int pos) const
Returns the element at the specified position.
T * last() const
Returns the last element.
T * first() const
Returns the first element.
void deleteVector(CSOObjectVector< T > *vector, bool deleteEntries=true)