19template<
class TYPE,
bool StackAlloc = false>
class FixedArray
73 void Fill(
const TYPE& val);
98 template<
class T,
bool S>
116template<
class TYPE,
bool StackAlloc>
127template<
class TYPE,
bool StackAlloc>
void
150template<
class TYPE,
bool StackAlloc>
void
153 #if NEBULA_BOUNDSCHECKS
174template<
class TYPE,
bool StackAlloc>
void
180 if constexpr (!std::is_trivially_copyable<TYPE>::value)
183 for (i = 0; i < this->
count; i++)
196template<
class TYPE,
bool StackAlloc>
207template<
class TYPE,
bool StackAlloc>
213 this->
Fill(initialValue);
219template<
class TYPE,
bool StackAlloc>
226 this->Alloc(rhs.count);
227 if constexpr (!std::is_trivially_copyable<TYPE>::value)
230 for (i = 0; i < this->count; i++)
232 this->elements[i] = rhs.elements[i];
243template<
class TYPE,
bool StackAlloc>
250 this->Alloc(rhs.count);
251 if constexpr (!std::is_trivially_copyable<TYPE>::value)
254 for (i = 0; i < this->count; i++)
256 this->elements[i] = rhs.elements[i];
267template<
class TYPE,
bool StackAlloc>
275 if constexpr (!std::is_trivially_copyable<TYPE>::value)
278 for (i = 0; i < this->
count; i++)
284 memcpy(this->
elements, rhs.
Begin(), this->count *
sizeof(TYPE));
291template<
class TYPE,
bool StackAlloc>
299 if (rhs.stackElements.data() == rhs.elements || StackAlloc)
301 this->Alloc(rhs.count);
302 if constexpr (!std::is_trivially_copyable<TYPE>::value)
305 for (i = 0; i < this->count; i++)
307 this->elements[i] = rhs.Begin()[i];
311 memcpy(this->elements, rhs.Begin(), this->count * sizeof(TYPE));
315 this->elements = rhs.elements;
316 rhs.elements = nullptr;
317 this->count = rhs.count;
327template<
class TYPE,
bool StackAlloc>
334 this->
Alloc(rhs.count);
335 if constexpr (!std::is_trivially_copyable<TYPE>::value)
338 for (i = 0; i < this->
count; i++)
344 memcpy(this->
elements, rhs.Begin(), this->count *
sizeof(TYPE));
349 rhs.elements =
nullptr;
356template<
class TYPE,
bool StackAlloc>
362 if constexpr (!std::is_trivially_copyable<TYPE>::value)
365 for (i = 0; i < this->
count; i++)
367 this->
elements[i] = list.begin()[i];
371 memcpy(this->
elements, list.begin(), this->count *
sizeof(TYPE));
377template<
class TYPE,
bool StackAlloc>
387template<
class TYPE,
bool StackAlloc>
396template<
class TYPE,
bool StackAlloc>
void
409template<
class TYPE,
bool StackAlloc>
void
416 this->
count = rhs.count;
417 rhs.elements =
nullptr;
425template<
class TYPE,
bool StackAlloc> TYPE&
428 #if NEBULA_BOUNDSCHECKS
437template<
class TYPE,
bool StackAlloc>
bool
446 #if NEBULA_BOUNDSCHECKS
451 for (i = 0; i < num; i++)
465template<
class TYPE,
bool StackAlloc>
bool
468 return !(*
this == rhs);
474template<
class TYPE,
bool StackAlloc>
void
484template<
class TYPE,
bool StackAlloc>
void
488 if (newSize == this->
count)
491 TYPE* newElements = 0;
505 if (numCopy > newSize)
507 if constexpr (!std::is_trivially_move_assignable<TYPE>::value && std::is_move_assignable<TYPE>::value)
510 for (i = 0; i < numCopy; i++)
512 newElements[i] = std::move(this->
elements[i]);
527 this->
count = newSize;
533template<
class TYPE,
bool StackAlloc>
const SizeT
542template<
class TYPE,
bool StackAlloc>
const SizeT
545 return this->
count *
sizeof(TYPE);
551template<
class TYPE,
bool StackAlloc>
bool
554 return 0 == this->
count;
560template<
class TYPE,
bool StackAlloc>
void
569template<
class TYPE,
bool StackAlloc>
574 if (std::is_trivially_destructible<TYPE>::value)
581 for (i = 0; i < this->
count; i++)
593template<
class TYPE,
bool StackAlloc>
void
597 for (i = 0; i < this->
count; i++)
606template<
class TYPE,
bool StackAlloc>
void
609 #if NEBULA_BOUNDSCHECKS
614 for (i = first; i < (first + num); i++)
645 for (i = 0; i < this->
count; i++)
658template<
class TYPE,
bool StackAlloc>
IndexT
662 for (i = 0; i < this->
count; i++)
675template<
class TYPE,
bool StackAlloc>
void
678 std::sort(this->
Begin(), this->
End());
685template<
class TYPE,
bool StackAlloc>
IndexT
697 if (0 != (
half = num/2))
699 mid = lo + ((num & 1) ?
half : (
half - 1));
744 for (i = 0; i < this->
count; i++)
772template<
class TYPE,
bool StackAlloc>
void
775 n_error(
"Trying to resize a fixed array");
781template<
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:128
void operator=(const FixedArray< TYPE, StackAlloc > &rhs)
assignment operator
Definition fixedarray.h:397
Iterator End() const
get iterator past last element
Definition fixedarray.h:633
IndexT BinarySearchIndex(const TYPE &val) const
do a binary search, requires a sorted array
Definition fixedarray.h:686
FixedArray(FixedArray< TYPE, StackAlloc > &&rhs)
move constructor
Definition fixedarray.h:328
TYPE & operator[](IndexT index) const
write [] operator
Definition fixedarray.h:426
Iterator Find(const TYPE &val) const
find identical element in unsorted array (slow)
Definition fixedarray.h:642
Array< TYPE > AsArray() const
return content as Array (slow!)
Definition fixedarray.h:739
void Fill(const TYPE &val)
fill the entire array with a value
Definition fixedarray.h:594
bool operator==(const FixedArray< TYPE, StackAlloc > &rhs) const
equality operator
Definition fixedarray.h:438
Iterator end() const
Definition fixedarray.h:764
FixedArray(const FixedArray< TYPE, false > &rhs)
copy constructor
Definition fixedarray.h:244
Iterator Begin() const
get iterator to first element
Definition fixedarray.h:624
FixedArray(const SizeT s)
constructor with size
Definition fixedarray.h:197
const SizeT ByteSize() const
get total byte size
Definition fixedarray.h:543
size_t size() const
Definition fixedarray.h:782
const SizeT Size() const
get number of elements
Definition fixedarray.h:534
void resize(size_t size)
Definition fixedarray.h:773
FixedArray(const FixedArray< TYPE, true > &rhs)
copy constructor
Definition fixedarray.h:220
IndexT FindIndex(const TYPE &val) const
find index of identical element in unsorted array (slow)
Definition fixedarray.h:659
void operator=(FixedArray< TYPE, StackAlloc > &&rhs) noexcept
move assignment operator
Definition fixedarray.h:410
bool operator!=(const FixedArray< TYPE, StackAlloc > &rhs) const
inequality operator
Definition fixedarray.h:466
void Clear()
clear the array, free elements
Definition fixedarray.h:561
ComponentId * Iterator
Definition fixedarray.h:23
FixedArray()
default constructor
Definition fixedarray.h:117
FixedArray(std::initializer_list< TYPE > list)
constructor from initializer list
Definition fixedarray.h:357
bool IsEmpty() const
return true if array if empty (has no elements)
Definition fixedarray.h:552
void Fill(IndexT first, SizeT num, const TYPE &val)
fill array range with element
Definition fixedarray.h:607
FixedArray(const Array< TYPE > &rhs)
construct from array
Definition fixedarray.h:268
void Resize(SizeT newSize)
resize array without deleting existing content
Definition fixedarray.h:485
void Reset()
Reset the size and destroy all elements.
Definition fixedarray.h:570
void SetSize(SizeT s)
set number of elements (clears existing content)
Definition fixedarray.h:475
~FixedArray()
destructor
Definition fixedarray.h:388
ComponentId * elements
Definition fixedarray.h:109
void Copy(const FixedArray< TYPE, StackAlloc > &src)
copy content
Definition fixedarray.h:175
friend class FixedArray
Definition fixedarray.h:99
void Alloc(SizeT s)
allocate array for given size
Definition fixedarray.h:151
FixedArray(const SizeT s, const TYPE &initialValue)
constructor with size and initial value
Definition fixedarray.h:208
FixedArray(std::nullptr_t)
construct an empty fixed array
Definition fixedarray.h:378
SizeT count
Definition fixedarray.h:108
FixedArray(Array< TYPE > &&rhs)
move from array
Definition fixedarray.h:292
Iterator begin() const
for range-based iteration (C++11)
Definition fixedarray.h:755
void Sort()
sort the array
Definition fixedarray.h:676
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:134
TYPE * ArrayAllocStack(size_t size)
Definition memory.h:87
void ArrayFree(size_t size, TYPE *buffer)
Definition memory.h:117
TYPE * ArrayAlloc(size_t size)
Definition memory.h:69
__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 pinned array is an array which manages its own virtual memory.
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