Nebula
Loading...
Searching...
No Matches
Util::TrivialArray< TYPE > Class Template Reference

#include <trivialarray.h>

Detailed Description

template<class TYPE>
class Util::TrivialArray< TYPE >

Array class based on Util::Array for trivial and POD types that avoids any per element copying and constructor/destructor calls.

Inherits Util::Array< TYPE, SMALL_VECTOR_SIZE >.

Public Types

typedef TYPE * Iterator
 define iterator
 
- Public Types inherited from Util::Array< TYPE, SMALL_VECTOR_SIZE >
typedef TYPE * Iterator
 define iterator
 
typedef const TYPE * ConstIterator
 
using ArrayT = Array<TYPE, SMALL_VECTOR_SIZE>
 

Public Member Functions

 TrivialArray ()
 constructor with default parameters
 
 TrivialArray (SizeT initialCapacity, SizeT initialGrow)
 constuctor with initial size and grow size
 
 TrivialArray (SizeT initialSize, SizeT initialGrow, const TYPE &initialValue)
 constructor with initial size, grow size and initial values
 
 TrivialArray (const TrivialArray< TYPE > &rhs)
 copy constructor
 
 TrivialArray (const Array< TYPE > &rhs)
 copy constructor from Array
 
 TrivialArray (std::initializer_list< TYPE > list)
 constructor from initializer list
 
 ~TrivialArray ()
 destructor
 
void operator= (const TrivialArray< TYPE > &rhs)
 assignment operator
 
void operator= (const Array< TYPE > &rhs)
 assignment operator from array
 
void EraseIndex (IndexT index)
 erase element at index, keep sorting intact
 
void EraseIndexSwap (IndexT index)
 erase element at index, fill gap by swapping in last element, destroys sorting!
 
void Clear ()
 clear array (calls destructors)
 
- Public Member Functions inherited from Util::Array< TYPE, SMALL_VECTOR_SIZE >
 Array ()
 constructor with default parameters
 
 Array (SizeT initialCapacity, SizeT initialGrow)
 constuctor with initial size and grow size
 
 Array (SizeT initialSize, SizeT initialGrow, const TYPE &initialValue)
 constructor with initial size, grow size and initial values
 
 Array (const ArrayT &rhs)
 copy constructor
 
 Array (ArrayT &&rhs) noexcept
 move constructor
 
 Array (std::initializer_list< TYPE > list)
 constructor from initializer list
 
 Array (std::nullptr_t)
 construct an empty fixed array
 
 Array (const TYPE *const buf, SizeT num)
 constructor from TYPE pointer and size.
 
 ~Array ()
 destructor
 
void operator= (const Array< TYPE, SMALL_VECTOR_SIZE > &rhs)
 assignment operator
 
void operator= (Array< TYPE, SMALL_VECTOR_SIZE > &&rhs) noexcept
 move operator
 
TYPE & operator[] (IndexT index) const
 [] operator
 
TYPE & operator[] (IndexT index)
 [] operator
 
bool operator== (const Array< TYPE, SMALL_VECTOR_SIZE > &rhs) const
 equality operator
 
bool operator!= (const Array< TYPE, SMALL_VECTOR_SIZE > &rhs) const
 inequality operator
 
template<typename T >
As () const
 convert to "anything"
 
TYPE & Get (IndexT index) const
 Get element (same as operator[] but as a function)
 
template<typename ... ELEM_TYPE>
void Append (const TYPE &first, const ELEM_TYPE &... elements)
 Append multiple elements to the end of the array.
 
void Append (const TYPE &elm)
 append element to end of array
 
void Append (TYPE &&elm)
 append an element which is being forwarded
 
void AppendArray (const Array< TYPE, SMALL_VECTOR_SIZE > &rhs)
 append the contents of an array to this array
 
void AppendArray (const TYPE *arr, const SizeT count)
 append from C array
 
TYPE & Emplace ()
 Emplace item (create new item and return reference)
 
TYPE * EmplaceArray (const SizeT count)
 Emplace range of items and return pointer to first.
 
void Reserve (SizeT num)
 increase capacity to fit N more elements into the array.
 
const SizeT Size () const
 get number of elements in array
 
const SizeT ByteSize () const
 return the byte size of the array.
 
const SizeT Capacity () const
 get overall allocated size of array in number of elements
 
TYPE & Front () const
 return reference to first element
 
TYPE & Back () const
 return reference to last element
 
bool IsEmpty () const
 return true if array empty
 
