36 unsigned int num()
const {
return static_cast<unsigned int>(_pointers.size());}
38 T*
at(
unsigned int pos)
const {
return (pos<_pointers.size()) ? _pointers[pos] :
nullptr; }
57 void swap(
unsigned int i,
unsigned int j);
59 std::vector<T*> _pointers;
61 std::vector<int> _positions;
77 _pointers.reserve(init);
78 _positions.reserve(init);
108 T*&
pi = _pointers[
i];
109 T*&
pj = _pointers[
j];
115 _positions[
i] = _positions[
j];
118 _pointers[
i]->setEntryNumber(
i);
119 _pointers[
j]->setEntryNumber(
j);
132 unsigned int entryNumber =
static_cast<unsigned int>(_pointers.size());
133 _pointers.push_back(t);
134 _positions.push_back(pos);
145 if (t ==
nullptr) {
return -1; }
146 const int i = t->getEntryNumber();
148 if (
i >=
n) {
return -1; }
149 if (
i <= -1) {
return -1; }
151 _objects.deleteAt(_positions[
i]);
157 at(
n - 1)->setEntryNumber(-1);
159 _pointers.pop_back();
160 _positions.pop_back();
187 at(
static_cast<unsigned int>(
i))->setEntryNumber(
static_cast<int>(
i));
192 WEM_ERROR(
"Vector of re-ordered indices must have the same size as the internal vectors!");
#define WEM_ERROR(msg)
Defines an output routine for error messages.
This template implements a proxy for container that contain a collection of items that are normally a...
Dynamic vector, based on a memory pool. Keeps track on entry numbers of stored primitives.
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.