Uranus  1.0.1.0
Uranus is a GameEngine written in C++
Loading...
Searching...
No Matches
uranus::ecs::SparseArray< Component > Class Template Reference

SparseArray class, used to store components in a sparse way. More...

#include <SparseArray.hpp>

Collaboration diagram for uranus::ecs::SparseArray< Component >:
[legend]

Public Types

using ConstIterator = typename Container::const_iterator
 
using ConstReferenceType = const ValueType &
 
using Container = std::vector< ValueType >
 
using Iterator = typename Container::iterator
 
using ReferenceType = ValueType &
 
using SizeType = typename Container::size_type
 
using ValueType = std::shared_ptr< std::optional< Component > >
 

Public Member Functions

 SparseArray ()=default
 Default constructor.
 
 SparseArray (const SparseArray &)=default
 Default copy constructor. More...
 
 SparseArray (SparseArray &&) noexcept=default
 Default move constructor. More...
 
 ~SparseArray ()=default
 Default destructor.
 
Iterator begin ()
 Return the iterator pointing to the beginning of the SparseArray. More...
 
ConstIterator begin () const
 Return the const_iterator pointing to the beginning of the SparseArray. More...
 
ConstIterator cbegin () const
 Return the const_iterator pointing to the beginning of the SparseArray. More...
 
ConstIterator cend () const
 Return the const_iterator pointing to the end of the SparseArray. More...
 
template<class... Params>
ReferenceType emplaceAt (SizeType pos, Params &&...params)
 Emplace a component at the given index. More...
 
Iterator end ()
 Return the iterator pointing to the end of the SparseArray. More...
 
ConstIterator end () const
 Return the const_iterator pointing to the end of the SparseArray. More...
 
void erase (SizeType pos)
 Erase the component at the given index. More...
 
Container & getData () const
 Get the _data container. More...
 
std::optional< SizeType > getIndex (const ValueType &) const
 Get the index of the entity possessing the given component. More...
 
ReferenceType insertAt (SizeType pos, Component &&)
 Insert a component at the given index. More...
 
ReferenceType insertAt (SizeType pos, const Component &)
 Insert a component at the given index. More...
 
SparseArrayoperator= (const SparseArray &)
 Copy assignment operator. More...
 
SparseArrayoperator= (SparseArray &&) noexcept
 Move assignment operator. More...
 
ReferenceType operator[] (std::size_t idx)
 Access the component at the given index, if it exists, otherwise resize the SparseArray. More...
 
ConstReferenceType operator[] (std::size_t idx) const
 Access the component at the given index, if it exists, otherwise return nullptr. More...
 
SizeType size () const
 Return the size of the SparseArray. More...
 

Private Attributes

Container _data
 Container of the components.
 

Detailed Description

template<typename Component>
class uranus::ecs::SparseArray< Component >

SparseArray class, used to store components in a sparse way.

Template Parameters
ComponentType of the component to store

Constructor & Destructor Documentation

◆ SparseArray() [1/2]

template<typename Component >
uranus::ecs::SparseArray< Component >::SparseArray ( const SparseArray< Component > &  )
default

Default copy constructor.

Parameters
otherSparseArray to copy

◆ SparseArray() [2/2]

template<typename Component >
uranus::ecs::SparseArray< Component >::SparseArray ( SparseArray< Component > &&  )
defaultnoexcept

Default move constructor.

Parameters
otherSparseArray to move

Member Function Documentation

◆ begin() [1/2]

template<typename Component >
SparseArray< Component >::Iterator uranus::ecs::SparseArray< Component >::begin

Return the iterator pointing to the beginning of the SparseArray.

Template Parameters
ComponentType of the component
Returns
Iterator pointing to the beginning of the SparseArray

◆ begin() [2/2]

template<typename Component >
SparseArray< Component >::ConstIterator uranus::ecs::SparseArray< Component >::begin

Return the const_iterator pointing to the beginning of the SparseArray.

Template Parameters
ComponentType of the component
Returns
ConstIterator pointing to the beginning of the SparseArray

◆ cbegin()

template<typename Component >
SparseArray< Component >::ConstIterator uranus::ecs::SparseArray< Component >::cbegin

Return the const_iterator pointing to the beginning of the SparseArray.

Template Parameters
ComponentType of the component
Returns
ConstIterator pointing to the beginning of the SparseArray

◆ cend()

template<typename Component >
SparseArray< Component >::ConstIterator uranus::ecs::SparseArray< Component >::cend

