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]; }
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);
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];
unsigned int num() const
Returns the number of elements in the vector.
virtual int lookup(T *elem) const
Searches for an element in the vector and returns its position.
CSOObjectVector(unsigned int init=0, unsigned int bs=65535)
Standard constructor.
virtual ~CSOObjectVector()
Standard destructor.
T * lastBoundsCheck() const
Returns the last element, and returns nullptr if out of range.
virtual void swap(unsigned int p1, unsigned int p2)
Swaps two elements in the vector.
T * atBoundsCheck(unsigned int pos) const
Returns the element at the specified position, and returns nullptr when out of range.
virtual int removeUnSwapped(T *elem)
Deletes an element specified by its pointer and returns its position.
T * firstBoundsCheck() const
Returns the first element, and return nullptr if out of range.
virtual unsigned int append(T *elem)
Appends the element to the back of the vector and returns its position.
T * at(unsigned int pos) const
Returns the element at the specified position.
virtual void replace(T *elem, unsigned int pos)
Replaces the element at the specified position with the specified element.
virtual void expand()
Grows vector by adding an extra block of size BLOCKSIZE.
virtual void deleteLast()
Deletes the last element of the vector.
void reserve(unsigned int init)
Reserves a number of elements. It copies old elements if needed.
virtual unsigned int appendUnsafe(T *elem)
virtual void deleteAt(unsigned int pos)
Deletes an element at the specified position.
virtual int remove(T *elem)
Deletes an element specified by its pointer and returns its position.
T * last() const
Returns the last element.
T * first() const
Returns the first element.
void deleteVector(CSOObjectVector< T > *vector, bool deleteEntries=true)