26 template <
class T,
int fixedBufferSize = 32>
39 inline unsigned int num()
const {
return _length;}
41 inline T*
at(
unsigned int pos)
const {
return (pos<_length) ? _block[pos] :
nullptr; }
53 virtual void swap(
unsigned int p1,
unsigned int p2);
71 virtual void replace(
T* elem,
unsigned int pos);
80 unsigned int _capacity;
84 T* _fixedBuffer[fixedBufferSize];
97 template <
class T,
int fixedBufferSize>
101 _capacity = fixedBufferSize;
102 _block = _fixedBuffer;
104 if (
init > _capacity) {
106 _block =
new T*[_capacity];
110 template <
class T,
int fixedBufferSize>
113 *
this = std::move(other);
116 template <
class T,
int fixedBufferSize>
119 _length = other._length;
121 _capacity = other._capacity;
122 other._capacity = fixedBufferSize;
124 if (other._block == other._fixedBuffer)
126 _block = _fixedBuffer;
127 for (
auto i = 0u; i < _length; ++i)
129 _fixedBuffer[i] = other._fixedBuffer[i];
134 _block = other._block;
136 other._block = other._fixedBuffer;
143 template <
class T,
int fixedBufferSize>
151 template <
class T,
int fixedBufferSize>
154 if (_block != _fixedBuffer)
161 _capacity = fixedBufferSize;
162 _block = _fixedBuffer;
167 template <
class T,
int fixedBufferSize>
170 for (
unsigned int i = 0; i < _length; i++)
172 delete _block[i]; _block[i] =
nullptr;
179 template <
class T,
int fixedBufferSize>
182 reserve(_capacity * 2);
187 template <
class T,
int fixedBufferSize>
192 if (_length == _capacity)
196 _block[_length] = elem;
204 template <
class T,
int fixedBufferSize>
207 if (_length == _capacity)
211 _block[_length] = elem;
218 template <
class T,
int fixedBufferSize>
226 template <
class T,
int fixedBufferSize>
232 T*& pb1 = _block[p1];
233 T*& pb2 = _block[p2];
242 template <
class T,
int fixedBufferSize>
245 if (pos != _length-1)
254 template <
class T,
int fixedBufferSize>
265 template <
class T,
int fixedBufferSize>
269 for (
unsigned int i = 0; i < _length; i++)
271 if (_block[i] == elem)
282 template <
class T,
int fixedBufferSize>
285 const int pos = lookup(elem);
295 template <
class T,
int fixedBufferSize>
298 const int pos = lookup(elem);
301 for (
unsigned int i = pos; i < _length-1; i++)
303 _block[i] = _block[i+1];
312 template <
class T,
int fixedBufferSize>
315 if (
init <= _capacity) {
return; }
317 T* *newblock =
nullptr;
318 newblock =
new T*[
init];
319 for (
unsigned int i = 0; i < _length; i++)
321 newblock[i] = _block[i];
323 if (_block != _fixedBuffer)
Dynamic templated vector.
T * last()
Returns the last element.
virtual void clear()
Clears all internal pointers.
WEMVector(unsigned int init=0)
Standard constructor.
WEMVector(WEMVector &&other) noexcept
virtual void replace(T *elem, unsigned int pos)
Replaces the given position with the given element.
WEMVector & operator=(WEMVector &&other) noexcept
virtual void destroy()
Deletes all elements in this vector.
virtual unsigned int append(T *elem)
Appends the given element to back of this vector.
T * at(unsigned int pos) const
Returns the element at the given position or returns NULL if out of range.
virtual void expand()
Grow vector, add extra block of size BLOCKSIZE.
unsigned int num() const
Returns the number of elements in this vector.
virtual int removeUnSwapped(T *elem)
Deletes the element given by its pointer. Keeps the order of the elements!
virtual int lookup(T *elem) const
Searches for the given element in this vector and returns its position.
virtual void swap(unsigned int p1, unsigned int p2)
Swaps the two elements given by their indices in this vector.
const T * first() const
Returns the first element.
virtual void deleteAt(unsigned int pos)
Deletes the element at the given position.
T * first()
Returns the first element.
virtual int remove(T *elem)
Deletes the element given by its pointer.
virtual unsigned int appendUnsafe(T *elem)
Append element to back of vector, don't check on element being non-NULL.
virtual void deleteLast()
Deletes the last element of this vector.
virtual ~WEMVector()
Standard destructor.
const T * last() const
Returns the last element.
void reserve(unsigned int init)
Reserves init elements, copies old ones if existing.
IteratorTraits::value_type & at(const ml_iterator_map< IteratorTraits, IDMap > &i, typename property_traits< IDMap >::key_type key)
void init()
Initializes the ML, the runtime type system, the memory manager, fields, static buffers,...
void destroy()
Delete dynamic data structures allocated by init().