Return the const_iterator pointing to the end of the SparseArray.

Template Parameters
ComponentType of the component
Returns
ConstIterator pointing to the end of the SparseArray

◆ emplaceAt()

template<typename Component >
template<class... Params>
SparseArray< Component >::ReferenceType uranus::ecs::SparseArray< Component >::emplaceAt ( SizeType  pos,
Params &&...  params 
)

Emplace a component at the given index.

Template Parameters
ParamsTypes of the parameters to construct the component
Parameters
posIndex to emplace the component
paramsParameters to construct the component
Returns
Reference to the inserted component
Note
The component is constructed in place or moved into the SparseArray

◆ end() [1/2]

template<typename Component >
SparseArray< Component >::Iterator uranus::ecs::SparseArray< Component >::end

Return the iterator pointing to the end of the SparseArray.

Template Parameters
ComponentType of the component
Returns
Iterator pointing to the end of the SparseArray

◆ end() [2/2]

template<typename Component >
SparseArray< Component >::ConstIterator uranus::ecs::SparseArray< Component >::end

Return the const_iterator pointing to the end of the SparseArray.

Template Parameters
ComponentType of the component
Returns
ConstIterator pointing to the end of the SparseArray

◆ erase()

template<typename Component >
void uranus::ecs::SparseArray< Component >::erase ( SizeType  pos)

Erase the component at the given index.

Template Parameters
ComponentType of the component
Parameters
posIndex of the component to erase

◆ getData()

template<typename Component >
SparseArray< Component >::Container & uranus::ecs::SparseArray< Component >::getData

Get the _data container.

Returns
Reference to the _data container

◆ getIndex()

template<typename Component >
std::optional< typename SparseArray< Component >::SizeType > uranus::ecs::SparseArray< Component >::getIndex ( const ValueType &  ptr) const

Get the index of the entity possessing the given component.

Template Parameters
ComponentType of the component
Parameters
ptrPointer to the component
Returns
Optional containing the index of the entity possessing the given component or nullopt if the component is not found

◆ insertAt() [1/2]

template<typename Component >
SparseArray< Component >::ReferenceType uranus::ecs::SparseArray< Component >::insertAt ( SizeType  pos,
Component &&  component 
)

Insert a component at the given index.

Template Parameters
ComponentType of the component
Parameters
posIndex to insert the component
componentComponent to insert
Returns
Reference to the inserted component
Note
The component is moved

◆ insertAt() [2/2]

template<typename Component >
SparseArray< Component >::ReferenceType uranus::ecs::SparseArray< Component >::insertAt ( SizeType  pos,
const Component &  component 
)

Insert a component at the given index.

Template Parameters
ComponentType of the component
Parameters
posIndex to insert the component
componentComponent to insert
Returns
Reference to the inserted component

◆ operator=() [1/2]

template<typename Component >
SparseArray< Component > & uranus::ecs::SparseArray< Component >::operator= ( const SparseArray< Component > &  other)

Copy assignment operator.

Template Parameters
ComponentType of the component
Parameters
otherSparseArray to copy
Returns
Reference to the current SparseArray

◆ operator=() [2/2]

template<typename Component >
SparseArray< Component > & uranus::ecs::SparseArray< Component >::operator= ( SparseArray< Component > &&  other)
noexcept

Move assignment operator.

Template Parameters
ComponentType of the component
Parameters
otherSparseArray to move
Returns
Reference to the current SparseArray

◆ operator[]() [1/2]

template<typename Component >
SparseArray< Component >::ReferenceType uranus::ecs::SparseArray< Component >::operator[] ( std::size_t  idx)

Access the component at the given index, if it exists, otherwise resize the SparseArray.

Template Parameters
ComponentType of the component
Parameters
idxIndex to get the component
Returns
Reference to the component

◆ operator[]() [2/2]

template<typename Component >
SparseArray< Component >::ConstReferenceType uranus::ecs::SparseArray< Component >::operator[] ( std::size_t  idx) const

Access the component at the given index, if it exists, otherwise return nullptr.

Template Parameters
ComponentType of the component
Parameters
idxIndex to get the component
Returns
Reference to the component if it exists, nullptr otherwise

◆ size()

template<typename Component >
SparseArray< Component >::SizeType uranus::ecs::SparseArray< Component >::size

Return the size of the SparseArray.

Template Parameters
ComponentType of the component
Returns
Size of the SparseArray

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