R-Type  2
Doom but in better
Loading...
Searching...
No Matches
DenseArray< Component, Allocator > Class Template Reference

A container that provides dense storage for components with a mapping between entity IDs and component indices. More...

#include <DenseArray.hpp>

Collaboration diagram for DenseArray< Component, Allocator >:
Collaboration graph

Public Types

using value_type = Component
 Type aliases for convenience.
 
using optional_t = std::optional<Component>
 
using reference_type = optional_t&
 
using const_reference_type = const optional_t&
 
using id_type = std::size_t
 
using id_container_t = std::vector<id_type>
 
using component_container_t = std::vector<optional_t, Allocator>
 
using size_type = typename component_container_t::size_type
 
using iterator = typename component_container_t::iterator
 
using const_iterator = typename component_container_t::const_iterator
 

Public Member Functions

 DenseArray ()=default
 Default constructor.
 
 DenseArray (const DenseArray &other)=default
 Copy constructor.
 
 DenseArray (DenseArray &&other) noexcept=default
 Move constructor.
 
 ~DenseArray ()=default
 Destructor.
 
DenseArrayoperator= (const DenseArray &other)=default
 Copy assignment operator.
 
DenseArrayoperator= (DenseArray &&other) noexcept=default
 Move assignment operator.
 
reference_type operator[] (size_type idx)
 Accesses the component at the given index.
 
const_reference_type operator[] (size_type idx) const
 Accesses the component at the given index (const version).
 
iterator begin ()
 Returns an iterator to the beginning of the component container.
 
const_iterator begin () const
 Returns a const iterator to the beginning of the component container.
 
const_iterator cbegin () const
 Returns a const iterator to the beginning of the component container.
 
iterator end ()
 Returns an iterator to the end of the component container.
 
const_iterator end () const
 Returns a const iterator to the end of the component container.
 
const_iterator cend () const
 Returns a const iterator to the end of the component container.
 
size_type size () const
 Returns the number of components stored in the array.
 
void insert_at (size_type id, const Component &component)
 Inserts a component at a specific ID.
 
void insert_at (size_type id, Component &&component)
 Inserts a component at a specific ID (move version).
 
template<typename... Params>
void emplace_at (size_type id, Params &&... params)
 Constructs and inserts a component at a specific ID.
 
void erase (size_type id)
 Removes the component at a specific ID.
 

Detailed Description

template<typename Component, typename Allocator = std::allocator<Component>>
class DenseArray< Component, Allocator >

A container that provides dense storage for components with a mapping between entity IDs and component indices.

The DenseArray class is designed for efficient storage and retrieval of components in an ECS (Entity-Component-System) architecture. It maintains a mapping between entity IDs and component indices to support fast lookups and iteration.

Template Parameters
ComponentThe type of the components stored in the array.
AllocatorThe allocator type used for memory management (defaults to std::allocator<Component>).

Definition at line 20 of file DenseArray.hpp.

Member Typedef Documentation

◆ component_container_t

template<typename Component , typename Allocator = std::allocator<Component>>
using DenseArray< Component, Allocator >::component_container_t = std::vector<optional_t, Allocator>

Container type for storing components.

Definition at line 29 of file DenseArray.hpp.

◆ const_iterator

template<typename Component , typename Allocator = std::allocator<Component>>
using DenseArray< Component, Allocator >::const_iterator = typename component_container_t::const_iterator

Const iterator type.

Definition at line 32 of file DenseArray.hpp.

◆ const_reference_type

template<typename Component , typename Allocator = std::allocator<Component>>
using DenseArray< Component, Allocator >::const_reference_type = const optional_t&

Const reference to a component.

Definition at line 26 of file DenseArray.hpp.

◆ id_container_t

template<typename Component , typename Allocator = std::allocator<Component>>
using DenseArray< Component, Allocator >::id_container_t = std::vector<id_type>

Container type for storing entity IDs.

Definition at line 28 of file DenseArray.hpp.

◆ id_type

template<typename Component , typename Allocator = std::allocator<Component>>
using DenseArray< Component, Allocator >::id_type = std::size_t

Type used for entity IDs.

Definition at line 27 of file DenseArray.hpp.

◆ iterator

template<typename Component , typename Allocator = std::allocator<Component>>
using DenseArray< Component, Allocator >::iterator = typename component_container_t::iterator

Iterator type.

Definition at line 31 of file DenseArray.hpp.

◆ optional_t

template<typename Component , typename Allocator = std::allocator<Component>>
using DenseArray< Component, Allocator >::optional_t = std::optional<Component>

Optional type for components.

Definition at line 24 of file DenseArray.hpp.

◆ reference_type

template<typename Component , typename Allocator = std::allocator<Component>>
using DenseArray< Component, Allocator >::reference_type = optional_t&

Reference to a component.

Definition at line 25 of file DenseArray.hpp.

◆ size_type

template<typename Component , typename Allocator = std::allocator<Component>>
using DenseArray< Component, Allocator >::size_type = typename component_container_t::size_type

Size type for the container.

Definition at line 30 of file DenseArray.hpp.

◆ value_type

template<typename Component , typename Allocator = std::allocator<Component>>
using DenseArray< Component, Allocator >::value_type = Component

Type aliases for convenience.

The type of component stored.

Definition at line 23 of file DenseArray.hpp.

Constructor & Destructor Documentation

◆ DenseArray() [1/3]

template<typename Component , typename Allocator = std::allocator<Component>>
DenseArray< Component, Allocator >::DenseArray ( )
default

Default constructor.

◆ DenseArray() [2/3]

