R-Type
Public Types | Public Member Functions | List of all members
SparseArray< Component > Class Template Reference

Array which can have empty indexes. More...

#include <SparseArray.hpp>

Public Types

using valueType = std::optional< Component >
 Type of the array wrap in an optional. More...
 
using referenceType = valueType &
 Reference to valueType. More...
 
using constReferenceType = const valueType &
 Constant reference to valueType. More...
 
using container = std::vector< valueType >
 Type of the container, which is a a vector storing a valueType. More...
 
using sizeType = typename container::size_type
 Type of the size of the container. More...
 
using iterator = typename container::iterator
 Type of the container's iterator. More...
 
using constIterator = typename container::const_iterator
 Constant type of the container's iterator. More...
 

Public Member Functions

 SparseArray ()
 SparseArray's constructor. More...
 
 SparseArray (const SparseArray &sparseArray)
 Copy constructor for the SparseArray. More...
 
 ~SparseArray ()=default
 
SparseArrayoperator= (const SparseArray &sparseArray)
 Overload for the copy assignement operator. More...
 
SparseArrayoperator= (SparseArray &&sparseArray) noexcept
 Overload for the move assignment operator. More...
 
referenceType operator[] (std::size_t idx)
 Overload for the bracket operator. More...
 
constReferenceType operator[] (std::size_t idx) const
 Overload for the bracket operator. More...
 
iterator begin ()
 Getter for the begin iterator. More...
 
constIterator begin () const
 Getter for the begin iterator. More...
 
constIterator cbegin () const
 Getter for the begin iterator. More...
 
iterator end ()
 Getter for the end iterator. More...
 
constIterator end () const
 Getter for the end iterator. More...
 
constIterator cend () const
 Getter for the end iterator. More...
 
sizeType size () const
 Getter for the array's size. More...
 
referenceType insert_at (sizeType pos, const Component &component)
 Insert a copy of the component at the position specified. Will resize the array if the position is bigger than the size of the array. More...
 
referenceType insert_at (sizeType pos, Component &&component)
 Insert the component at the position specified, the component will be moved in. Will resize the array if the position is bigger than the size of the array. More...
 
referenceType emplace_at (sizeType pos)
 Creates the component at the specified position. More...
 
template<class... Params>
referenceType emplace_at (sizeType pos, Params &&...params)
 Creates components at the specified positions. More...
 
void erase (sizeType pos)
 Removes the component at the specified position. More...
 
sizeType getIndex (const valueType &val) const
 Getter for the index of the component given. The component needs to be in the array. More...
 
void resize (const std::size_t &count)
 Resize the array. More...
 

Detailed Description

template<typename Component>
class SparseArray< Component >

Array which can have empty indexes.

Template Parameters
ComponentType of the component in the array.

Member Typedef Documentation

◆ constIterator

template<typename Component >
using SparseArray< Component >::constIterator = typename container::const_iterator

Constant type of the container's iterator.

◆ constReferenceType

template<typename Component >
using SparseArray< Component >::constReferenceType = const valueType &

Constant reference to valueType.

◆ container

template<typename Component >
using SparseArray< Component >::container = std::vector<valueType>

Type of the container, which is a a vector storing a valueType.

◆ iterator

template<typename Component >
using SparseArray< Component >::iterator = typename container::iterator

Type of the container's iterator.

◆ referenceType

template<typename Component >
using SparseArray< Component >::referenceType = valueType &

Reference to valueType.

◆ sizeType

template<typename Component >
using SparseArray< Component >::sizeType = typename container::size_type

Type of the size of the container.

◆ valueType

template<typename Component >
using SparseArray< Component >::valueType = std::optional<Component>

Type of the array wrap in an optional.

Constructor & Destructor Documentation

◆ SparseArray() [1/2]

template<typename Component >
SparseArray< Component >::SparseArray ( )
inline

SparseArray's constructor.

◆ SparseArray() [2/2]

template<typename Component >
SparseArray< Component >::SparseArray ( const SparseArray< Component > &  sparseArray)
inline

Copy constructor for the SparseArray.

Parameters
sparseArraySparseArray to copy.

◆ ~SparseArray()

template<typename Component >
SparseArray< Component >::~SparseArray ( )
default

Member Function Documentation

◆ begin() [1/2]

