![]() |
R-Type
2
Doom but in better
|
A container that provides sparse storage for optional components. More...
#include <SparseArray.hpp>
Public Types | |
using | value_type = std::optional<Component> |
Type aliases for convenience. | |
using | reference_type = value_type& |
using | const_reference_type = const value_type& |
using | container_t = std::vector<value_type, Allocator> |
using | size_type = typename container_t::size_type |
using | iterator = typename container_t::iterator |
using | const_iterator = typename container_t::const_iterator |
Public Member Functions | |
SparseArray ()=default | |
Default constructor. | |
SparseArray (const SparseArray &other)=default | |
Copy constructor. | |
SparseArray (SparseArray &&other) noexcept=default | |
Move constructor. | |
~SparseArray ()=default | |
Destructor. | |
SparseArray & | operator= (const SparseArray &other)=default |
Copy assignment operator. | |
SparseArray & | operator= (SparseArray &&other) noexcept=default |
Move assignment operator. | |
reference_type | operator[] (std::size_t idx) |
Accesses the value at the given index. | |
const_reference_type | operator[] (std::size_t idx) const |
Accesses the value at the given index (const version). | |
iterator | begin () |
Returns an iterator to the beginning of the array. | |
const_iterator | begin () const |
Returns a const iterator to the beginning of the array. | |
const_iterator | cbegin () const |
Returns a const iterator to the beginning of the array. | |
iterator | end () |
Returns an iterator to the end of the array. | |
const_iterator | end () const |
Returns a const iterator to the end of the array. | |
const_iterator | cend () const |
Returns a const iterator to the end of the array. | |
size_type | size () const |
Returns the size of the array. | |
reference_type | insert_at (size_type pos, const Component &component) |
Inserts a component at a specific position. | |
reference_type | insert_at (size_type pos, Component &&component) |
Inserts a component at a specific position (move version). | |
template<class... Params> | |
reference_type | emplace_at (size_type pos, Params &&... params) |
Constructs and inserts a component at a specific position. | |
void | erase (size_type pos) |
Removes the component at a specific position. | |
A container that provides sparse storage for optional components.
The SparseArray
class is designed for efficient storage of components where not all indices are occupied, allowing components to be stored sparsely with optional values.
Component | The type of the components stored in the array. |
Allocator | The allocator type used for memory management (defaults to std::allocator<Component> ). |
Definition at line 19 of file SparseArray.hpp.
using SparseArray< Component, Allocator >::const_iterator = typename container_t::const_iterator |
Const iterator type.
Definition at line 28 of file SparseArray.hpp.
using SparseArray< Component, Allocator >::const_reference_type = const value_type& |
Const reference type to a value in the array.
Definition at line 24 of file SparseArray.hpp.
using SparseArray< Component, Allocator >::container_t = std::vector<value_type, Allocator> |
Internal storage container type.
Definition at line 25 of file SparseArray.hpp.
using SparseArray< Component, Allocator >::iterator = typename container_t::iterator |
Iterator type.
Definition at line 27 of file SparseArray.hpp.
using SparseArray< Component, Allocator >::reference_type = value_type& |
Reference type to a value in the array.
Definition at line 23 of file SparseArray.hpp.
using SparseArray< Component, Allocator >::size_type = typename container_t::size_type |
Size type for the container.
Definition at line 26 of file SparseArray.hpp.
using SparseArray< Component, Allocator >::value_type = std::optional<Component> |
Type aliases for convenience.
The type of value stored, wrapped in an std::optional
.
Definition at line 22 of file SparseArray.hpp.
|
default |
Default constructor.
|
default |
Copy constructor.
other | The SparseArray to copy from. |
|
defaultnoexcept |
Move constructor.
other | The SparseArray to move from. |
|
default |
Destructor.
|
inline |
Returns an iterator to the beginning of the array.
Definition at line 97 of file SparseArray.hpp.
|
inline |
Returns a const iterator to the beginning of the array.
Definition at line 106 of file SparseArray.hpp.
|
inline |
Returns a const iterator to the beginning of the array.
Definition at line 115 of file SparseArray.hpp.
|
inline |
Returns a const iterator to the end of the array.
Definition at line 142 of file SparseArray.hpp.
|
inline |
Constructs and inserts a component at a specific position.
Params | The types of the parameters for the component constructor. |
pos | The position to insert the component at. |
params | The parameters for constructing the component. |
Definition at line 190 of file SparseArray.hpp.
|
inline |
Returns an iterator to the end of the array.
Definition at line 124 of file SparseArray.hpp.
|
inline |
Returns a const iterator to the end of the array.
Definition at line 133 of file SparseArray.hpp.
|
inline |
Removes the component at a specific position.
pos | The position of the component to erase. |
Definition at line 203 of file SparseArray.hpp.
|
inline |
Inserts a component at a specific position (move version).
pos | The position to insert the component at. |
component | The component to insert (moved). |
Definition at line 175 of file SparseArray.hpp.
|
inline |
Inserts a component at a specific position.
pos | The position to insert the component at. |
component | The component to insert. |
Definition at line 162 of file SparseArray.hpp.
|
default |
Copy assignment operator.
other | The SparseArray to copy from. |
SparseArray
.
|
defaultnoexcept |
Move assignment operator.
other | The SparseArray to move from. |
SparseArray
.
|
inline |
Accesses the value at the given index.
idx | The index to access. |
Definition at line 76 of file SparseArray.hpp.
|
inline |
Accesses the value at the given index (const version).
idx | The index to access. |
Definition at line 87 of file SparseArray.hpp.
|
inline |
Returns the size of the array.
Definition at line 151 of file SparseArray.hpp.