template<typename Component , typename Allocator = std::allocator<Component>>
DenseArray< Component, Allocator >::DenseArray ( const DenseArray< Component, Allocator > & other)
default

Copy constructor.

Parameters
otherThe DenseArray to copy from.

◆ DenseArray() [3/3]

template<typename Component , typename Allocator = std::allocator<Component>>
DenseArray< Component, Allocator >::DenseArray ( DenseArray< Component, Allocator > && other)
defaultnoexcept

Move constructor.

Parameters
otherThe DenseArray to move from.

◆ ~DenseArray()

template<typename Component , typename Allocator = std::allocator<Component>>
DenseArray< Component, Allocator >::~DenseArray ( )
default

Destructor.

Member Function Documentation

◆ begin() [1/2]

template<typename Component , typename Allocator = std::allocator<Component>>
iterator DenseArray< Component, Allocator >::begin ( )
inline

Returns an iterator to the beginning of the component container.

Returns
An iterator to the first component.

Definition at line 100 of file DenseArray.hpp.

◆ begin() [2/2]

template<typename Component , typename Allocator = std::allocator<Component>>
const_iterator DenseArray< Component, Allocator >::begin ( ) const
inline

Returns a const iterator to the beginning of the component container.

Returns
A const iterator to the first component.

Definition at line 109 of file DenseArray.hpp.

◆ cbegin()

template<typename Component , typename Allocator = std::allocator<Component>>
const_iterator DenseArray< Component, Allocator >::cbegin ( ) const
inline

Returns a const iterator to the beginning of the component container.

Returns
A const iterator to the first component.

Definition at line 118 of file DenseArray.hpp.

◆ cend()

template<typename Component , typename Allocator = std::allocator<Component>>
const_iterator DenseArray< Component, Allocator >::cend ( ) const
inline

Returns a const iterator to the end of the component container.

Returns
A const iterator to one past the last component.

Definition at line 145 of file DenseArray.hpp.

◆ emplace_at()

template<typename Component , typename Allocator = std::allocator<Component>>
template<typename... Params>
void DenseArray< Component, Allocator >::emplace_at ( size_type id,
Params &&... params )
inline

Constructs and inserts a component at a specific ID.

Template Parameters
ParamsThe types of the parameters for the component constructor.
Parameters
idThe ID where the component should be inserted.
paramsThe parameters for constructing the component.

Definition at line 190 of file DenseArray.hpp.

◆ end() [1/2]

template<typename Component , typename Allocator = std::allocator<Component>>
iterator DenseArray< Component, Allocator >::end ( )
inline

Returns an iterator to the end of the component container.

Returns
An iterator to one past the last component.

Definition at line 127 of file DenseArray.hpp.

◆ end() [2/2]

template<typename Component , typename Allocator = std::allocator<Component>>
const_iterator DenseArray< Component, Allocator >::end ( ) const
inline

Returns a const iterator to the end of the component container.

Returns
A const iterator to one past the last component.

Definition at line 136 of file DenseArray.hpp.

◆ erase()

template<typename Component , typename Allocator = std::allocator<Component>>
void DenseArray< Component, Allocator >::erase ( size_type id)
inline

Removes the component at a specific ID.

Parameters
idThe ID of the component to erase.

Definition at line 201 of file DenseArray.hpp.

◆ insert_at() [1/2]

template<typename Component , typename Allocator = std::allocator<Component>>
void DenseArray< Component, Allocator >::insert_at ( size_type id,
Component && component )
inline

Inserts a component at a specific ID (move version).

Parameters
idThe ID where the component should be inserted.
componentThe component to insert (moved).

Definition at line 176 of file DenseArray.hpp.

◆ insert_at() [2/2]

template<typename Component , typename Allocator = std::allocator<Component>>
void DenseArray< Component, Allocator >::insert_at ( size_type id,
const Component & component )
inline

Inserts a component at a specific ID.

Parameters
idThe ID where the component should be inserted.
componentThe component to insert.

Definition at line 164 of file DenseArray.hpp.

◆ operator=() [1/2]

template<typename Component , typename Allocator = std::allocator<Component>>
DenseArray & DenseArray< Component, Allocator >::operator= ( const DenseArray< Component, Allocator > & other)
default

Copy assignment operator.

Parameters
otherThe DenseArray to copy from.
Returns
A reference to the current DenseArray.

◆ operator=() [2/2]

template<typename Component , typename Allocator = std::allocator<Component>>
DenseArray & DenseArray< Component, Allocator >::operator= ( DenseArray< Component, Allocator > && other)
defaultnoexcept

Move assignment operator.

Parameters
otherThe DenseArray to move from.
Returns
A reference to the current DenseArray.

◆ operator[]() [1/2]

template<typename Component , typename Allocator = std::allocator<Component>>
reference_type DenseArray< Component, Allocator >::operator[] ( size_type idx)
inline

Accesses the component at the given index.

Parameters
idxThe index to access.
Returns
A reference to the component at the specified index.

Definition at line 80 of file DenseArray.hpp.

◆ operator[]() [2/2]

template<typename Component , typename Allocator = std::allocator<Component>>
const_reference_type DenseArray< Component, Allocator >::operator[] ( size_type idx) const
inline

Accesses the component at the given index (const version).

Parameters
idxThe index to access.
Returns
A const reference to the component at the specified index.

Definition at line 91 of file DenseArray.hpp.

◆ size()

template<typename Component , typename Allocator = std::allocator<Component>>
size_type DenseArray< Component, Allocator >::size ( ) const
inline

Returns the number of components stored in the array.

Returns
The number of components.

Definition at line 154 of file DenseArray.hpp.


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