19template <
typename Component,
typename Allocator = std::allocator<Component>>
30 using size_type =
typename component_container_t::size_type;
31 using iterator =
typename component_container_t::iterator;
81 assert(idx < _components.size() &&
"Index out of bounds");
82 return _components[idx];
92 return _components[idx];
101 return _components.begin();
110 return _components.begin();
119 return _components.cbegin();
128 return _components.end();
137 return _components.end();
146 return _components.cend();
155 return _components.size();
167 _components.push_back(component);
179 _components[id] = std::move(component);
189 template <
typename... Params>
193 _components.emplace_back(std::forward<Params>(params)...);
202 _ids.erase(_ids.begin() +
id);
203 _components.erase(_components.begin() +
id);
213 if (pos >= _components.size()) {
214 _ids.resize(pos + 1);
215 _components.resize(pos + 1);
221 Allocator _allocator;
A container that provides dense storage for components with a mapping between entity IDs and componen...
void insert_at(size_type id, const Component &component)
Inserts a component at a specific ID.
DenseArray(const DenseArray &other)=default
Copy constructor.
DenseArray()=default
Default constructor.
const_iterator end() const
Returns a const iterator to the end of the component container.
typename component_container_t::iterator iterator
Component value_type
Type aliases for convenience.
iterator end()
Returns an iterator to the end of the component container.
iterator begin()
Returns an iterator to the beginning of the component container.
size_type size() const
Returns the number of components stored in the array.
DenseArray(DenseArray &&other) noexcept=default
Move constructor.
reference_type operator[](size_type idx)
Accesses the component at the given index.
std::vector< optional_t, Allocator > component_container_t
const optional_t & const_reference_type
optional_t & reference_type
DenseArray & operator=(const DenseArray &other)=default
Copy assignment operator.
void emplace_at(size_type id, Params &&... params)
Constructs and inserts a component at a specific ID.
typename component_container_t::const_iterator const_iterator
std::optional< Component > optional_t
void insert_at(size_type id, Component &&component)
Inserts a component at a specific ID (move version).
const_iterator cend() const
Returns a const iterator to the end of the component container.
DenseArray & operator=(DenseArray &&other) noexcept=default
Move assignment operator.
void erase(size_type id)
Removes the component at a specific ID.
typename component_container_t::size_type size_type
const_iterator cbegin() const
Returns a const iterator to the beginning of the component container.
std::vector< id_type > id_container_t
const_iterator begin() const
Returns a const iterator to the beginning of the component container.
const_reference_type operator[](size_type idx) const
Accesses the component at the given index (const version).
~DenseArray()=default
Destructor.