template<typename Component >
iterator SparseArray< Component >::begin ( )
inline

Getter for the begin iterator.

Returns
An iterator at the begining of the array.

◆ begin() [2/2]

template<typename Component >
constIterator SparseArray< Component >::begin ( ) const
inline

Getter for the begin iterator.

Returns
A constant iterator at the begining of the array.

◆ cbegin()

template<typename Component >
constIterator SparseArray< Component >::cbegin ( ) const
inline

Getter for the begin iterator.

Returns
A constant iterator at the begining of the array.

◆ cend()

template<typename Component >
constIterator SparseArray< Component >::cend ( ) const
inline

Getter for the end iterator.

Returns
A constant iterator at the end of the array.

◆ emplace_at() [1/2]

template<typename Component >
referenceType SparseArray< Component >::emplace_at ( sizeType  pos)
inline

Creates the component at the specified position.

Parameters
posPosition to create the component at.
Returns
A reference to the created component.

◆ emplace_at() [2/2]

template<typename Component >
template<class... Params>
referenceType SparseArray< Component >::emplace_at ( sizeType  pos,
Params &&...  params 
)
inline

Creates components at the specified positions.

Template Parameters
...ParamsVariadic template of the type of the positions
Parameters
posFirst position to create the component.
...paramsVariadic parameter of the positions to insert at.
Returns
A reference to the first component created.

◆ end() [1/2]

template<typename Component >
iterator SparseArray< Component >::end ( )
inline

Getter for the end iterator.

Returns
An iterator at the end of the array.

◆ end() [2/2]

template<typename Component >
constIterator SparseArray< Component >::end ( ) const
inline

Getter for the end iterator.

Returns
A constant iterator at the end of the array.

◆ erase()

template<typename Component >
void SparseArray< Component >::erase ( sizeType  pos)
inline

Removes the component at the specified position.

Parameters
posPosition at which to remove the component.

◆ getIndex()

template<typename Component >
sizeType SparseArray< Component >::getIndex ( const valueType val) const
inline

Getter for the index of the component given. The component needs to be in the array.

Parameters
valComponent from which to get the index.
Returns
The index of the component.

◆ insert_at() [1/2]

template<typename Component >
referenceType SparseArray< Component >::insert_at ( sizeType  pos,
Component &&  component 
)
inline

Insert the component at the position specified, the component will be moved in. Will resize the array if the position is bigger than the size of the array.

Parameters
posPosition to insert the component at.
componentMoved component to insert.
Returns
A reference to the inserted component.

◆ insert_at() [2/2]

template<typename Component >
referenceType SparseArray< Component >::insert_at ( sizeType  pos,
const Component &  component 
)
inline

Insert a copy of the component at the position specified. Will resize the array if the position is bigger than the size of the array.

Parameters
posPosition to insert the component at.
componentCopy of the component to insert.
Returns
A reference to the inserted component.

◆ operator=() [1/2]

template<typename Component >
SparseArray& SparseArray< Component >::operator= ( const SparseArray< Component > &  sparseArray)
inline

Overload for the copy assignement operator.

Parameters
sparseArraySparseArray to copy.
Returns
A reference to the SparseArray.

◆ operator=() [2/2]

template<typename Component >
SparseArray& SparseArray< Component >::operator= ( SparseArray< Component > &&  sparseArray)
inlinenoexcept

Overload for the move assignment operator.

Parameters
sparseArraySparseArray to move.
Returns
A reference to the SparseArray.

◆ operator[]() [1/2]

template<typename Component >
referenceType SparseArray< Component >::operator[] ( std::size_t  idx)
inline

Overload for the bracket operator.

Parameters
idxIndex to get the value at.
Returns
Reference to the value at the index.

◆ operator[]() [2/2]

template<typename Component >
constReferenceType SparseArray< Component >::operator[] ( std::size_t  idx) const
inline

Overload for the bracket operator.

Parameters
idxIndex to get the value at.
Returns
Constant reference to the value at the index.

◆ resize()

template<typename Component >
void SparseArray< Component >::resize ( const std::size_t &  count)
inline

Resize the array.

Parameters
countSize to resize the array.

◆ size()

template<typename Component >
sizeType SparseArray< Component >::size ( ) const
inline

Getter for the array's size.

Returns
The size of the array.

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