71 static_assert(std::is_trivial<TYPE>::value,
"Non trivial type used, try Util::Array instead");
79 Array<TYPE>(_capacity, _grow)
82 static_assert(std::is_trivial<TYPE>::value,
"Non trivial type used, try Util::Array instead");
90 Array<TYPE>(initialSize, _grow, initialValue)
92 static_assert(std::is_trivial<TYPE>::value,
"Non trivial type used, try Util::Array instead");
102 static_assert(std::is_trivial<TYPE>::value,
"Non trivial type used, try Util::Array instead");
129template<
class TYPE>
void
132 #if NEBULA_BOUNDSCHECKS
136 this->grow = src.
grow;
138 this->size = src.
size;
139 if (this->capacity > 0)
141 this->elements =
new TYPE[this->capacity];
149template<
class TYPE>
void
152#if NEBULA_BOUNDSCHECKS
155 this->grow = src.
grow;
157 this->size = src.
size;
158 if (this->capacity > 0)
160 this->elements =
new TYPE[this->capacity];
168template<
class TYPE>
void
186template<
class TYPE>
void
191 if ((this->capacity > 0) && (rhs.
size <= this->capacity))
197 this->grow = rhs.
grow;
198 this->size = rhs.
size;
212template<
class TYPE>
void
217 if ((this->capacity > 0) && (rhs.
size <= this->capacity))
223 this->grow = rhs.
grow;
224 this->size = rhs.
size;
237template<
class TYPE>
void
240 TYPE* newArray =
new TYPE[newCapacity];
243 Memory::Copy(this->elements, newArray, this->size *
sizeof(TYPE));
245 delete[] this->elements;
247 this->elements = newArray;
248 this->capacity = newCapacity;
256template<
class TYPE>
void
259 #if NEBULA_BOUNDSCHECKS
265 if (fromIndex == toIndex)
271 SizeT num = this->size - fromIndex;
274 SizeT neededSize = toIndex + num;
275 while (neededSize > this->capacity)
281 if (fromIndex > toIndex)
285 for (i = 0; i < num; i++)
287 this->elements[toIndex + i] = this->elements[fromIndex + i];
294 for (i = num - 1; i >= 0; --i)
296 this->elements[toIndex + i] = this->elements[fromIndex + i];
301 this->size = toIndex + num;
307template<
class TYPE>
void
310 #if NEBULA_BOUNDSCHECKS
311 n_assert(this->elements && (index < this->size));
313 if (index == (this->size - 1))
320 this->Move(index + 1, index);
328template<
class TYPE>
void
331 #if NEBULA_BOUNDSCHECKS
332 n_assert(this->elements && (index < this->size));
336 IndexT lastElementIndex = this->size - 1;
337 if (index < lastElementIndex)
339 this->elements[index] = this->elements[lastElementIndex];
349template<
class TYPE>
void
Nebula's dynamic array class.
Definition array.h:60
SizeT capacity
Definition array.h:248
TYPE * elements
Definition array.h:250
SizeT grow
Definition array.h:247
size_t size() const
Definition array.h:1699
Array class based on Util::Array for trivial and POD types that avoids any per element copying and co...
Definition trivialarray.h:19
void Copy(const TrivialArray< TYPE > &src)
copy content
Definition trivialarray.h:130
~TrivialArray()
destructor
Definition trivialarray.h:178
void Move(IndexT fromIndex, IndexT toIndex)
move elements, grows array if needed
Definition trivialarray.h:257
void EraseIndexSwap(IndexT index)
erase element at index, fill gap by swapping in last element, destroys sorting!
Definition trivialarray.h:329
void Clear()
clear array (calls destructors)
Definition trivialarray.h:350
void EraseIndex(IndexT index)
erase element at index, keep sorting intact
Definition trivialarray.h:308
TrivialArray()
constructor with default parameters
Definition trivialarray.h:69
TYPE * Iterator
define iterator
Definition trivialarray.h:22
void GrowTo(SizeT newCapacity)
grow array to target size
Definition trivialarray.h:238
void operator=(const TrivialArray< TYPE > &rhs)
assignment operator
Definition trivialarray.h:187
void Destroy(TYPE *elm)
does nothing
Definition trivialarray.h:169
#define n_assert(exp)
Definition debug.h:50
void Copy(const void *from, void *to, size_t numBytes)
Copy a chunk of memory (note the argument order is different from memcpy()!!!)
Definition osxmemory.cc:213
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48