34 unsigned int num()
const
36 return static_cast<unsigned int>(_pointers.size());
39 T*
at(
unsigned int pos)
const
41 return (pos < _pointers.size()) ? _pointers[pos] :
nullptr;
70 void swap(
unsigned int i,
unsigned int j);
72 std::vector<T*> _pointers;
74 std::vector<int> _positions;
90 _pointers.reserve(init);
91 _positions.reserve(init);
117 T*&
pi = _pointers[
i];
118 T*&
pj = _pointers[
j];
124 _positions[
i] = _positions[
j];
127 _pointers[
i]->setEntryNumber(
static_cast<int>(
i));
128 _pointers[
j]->setEntryNumber(
static_cast<int>(
j));
139 int entryNumber =
static_cast<int>(_pointers.size());
140 _pointers.push_back(t);
141 _positions.push_back(
static_cast<int>(pos));
154 const int i = t->getEntryNumber();
155 const int n =
static_cast<int>(num());
163 _objects.deleteAt(
static_cast<unsigned int>(_positions[
static_cast<unsigned int>(
i)]));
166 swap(
static_cast<unsigned int>(
i),
static_cast<unsigned int>(
n - 1));
168 at(
static_cast<unsigned int>(
n - 1))->setEntryNumber(-1);
170 _pointers.pop_back();
171 _positions.pop_back();
194 at(
static_cast<unsigned int>(
i))->setEntryNumber(
static_cast<int>(
i));
198 WEM_ERROR(
"Vector of reordered indices must have the same size as the internal vectors!");
220 T*
object = _objects.at(
i);
221 object->setEntryNumber(
static_cast<int>(
i));
222 _pointers[
i] = object;
223 _positions[
i] =
static_cast<int>(
i);
#define WEM_ERROR(msg)
Defines an output routine for error messages.
This template implements a proxy for containers that contain a collection of items normally accessed ...
Dynamic vector, based on a memory pool. Keeps track on entry numbers of stored primitives.
void createNumObjects(unsigned int numObjects)
Creates the given number of new objects.
void reserve(unsigned int numObjects)
Reserves memory for the given number of objects.
WEMIndexVector(unsigned int init=0, unsigned int bs=8192)
Standard constructor.
WEMIndexVector(WEMIndexVector &&other) noexcept=default
WEMIndexVector & operator=(WEMIndexVector &&other) noexcept=default
T * first()
Returns the first element of this vector.
const T * first() const
Returns the first element of this vector.
void destroy()
Destroys all elements in this vector.
~WEMIndexVector()
Standard destructor.
unsigned int num() const
Returns the number of elements in this vector.
T * at(unsigned int pos) const
Returns the element at the given position, typecast from WEMPrimitive to T.
int remove(T *t)
Removes the given element from vector.
void reorder(const std::vector< unsigned int > &indexOrder)
Sets the order by the given vector of indices.
T * append()
Appends an element to this vector, returns it and updates the index.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.