19template<
class TYPE,
bool StackAlloc = false>
class FixedArray
73 void Fill(
const TYPE& val);
102 template<
class T,
bool S>
120template<
class TYPE,
bool StackAlloc>
131template<
class TYPE,
bool StackAlloc>
void
154template<
class TYPE,
bool StackAlloc>
void
157 #if NEBULA_BOUNDSCHECKS
178template<
class TYPE,
bool StackAlloc>
void
184 if constexpr (!std::is_trivially_copyable<TYPE>::value)
187 for (i = 0; i < this->
count; i++)
200template<
class TYPE,
bool StackAlloc>
211template<
class TYPE,
bool StackAlloc>
217 this->
Fill(initialValue);
223template<
class TYPE,
bool StackAlloc>
230 this->Alloc(rhs.count);
231 if constexpr (!std::is_trivially_copyable<TYPE>::value)
234 for (i = 0; i < this->count; i++)
236 this->elements[i] = rhs.elements[i];
247template<
class TYPE,
bool StackAlloc>
254 this->Alloc(rhs.count);
255 if constexpr (!std::is_trivially_copyable<TYPE>::value)
258 for (i = 0; i < this->count; i++)
260 this->elements[i] = rhs.elements[i];
271template<
class TYPE,
bool StackAlloc>
279 if constexpr (!std::is_trivially_copyable<TYPE>::value)
282 for (i = 0; i < this->
count; i++)
288 memcpy(this->
elements, rhs.
Begin(), this->count *
sizeof(TYPE));
295template<
class TYPE,
bool StackAlloc>
303 if (rhs.stackElements.data() == rhs.elements || StackAlloc)
305 this->Alloc(rhs.count);
306 if constexpr (!std::is_trivially_copyable<TYPE>::value)
309 for (i = 0; i < this->count; i++)
311 this->elements[i] = rhs.Begin()[i];
315 memcpy(this->elements, rhs.Begin(), this->count * sizeof(TYPE));
319 this->elements = rhs.elements;
320 rhs.elements = nullptr;
321 this->count = rhs.count;
331template<
class TYPE,
bool StackAlloc>
338 this->
Alloc(rhs.count);
339 if constexpr (!std::is_trivially_copyable<TYPE>::value)
342 for (i = 0; i < this->
count; i++)
348 memcpy(this->
elements, rhs.Begin(), this->count *
sizeof(TYPE));
353 rhs.elements =
nullptr;
360template<
class TYPE,
bool StackAlloc>
366 if constexpr (!std::is_trivially_copyable<TYPE>::value)
369 for (i = 0; i < this->
count; i++)
371 this->
elements[i] = list.begin()[i];
375 memcpy(this->
elements, list.begin(), this->count *
sizeof(TYPE));
381template<
class TYPE,
bool StackAlloc>
391template<
class TYPE,
bool StackAlloc>
400template<
class TYPE,
bool StackAlloc>
void
413template<
class TYPE,
bool StackAlloc>
void
420 this->
count = rhs.count;
421 rhs.elements =
nullptr;
429template<
class TYPE,
bool StackAlloc> TYPE&
432 #if NEBULA_BOUNDSCHECKS
441template<
class TYPE,
bool StackAlloc>
bool
450 #if NEBULA_BOUNDSCHECKS
455 for (i = 0; i < num; i++)
469template<
class TYPE,
bool StackAlloc>
bool
472 return !(*
this == rhs);
478template<
class TYPE,
bool StackAlloc>
void
488template<
class TYPE,
bool StackAlloc>
void
492 if (newSize == this->
count)
495 TYPE* newElements = 0;
509 if (numCopy > newSize)
511 if constexpr (!std::is_trivially_move_assignable<TYPE>::value && std::is_move_assignable<TYPE>::value)
514 for (i = 0; i < numCopy; i++)
516 newElements[i] = std::move(this->
elements[i]);
531 this->
count = newSize;
537template<
class TYPE,
bool StackAlloc>
const SizeT
546template<
class TYPE,
bool StackAlloc>
const SizeT
549 return this->
count *
sizeof(TYPE);
555template<
class TYPE,
bool StackAlloc>
bool
558 return 0 == this->
count;
564template<
class TYPE,
bool StackAlloc>
void
573template<
class TYPE,
bool StackAlloc>
578 if (std::is_trivially_destructible<TYPE>::value)
585 for (i = 0; i < this->
count; i++)
596template<
class TYPE,
bool StackAlloc>
void
600 for (i = 0; i < this->
count; i++)
609template<
class TYPE,
bool StackAlloc>
void
612 #if NEBULA_BOUNDSCHECKS
617 for (i = first; i < (first + num); i++)
644template<
class TYPE,
bool StackAlloc>
653template<
class TYPE,
bool StackAlloc>
666 for (i = 0; i < this->
count; i++)
679template<
class TYPE,
bool StackAlloc>
IndexT
683 for (i = 0; i < this->
count; i++)
696template<
class TYPE,
bool StackAlloc>
void
699 std::sort(this->
Begin(), this->
End());
706template<
class TYPE,
bool StackAlloc>
IndexT
718 if (0 != (
half = num/2))
720 mid = lo + ((num & 1) ?
half : (
half - 1));
765 for (i = 0; i < this->
count; i++)
793template<
class TYPE,
bool StackAlloc>
void
796 n_error(
"Trying to resize a fixed array");
802template<
class TYPE,
bool StackAlloc>
size_t
Nebula's dynamic array class.
Definition array.h:60
void Reserve(SizeT num)
increase capacity to fit N more elements into the array.
Definition array.h:862
void Append(const TYPE &first, const ELEM_TYPE &... elements)
Append multiple elements to the end of the array.
Definition array.h:1334
Iterator Begin() const
return iterator to beginning of array
Definition array.h:1245
void Delete()
delete content
Definition fixedarray.h:132
void operator=(const FixedArray< TYPE, StackAlloc > &rhs)
assignment operator
Definition fixedarray.h:401
Iterator End() const
get iterator past last element
Definition fixedarray.h:636
IndexT BinarySearchIndex(const TYPE &val) const
do a binary search, requires a sorted array
Definition fixedarray.h:707
FixedArray(FixedArray< TYPE, StackAlloc > &&rhs)
move constructor
Definition fixedarray.h:332
TYPE & operator[](IndexT index) const
write [] operator
Definition fixedarray.h:430
Iterator Find(const TYPE &val) const
find identical element in unsorted array (slow)
Definition fixedarray.h:663
Array< TYPE > AsArray() const
return content as Array (slow!)
Definition fixedarray.h:760
void Fill(const TYPE &val)
fill the entire array with a value
Definition fixedarray.h:597
bool operator==(const FixedArray< TYPE, StackAlloc > &rhs) const
equality operator
Definition fixedarray.h:442
Iterator end() const
Definition fixedarray.h:785
FixedArray(const FixedArray< TYPE, false > &rhs)
copy constructor
Definition fixedarray.h:248
Iterator Begin() const
get iterator to first element
Definition fixedarray.h:627
FixedArray(const SizeT s)
constructor with size
Definition fixedarray.h:201
const SizeT ByteSize() const
get total byte size
Definition fixedarray.h:547
size_t size() const
Definition fixedarray.h:803
const SizeT Size() const
get number of elements
Definition fixedarray.h:538
void resize(size_t size)
Definition fixedarray.h:794
FixedArray(const FixedArray< TYPE, true > &rhs)
copy constructor
Definition fixedarray.h:224
TYPE & Back() const
return reference to last element
Definition fixedarray.h:654
IndexT FindIndex(const TYPE &val) const
find index of identical element in unsorted array (slow)
Definition fixedarray.h:680
TYPE & Front() const
return reference to first element
Definition fixedarray.h:645
void operator=(FixedArray< TYPE, StackAlloc > &&rhs) noexcept
move assignment operator
Definition fixedarray.h:414
bool operator!=(const FixedArray< TYPE, StackAlloc > &rhs) const
inequality operator
Definition fixedarray.h:470
void Clear()
clear the array, free elements
Definition fixedarray.h:565
ComponentId * Iterator
Definition fixedarray.h:23
FixedArray()
default constructor
Definition fixedarray.h:121
FixedArray(std::initializer_list< TYPE > list)
constructor from initializer list
Definition fixedarray.h:361
bool IsEmpty() const
return true if array if empty (has no elements)
Definition fixedarray.h:556
void Fill(IndexT first, SizeT num, const TYPE &val)
fill array range with element
Definition fixedarray.h:610
FixedArray(const Array< TYPE > &rhs)
construct from array
Definition fixedarray.h:272
void Resize(SizeT newSize)
resize array without deleting existing content
Definition fixedarray.h:489
void Reset()
Reset the size and destroy all elements.
Definition fixedarray.h:574
void SetSize(SizeT s)
set number of elements (clears existing content)
Definition fixedarray.h:479
~FixedArray()
destructor
Definition fixedarray.h:392
ComponentId * elements
Definition fixedarray.h:113
void Copy(const FixedArray< TYPE, StackAlloc > &src)
copy content
Definition fixedarray.h:179
friend class FixedArray
Definition fixedarray.h:103
void Alloc(SizeT s)
allocate array for given size
Definition fixedarray.h:155
FixedArray(const SizeT s, const TYPE &initialValue)
constructor with size and initial value
Definition fixedarray.h:212
FixedArray(std::nullptr_t)
construct an empty fixed array
Definition fixedarray.h:382
SizeT count
Definition fixedarray.h:112
FixedArray(Array< TYPE > &&rhs)
move from array
Definition fixedarray.h:296
Iterator begin() const
for range-based iteration (C++11)
Definition fixedarray.h:776
void Sort()
sort the array
Definition fixedarray.h:697
void __cdecl n_error(const char *msg,...)
This function is called when a serious situation is encountered which requires abortion of the applic...
Definition debug.cc:138
#define n_assert(exp)
Definition debug.h:50
void ArrayFreeStack(size_t size, TYPE *buffer)
Definition memory.h:205
TYPE * ArrayAllocStack(size_t size)
Definition memory.h:155
void ArrayFree(size_t size, TYPE *buffer)
Definition memory.h:188
TYPE * ArrayAlloc(size_t size)
Definition memory.h:137
__forceinline void MoveElements(const T *from, T *to, size_t numElements)
Move a chunk of memory, can handle overlapping regions.
Definition posixmemory.h:197
A quad tree designed to return regions of free 2D space.
Definition String.cs:6
#define StackAlloc(size)
Definition posixmemory.h:31
static const int InvalidIndex
Definition types.h:47
int SizeT
Definition types.h:42
int IndexT
Definition types.h:41