bool IsValidIndex (IndexT index) const
 check if index is valid
 
void EraseIndex (IndexT index)
 erase element at index, keep sorting intact
 
Iterator Erase (Iterator iter)
 erase element pointed to by iterator, keep sorting intact
 
void EraseIndexSwap (IndexT index)
 erase element at index, fill gap by swapping in last element, destroys sorting!
 
Iterator EraseSwap (Iterator iter)
 erase element at iterator, fill gap by swapping in last element, destroys sorting!
 
void EraseRange (IndexT start, IndexT end)
 erase range, excluding the element at end
 
void EraseBack ()
 erase back
 
void EraseFront ()
 erase front
 
TYPE PopFront ()
 Pop front.
 
TYPE PopBack ()
 Pop back.
 
void Insert (IndexT index, const TYPE &elm)
 insert element before element at index
 
IndexT InsertSorted (const TYPE &elm)
 insert element into sorted array, return index where element was included
 
IndexT InsertAtEndOfIdenticalRange (IndexT startIndex, const TYPE &elm)
 insert element at the first non-identical position, return index of inclusion position
 
bool IsSorted () const
 test if the array is sorted, this is a slow operation!
 
void Clear ()
 clear array (calls destructors)
 
void Reset ()
 reset array (does NOT call destructors)
 
void Free ()
 free memory and reset size
 
Iterator Begin () const
 return iterator to beginning of array
 
ConstIterator ConstBegin () const
 return const iterator to beginning of array
 
Iterator End () const
 return iterator to end of array
 
ConstIterator ConstEnd () const
 return const iterator to end of array
 
Iterator Find (const TYPE &elm, const IndexT start=0) const
 find identical element in array, return iterator
 
IndexT FindIndex (const TYPE &elm, const IndexT start=0) const
 find identical element in array, return index, InvalidIndex if not found
 
template<typename KEYTYPE >
IndexT FindIndex (typename std::enable_if< true, const KEYTYPE & >::type elm, const IndexT start=0) const
 find identical element using a specific key type
 
void Fill (IndexT first, SizeT num, const TYPE &elm)
 fill array range with element
 
void Realloc (SizeT capacity, SizeT grow)
 clear contents and preallocate with new attributes
 
ArrayT Difference (const Array< TYPE, SMALL_VECTOR_SIZE > &rhs)
 returns new array with elements which are not in rhs (slow!)
 
void Sort ()
 sort the array
 
void QuickSort ()
 quick sort the array
 
void SortWithFunc (bool(*func)(const TYPE &lhs, const TYPE &rhs))
 sort with custom function
 
void QuickSortWithFunc (int(*func)(const void *lhs, const void *rhs))
 quick sort the array
 
IndexT BinarySearchIndex (const TYPE &elm) const
 do a binary search, requires a sorted array
 
template<typename KEYTYPE >
IndexT BinarySearchIndex (typename std::enable_if< true, const KEYTYPE & >::type elm) const
 do a binary search using a specific key type
 
void Resize (SizeT num)
 Set size. Grows array if num is greater than capacity. Calls destroy on all objects at index > num!
 
template<typename ... ARGS>
void Resize (SizeT num, ARGS... args)
 Resize and fill new elements with arguments.
 
void Extend (SizeT num)
 Resize to fit the provided value, but don't shrink if the new size is smaller.
 
void Fit ()
 Fit the size of the array to the amount of elements.
 
constexpr SizeT TypeSize () const
 Returns sizeof(TYPE)
 
Iterator begin () const
 for range-based iteration
 
Iterator end () const
 
size_t size () const
 
void resize (size_t size)
 
void clear () noexcept
 
void push_back (const TYPE &item)
 
void Grow ()
 grow array with grow value
 

Private Member Functions

void Destroy (TYPE *elm)
 does nothing
 
void Copy (const TrivialArray< TYPE > &src)
 copy content
 
void Copy (const Array< TYPE > &src)
 copy content
 
void GrowTo (SizeT newCapacity)
 grow array to target size
 
void Move (IndexT fromIndex, IndexT toIndex)
 move elements, grows array if needed
 

Additional Inherited Members

- Protected Member Functions inherited from Util::Array< TYPE, SMALL_VECTOR_SIZE >
void Destroy (TYPE *elm)
 destroy an element (call destructor without freeing memory)
 
void Copy (const Array< TYPE, SMALL_VECTOR_SIZE > &src)
 copy content
 
