8 #ifndef SPARSEARRAY_HPP_
9 #define SPARSEARRAY_HPP_
17 template <
typename Component>
31 using sizeType =
typename container::size_type;
51 _data = sparseArray._data;
59 _data = sparseArray._data;
103 if (_data.size() < pos + 1)
104 _data.resize(pos + 1);
105 _data[pos] = component;
115 if (_data.size() < pos + 1)
116 _data.resize(pos + 1);
117 _data[pos] = component;
134 template <
class... Params>
147 if (_data.size() > pos && _data[pos].has_value())
155 for (
sizeType pos = 0; pos < _data.size(); pos++) {
156 if (std::addressof(_data[pos]) == std::addressof(val))
164 void resize(
const std::size_t &count) { _data.resize(count); }
ComponentNotInsertedError Class Error Error thrown when trying to access a component that is not regi...
Definition: Error.hpp:37
Array which can have empty indexes.
Definition: SparseArray.hpp:19
void erase(sizeType pos)
Removes the component at the specified position.
Definition: SparseArray.hpp:145
iterator begin()
Getter for the begin iterator.
Definition: SparseArray.hpp:74
constIterator begin() const
Getter for the begin iterator.
Definition: SparseArray.hpp:77
valueType & referenceType
Reference to valueType.
Definition: SparseArray.hpp:24
SparseArray & operator=(const SparseArray &sparseArray)
Overload for the copy assignement operator.
Definition: SparseArray.hpp:49
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 bi...
Definition: SparseArray.hpp:101
typename container::size_type sizeType
Type of the size of the container.
Definition: SparseArray.hpp:31
sizeType getIndex(const valueType &val) const
Getter for the index of the component given. The component needs to be in the array.
Definition: SparseArray.hpp:153
iterator end()
Getter for the end iterator.
Definition: SparseArray.hpp:84
SparseArray()
SparseArray's constructor.
Definition: SparseArray.hpp:39
typename container::iterator iterator
Type of the container's iterator.
Definition: SparseArray.hpp:34
referenceType insert_at(sizeType pos, Component &&component)
Insert the component at the position specified, the component will be moved in. Will resize the array...
Definition: SparseArray.hpp:113
constIterator cbegin() const
Getter for the begin iterator.
Definition: SparseArray.hpp:80
std::vector< valueType > container
Type of the container, which is a a vector storing a valueType.
Definition: SparseArray.hpp:28
constIterator end() const
Getter for the end iterator.
Definition: SparseArray.hpp:87
sizeType size() const
Getter for the array's size.
Definition: SparseArray.hpp:94
void resize(const std::size_t &count)
Resize the array.
Definition: SparseArray.hpp:164
std::optional< Component > valueType
Type of the array wrap in an optional.
Definition: SparseArray.hpp:22
typename container::const_iterator constIterator
Constant type of the container's iterator.
Definition: SparseArray.hpp:36
referenceType emplace_at(sizeType pos, Params &&...params)
Creates components at the specified positions.
Definition: SparseArray.hpp:135
referenceType operator[](std::size_t idx)
Overload for the bracket operator.
Definition: SparseArray.hpp:66
referenceType emplace_at(sizeType pos)
Creates the component at the specified position.
Definition: SparseArray.hpp:124
SparseArray(const SparseArray &sparseArray)
Copy constructor for the SparseArray.
Definition: SparseArray.hpp:42
const valueType & constReferenceType
Constant reference to valueType.
Definition: SparseArray.hpp:26
constReferenceType operator[](std::size_t idx) const
Overload for the bracket operator.
Definition: SparseArray.hpp:70
SparseArray & operator=(SparseArray &&sparseArray) noexcept
Overload for the move assignment operator.
Definition: SparseArray.hpp:57
constIterator cend() const
Getter for the end iterator.
Definition: SparseArray.hpp:90