psl::ecs::details::staged_sparse_memory_region_t class

A specialized container type to store components in a type agnostic manner.

static member functions

instantiate<…>
Safe (and preferred) method of creating a staged_sparse_memory_region_t
-> staged_sparse_memory_region_t public static

constructors, destructors, conversion operators

staged_sparse_memory_region_t
public

member-functions

clear
Revert the object back to a safe default stage.
public noexcept
has
Checks if the given index exist in the requested range.
const noexcept -> bool public
operator[]<…>
Fetch or create the item at the given index.
-> T & public constexpr
get<…>
Fetch the item at the given index.
const -> T & public constexpr
set<…>
Sets the value at the given index.
-> bool public constexpr
dense<…>
Get a view of the underlying data for the given stage_range_t
const noexcept -> psl::array_view< T > public
indices
Get a view of the indices for the given stage_range_t
const noexcept -> psl::array_view< key_type > public
data
Get the data pointer for the given stage (where the data begins)
noexcept -> pointer public
cdata
Get the data pointer for the given stage (where the data begins)
const noexcept -> const_pointer public
at<…>
Get a reference of the requested type at the index.
const noexcept -> T const & public
at<…>
Get a reference of the requested type at the index.
noexcept -> T & public
addressof
Get a pointer of the data at the index.
const noexcept -> const_pointer public
addressof
Get a pointer of the data at the index.
noexcept -> pointer public
addressof_if
Get a pointer of the data at the index, or nullptr when not found.
const noexcept -> const_pointer public
addressof_if
Get a pointer of the data at the index, or nullptr when not found.
noexcept -> pointer public
dense_index_for
Retrieves the internal index for the dense data for the given index.
const noexcept -> key_type public
erase
Erases all values between the first/last indices.
noexcept -> size_t public
erase
Erases value at the given index.
noexcept -> size_t public
insert<…>
Inserts an item at the given index.
-> void public
insert<…>
Inserts all items [begin, end) starting from the index.
-> void public
insert
Insert an element at the given index.
-> void public
insert
Insert a range of elements from [begin, end).
-> void public
insert
Insert a range of elements at the given index.
-> void public
insert<…>
Insert a range of elements from [begin, end), and invoke the callback with the memory address associated with it.
-> void public
insert<…>
Insert a range of elements at the given index, and invoke the callback with the memory address associated with it.
-> void public
insert<…>
Insert an element at the given index, and invoke the callback with the memory address associated with it.
-> void public
promote
Promotes all values to the next stage_t. The cycle is as follows: ADDED -> SETTLED -> REMOVED -> deleted.
noexcept -> void public
remap<…>
Remaps the current instance based on the mapping provided.
-> void public
merge
Merges 2 staged_sparse_memory_region_t together (into the current one) replacing pre-existing entries.
noexcept -> merge_result public
insert_make_space
Makes sure there is insertion space for N elements.
-> void private

Function documentation

template<IsValidForStagedSparseMemoryRange T>
static FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::instantiate() -> staged_sparse_memory_region_t

Brief

Safe (and preferred) method of creating a staged_sparse_memory_region_t

Template parameters
T component type this should be storing (only used for size)
Returns An instance of staged_sparse_memory_region_t set up to be used with the given type

psl::ecs::details::staged_sparse_memory_region_t::staged_sparse_memory_region_t(size_t size)

Details

Parameters
size element size in the container

FORCEINLINE void psl::ecs::details::staged_sparse_memory_region_t::clear() noexcept

Brief

Revert the object back to a safe default stage.

Details

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::has(key_type index, stage_range_t stage = stage_range_t::ALIVE) const noexcept -> bool

Brief

Checks if the given index exist in the requested range.

Parameters
index Index to check
stage Stage that will be searched in
Returns Boolean containing true if found

template<IsValidForStagedSparseMemoryRange T>
FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::operator[](key_type index) -> T & constexpr

Brief

Fetch or create the item at the given index.

Template parameters
T Used to check the expected component size
Parameters
index Where the item would be
Returns The object as T at the given location

template<IsValidForStagedSparseMemoryRange T>
FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::get(key_type index, stage_range_t stage = stage_range_t::ALL) const -> T & constexpr

Brief

Fetch the item at the given index.

Details

Template parameters
T Used to check the expected component size
Parameters
index Where the item would be
stage The stage_range_t to search the index.
Returns The object as T at the given location

template<IsValidForStagedSparseMemoryRange T>
FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::set(key_type index, const T& value) -> bool constexpr

Brief

Sets the value at the given index.

Template parameters
T Type of the component (used for size and assignment)
Parameters
index Index of the item
value The value to set at the given index
Returns Boolean value indicating if the index was successfuly set or not

template<IsValidForStagedSparseMemoryRange T>
FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::dense(stage_range_t stage = stage_range_t::ALIVE) const noexcept -> psl::array_view< T >

Brief

Get a view of the underlying data for the given stage_range_t

Template parameters
T Component type to interpret the data as
Parameters
stage stage_range_t to limit what data is returned
Returns A view of the underlying data as the requested type

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::indices(stage_range_t stage = stage_range_t::ALIVE) const noexcept -> psl::array_view< key_type >

Brief

Get a view of the indices for the given stage_range_t

Parameters
stage stage_range_t to limit what indices are returned
Returns A view of the indices

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::data(stage_t stage = stage_t::SETTLED) noexcept -> pointer

Brief

Get the data pointer for the given stage (where the data begins)

Parameters
stage stage_t to retrieve
Returns A pointer to the head of the dense data

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::cdata(stage_t stage = stage_t::SETTLED) const noexcept -> const_pointer

Brief

Get the data pointer for the given stage (where the data begins)

Parameters
stage stage_t to retrieve
Returns A pointer to the head of the dense data

template<IsValidForStagedSparseMemoryRange T>
FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::at(key_type index, stage_range_t stage = stage_range_t::ALIVE) const noexcept -> T const &

Brief

Get a reference of the requested type at the index.

Details

Template parameters
T Type we want to interpret the data as
Parameters
index Where to look
stage Used to limit the stages we wish to look in
Returns Given memory address as a const ref

template<IsValidForStagedSparseMemoryRange T>
FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::at(key_type index, stage_range_t stage = stage_range_t::ALIVE) noexcept -> T &

Brief

Get a reference of the requested type at the index.

Details

Template parameters
T Type we want to interpret the data as
Parameters
index Where to look
stage Used to limit the stages we wish to look in
Returns Given memory address as a const ref

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::addressof(key_type index, stage_range_t stage = stage_range_t::ALIVE) const noexcept -> const_pointer

Brief

Get a pointer of the data at the index.

Details

Parameters
index Where to look
stage Used to limit the stages we wish to look in
Returns memory address

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::addressof(key_type index, stage_range_t stage = stage_range_t::ALIVE) noexcept -> pointer

Brief

Get a pointer of the data at the index.

Details

Parameters
index Where to look
stage Used to limit the stages we wish to look in
Returns memory address

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::addressof_if(key_type index, stage_range_t stage = stage_range_t::ALIVE) const noexcept -> const_pointer

Brief

Get a pointer of the data at the index, or nullptr when not found.

Parameters
index Where to look
stage Used to limit the stages we wish to look in
Returns memory address or nullptr

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::addressof_if(key_type index, stage_range_t stage = stage_range_t::ALIVE) noexcept -> pointer

Brief

Get a pointer of the data at the index, or nullptr when not found.

Parameters
index Where to look
stage Used to limit the stages we wish to look in
Returns memory address or nullptr

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::dense_index_for(key_type index, stage_range_t stage = stage_range_t::ALIVE) const noexcept -> key_type

Brief

Retrieves the internal index for the dense data for the given index.

Parameters
index Where to look
stage Used to limit the stages we wish to look in
Returns Index of the data relative to the data() (note that this does not take the type's size in account)

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::erase(key_type first, key_type last) noexcept -> size_t

Brief

Erases all values between the first/last indices.

Parameters
first Begin of the range
last End of the range
Returns Amount of elements erased

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::erase(key_type index) noexcept -> size_t

Brief

Erases value at the given index.

Parameters
index Index to erase
Returns Amount of elements erased (0 or 1)

template<IsValidForStagedSparseMemoryRange T>
FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::insert(key_type index, const T& value) -> void

Brief

Inserts an item at the given index.

Details

Template parameters
T The type of the element to insert
Parameters
index Where to insert it
value The value to insert

template<typename ItF, typename ItL>
FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::insert(key_type index, ItF&& begin, ItL&& end) -> void

Brief

Inserts all items [begin, end) starting from the index.

Details

Parameters
index First index to where to start the insertions
begin Iterator to the beginning of the values range
end Iterator to the end of the values range

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::insert(key_type index) -> void

Brief

Insert an element at the given index.

Parameters
index Location to insert a value

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::insert(key_type* begin, key_type* end) -> void

Brief

Insert a range of elements from [begin, end).

Parameters
begin Iterator to the first element.
end Iterator to one beyond the last element.

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::insert(key_type index, key_type count) -> void

Brief

Insert a range of elements at the given index.

Parameters
index Location of the first element
count How many items to insert (the range is [index, index+count)

template<typename Fn>
FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::insert(key_type* begin, key_type* end, Fn&& callback) -> void

Brief

Insert a range of elements from [begin, end), and invoke the callback with the memory address associated with it.

Parameters
begin Iterator to the first element.
end Iterator to one beyond the last element.
callback Function of the signature void(std::byte*, std::byte*) to invoke. Where the second element is the end ptr.

template<typename Fn>
FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::insert(key_type index, key_type count, Fn&& callback) -> void

Brief

Insert a range of elements at the given index, and invoke the callback with the memory address associated with it.

Parameters
index Location of the first element
count How many items to insert (the range is [index, index+count)
callback Function of the signature void(std::byte*, std::byte*) to invoke. Where the second element is the end ptr.

template<typename Fn>
FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::insert(key_type index, Fn&& callback) -> void

Brief

Insert an element at the given index, and invoke the callback with the memory address associated with it.

Parameters
index Location to insert a value
callback Function of the signature void(std::byte*) to invoke.

template<typename Fn>
FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::remap(const psl::sparse_array<key_type>& mapping, Fn&& predicate) -> void

Brief

Remaps the current instance based on the mapping provided.

Details

accesses all indices in the current container rejecting those who don't satisfy the predicate. Those who weren't rejected by the predicate are then looked up in the mapping value, and their return value is used to re-assign the index in the current container. f.e. if the mapping had a value of { 100, 200 } (index, value), and the predicate didn't reject the item on our end, then what was at 100 in this container would be remapped to the index 200.

Template parameters
Fn
Parameters
mapping The mapping to use
predicate Predicate that returns a boolean value if the index was found

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::merge(const staged_sparse_memory_region_t& other) noexcept -> merge_result

Brief

Merges 2 staged_sparse_memory_region_t together (into the current one) replacing pre-existing entries.

Parameters
other the staged_sparse_memory_region_t to merge into this one
Returns object that contains { .success /* bool ‍/, .total / total items processed, inserted + replaced ‍/, .added / amount that was inserted into the current container *‍/ }

FORCEINLINE auto psl::ecs::details::staged_sparse_memory_region_t::insert_make_space(key_type size = 1) -> void private

Brief

Makes sure there is insertion space for N elements.

Parameters
size Amount of elements to make space for