nCine 2022.04.r504-20bd01e
A cross-platform 2D game engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
nctl::StaticArray< T, C > Class Template Reference

A static array based on templates that stores elements in the stack. More...

#include <StaticArray.h>

Public Types

using Iterator = ArrayIterator< T, false >
 Iterator type.
 
using ConstIterator = ArrayIterator< T, true >
 Constant iterator type.
 
using ReverseIterator = nctl::ReverseIterator< Iterator >
 Reverse iterator type.
 
using ConstReverseIterator = nctl::ReverseIterator< ConstIterator >
 Reverse constant iterator type.
 

Public Member Functions

 StaticArray ()
 Constructs an empty array with fixed capacity.
 
 StaticArray (StaticArrayMode mode)
 Constructs an array with the option for it to have the size match its capacity.
 
 StaticArray (const StaticArray &other)
 Copy constructor.
 
 StaticArray (StaticArray &&other)
 Move constructor.
 
StaticArrayoperator= (const StaticArray &other)
 Assignment operator.
 
StaticArrayoperator= (StaticArray &&other)
 Move assignment operator.
 
Iterator begin ()
 Returns an iterator to the first element.
 
ReverseIterator rBegin ()
 Returns a reverse iterator to the last element.
 
Iterator end ()
 Returns an iterator to past the last element.
 
ReverseIterator rEnd ()
 Returns a reverse iterator to prior the first element.
 
ConstIterator begin () const
 Returns a constant iterator to the first element.
 
ConstReverseIterator rBegin () const
 Returns a constant reverse iterator to the last element.
 
ConstIterator end () const
 Returns a constant iterator to past the last lement.
 
ConstReverseIterator rEnd () const
 Returns a constant reverse iterator to prior the first element.
 
ConstIterator cBegin () const
 Returns a constant iterator to the first element.
 
ConstReverseIterator crBegin () const
 Returns a constant reverse iterator to the last element.
 
ConstIterator cEnd () const
 Returns a constant iterator to past the last lement.
 
ConstReverseIterator crEnd () const
 Returns a constant reverse iterator to prior the first element.
 
bool isEmpty () const
 Returns true if the array is empty.
 
unsigned int size () const
 Returns the array size.
 
unsigned int capacity () const
 Returns the array capacity.
 
void setSize (unsigned int newSize)
 Sets a new size for the array (allowing for "holes")
 
void clear ()
 Clears the array.
 
const T & front () const
 Returns a constant reference to the first element in constant time.
 
T & front ()
 Returns a reference to the first element in constant time.
 
const T & back () const
 Returns a constant reference to the last element in constant time.
 
T & back ()
 Returns a reference to the last element in constant time.
 
void pushBack (const T &element)
 Inserts a new element as the last one in constant time.
 
void pushBack (T &&element)
 Move inserts a new element as the last one in constant time.
 
template<typename... Args>
void emplaceBack (Args &&... args)
 Constructs a new element as the last one in constant time.
 
void popBack ()
 Removes the last element in constant time.
 
T * insertRange (unsigned int index, const T *firstPtr, const T *lastPtr)
 Inserts new elements at the specified position from a source range, last not included (shifting elements around)
 
T * insertAt (unsigned int index, const T &element)
 Inserts a new element at a specified position (shifting elements around)
 
T * insertAt (unsigned int index, T &&element)
 Move inserts a new element at a specified position (shifting elements around)
 
template<typename... Args>
T * emplaceAt (unsigned int index, Args &&... args)
 Constructs a new element at the position specified by the index.
 
Iterator insert (Iterator position, const T &value)
 Inserts a new element at the position specified by the iterator (shifting elements around)
 
Iterator insert (Iterator position, T &&value)
 Move inserts a new element at the position specified by the iterator (shifting elements around)
 
Iterator insert (Iterator position, Iterator first, Iterator last)
 Inserts new elements from a source at the position specified by the iterator (shifting elements around)
 
template<typename... Args>
Iterator emplace (Iterator position, Args &&... args)
 Constructs a new element at the position specified by the iterator.
 
T * removeRange (unsigned int firstIndex, unsigned int lastIndex)
 Removes the specified range of elements, last not included (shifting elements around)
 
Iterator removeAt (unsigned int index)
 Removes an element at a specified position (shifting elements around)
 
Iterator erase (Iterator position)
 Removes the element pointed by the iterator (shifting elements around)
 
Iterator erase (Iterator first, const Iterator last)
 Removes the elements in the range, last not included (shifting elements around)
 
T * unorderedRemoveRange (unsigned int firstIndex, unsigned int lastIndex)
 Removes the specified range of elements, last not included (moving tail elements in place)
 
Iterator unorderedRemoveAt (unsigned int index)
 Removes an element at a specified position (moving the last element in place)
 
Iterator unorderedErase (Iterator position)
 Removes the element pointed by the iterator (moving the last element in place)
 
Iterator unorderedErase (Iterator first, const Iterator last)
 Removes the elements in the range, last not included (moving tail elements in place)
 
const T & at (unsigned int index) const
 Read-only access to the specified element (with bounds checking)
 
T & at (unsigned int index)
 Access to the specified element (with bounds checking)
 
const T & operator[] (unsigned int index) const
 Read-only subscript operator.
 
T & operator[] (unsigned int index)
 Subscript operator.
 
const T * data () const
 Returns a constant pointer to the allocated memory.
 
T * data ()
 Returns a pointer to the allocated memory.
 

Detailed Description

template<class T, unsigned int C>
class nctl::StaticArray< T, C >

A static array based on templates that stores elements in the stack.

Member Function Documentation

◆ clear()

template<class T , unsigned int C>
void nctl::StaticArray< T, C >::clear ( )

Clears the array.

Size will be set to zero but capacity remains unmodified.

◆ size()

template<class T , unsigned int C>
unsigned int nctl::StaticArray< T, C >::size ( ) const
inline

Returns the array size.

The array is filled without gaps until the Size()-1 element.

◆ unorderedErase() [1/2]

template<class T , unsigned int C>
StaticArray< T, C >::Iterator nctl::StaticArray< T, C >::unorderedErase ( Iterator  first,
const Iterator  last 
)

Removes the elements in the range, last not included (moving tail elements in place)

Note
This method is faster than erase() but it will not preserve the array order

◆ unorderedErase() [2/2]

template<class T , unsigned int C>
StaticArray< T, C >::Iterator nctl::StaticArray< T, C >::unorderedErase ( Iterator  position)

Removes the element pointed by the iterator (moving the last element in place)

Note
This method is faster than erase() but it will not preserve the array order

◆ unorderedRemoveRange()

template<class T , unsigned int C>
T * nctl::StaticArray< T, C >::unorderedRemoveRange ( unsigned int  firstIndex,
unsigned int  lastIndex 
)

Removes the specified range of elements, last not included (moving tail elements in place)

Note
This method is faster than removeRange() but it will not preserve the array order

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