void Delete ()
 delete content
 
void GrowTo (SizeT newCapacity)
 grow array to target size
 
void Move (IndexT fromIndex, IndexT toIndex)
 move elements, grows array if needed
 
void DestroyRange (IndexT fromIndex, IndexT toIndex)
 destroy range of elements
 
void CopyRange (TYPE *to, TYPE *from, SizeT num)
 copy range
 
void MoveRange (TYPE *to, TYPE *from, SizeT num)
 move range
 
- Protected Attributes inherited from Util::Array< TYPE, SMALL_VECTOR_SIZE >
SizeT grow
 
SizeT capacity
 
SizeT count
 
TYPE * elements
 
_smallvector< TYPE, SMALL_VECTOR_SIZE > stackElements
 
- Static Protected Attributes inherited from Util::Array< TYPE, SMALL_VECTOR_SIZE >
static const SizeT MinGrowSize = 16
 
static const SizeT MaxGrowSize = 65536
 

Member Typedef Documentation

◆ Iterator

template<class TYPE >
typedef TYPE* Util::TrivialArray< TYPE >::Iterator

define iterator

Constructor & Destructor Documentation

◆ TrivialArray() [1/6]

template<class TYPE >
Util::TrivialArray< TYPE >::TrivialArray ( )

constructor with default parameters

◆ TrivialArray() [2/6]

template<class TYPE >
Util::TrivialArray< TYPE >::TrivialArray ( SizeT initialCapacity,
SizeT initialGrow )

constuctor with initial size and grow size

◆ TrivialArray() [3/6]

template<class TYPE >
Util::TrivialArray< TYPE >::TrivialArray ( SizeT initialSize,
SizeT initialGrow,
const TYPE & initialValue )

constructor with initial size, grow size and initial values

◆ TrivialArray() [4/6]

template<class TYPE >
Util::TrivialArray< TYPE >::TrivialArray ( const TrivialArray< TYPE > & rhs)

copy constructor

◆ TrivialArray() [5/6]

template<class TYPE >
Util::TrivialArray< TYPE >::TrivialArray ( const Array< TYPE > & rhs)

copy constructor from Array

◆ TrivialArray() [6/6]

template<class TYPE >
Util::TrivialArray< TYPE >::TrivialArray ( std::initializer_list< TYPE > list)

constructor from initializer list

◆ ~TrivialArray()

template<class TYPE >
Util::TrivialArray< TYPE >::~TrivialArray ( )

destructor

Member Function Documentation

◆ Clear()

template<class TYPE >
void Util::TrivialArray< TYPE >::Clear ( )

clear array (calls destructors)

The current implementation of this method does not shrink the preallocated space.

It simply sets the array size to 0.

◆ Copy() [1/2]

template<class TYPE >
void Util::TrivialArray< TYPE >::Copy ( const Array< TYPE > & src)
private

copy content

◆ Copy() [2/2]

template<class TYPE >
void Util::TrivialArray< TYPE >::Copy ( const TrivialArray< TYPE > & src)
private

copy content

◆ Destroy()

template<class TYPE >
void Util::TrivialArray< TYPE >::Destroy ( TYPE * elm)
private

does nothing

◆ EraseIndex()

template<class TYPE >
void Util::TrivialArray< TYPE >::EraseIndex ( IndexT index)

erase element at index, keep sorting intact

◆ EraseIndexSwap()

template<class TYPE >
void Util::TrivialArray< TYPE >::EraseIndexSwap ( IndexT index)

erase element at index, fill gap by swapping in last element, destroys sorting!

NOTE: this method is fast but destroys the sorting order!

◆ GrowTo()

template<class TYPE >
void Util::TrivialArray< TYPE >::GrowTo ( SizeT newCapacity)
private

grow array to target size

◆ Move()

template<class TYPE >
void Util::TrivialArray< TYPE >::Move ( IndexT fromIndex,
IndexT toIndex )
private

move elements, grows array if needed

30-Jan-03 floh serious bugfixes! 07-Dec-04 jo bugfix: neededSize >= this->capacity => neededSize > capacity

◆ operator=() [1/2]

template<class TYPE >
void Util::TrivialArray< TYPE >::operator= ( const Array< TYPE > & rhs)

assignment operator from array

◆ operator=() [2/2]

template<class TYPE >
void Util::TrivialArray< TYPE >::operator= ( const TrivialArray< TYPE > & rhs)

assignment operator


The documentation for this class was generated from the following file: