sandbox
Loading...
Searching...
No Matches
sbx::ecs::basic_sparse_set< Entity, Allocator > Class Template Reference

Sparse set container for entity identifiers. More...

#include <sparse_set.hpp>

Inheritance diagram for sbx::ecs::basic_sparse_set< Entity, Allocator >:
sbx::ecs::basic_storage< Type, Entity, Allocator >

Public Types

using allocator_type = Allocator
 
using entity_type = entity_traits::value_type
 
using version_type = entity_traits::version_type
 
using pointer = typename dense_storage_type::pointer
 
using const_pointer = typename dense_storage_type::const_pointer
 
using reference = typename dense_storage_type::reference
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 
using iterator = detail::sparse_set_iterator< dense_storage_type >
 
using const_iterator = iterator
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 

Public Member Functions

 basic_sparse_set (const deletion_policy policy=deletion_policy::unspecified, const allocator_type &allocator=allocator_type{})
 Constructs an empty sparse set. More...
 
 basic_sparse_set (const basic_sparse_set &other)=delete
 Deleted copy constructor. More...
 
 basic_sparse_set (basic_sparse_set &&other) noexcept
 Move-constructs a sparse set. More...
 
 basic_sparse_set (basic_sparse_set &&other, const allocator_type &allocator)
 Move-constructs a sparse set using a specific allocator. More...
 
virtual ~basic_sparse_set ()
 Destroys the sparse set. More...
 
auto operator= (const basic_sparse_set &other) -> basic_sparse_set &=delete
 Deleted copy assignment operator. More...
 
auto operator= (basic_sparse_set &&other) noexcept -> basic_sparse_set &
 Move-assigns a sparse set. More...
 
auto swap (basic_sparse_set &other) noexcept -> void
 Swaps the contents of two sparse sets.
 
constexpr auto get_allocator () const noexcept -> allocator_type
 Returns the allocator associated with the container.
 
auto policy () const noexcept -> deletion_policy
 Returns the deletion policy.
 
auto free_list () const noexcept -> size_type
 Returns the index of the free-list head.
 
virtual void reserve (const size_type capacity)
 Reserves dense storage capacity. More...
 
virtual auto capacity () const noexcept -> size_type
 Returns dense storage capacity.
 
auto extent () const noexcept -> size_type
 Returns sparse storage extent.
 
auto size () const noexcept -> size_type
 Returns the number of stored entities.
 
auto is_empty () const noexcept -> bool
 Checks whether the set is empty.
 
auto is_contiguous () const noexcept -> bool
 Checks whether the dense storage is contiguous.
 
auto data () const noexcept -> const_pointer
 Returns pointer to dense storage.
 
auto data () noexcept -> pointer
 Returns pointer to dense storage.
 
auto bump (const entity_type entity) -> version_type
 Updates the version of an entity.
 
auto begin () const noexcept -> iterator
 Returns iterator to the first element.
 
auto cbegin () const noexcept -> const_iterator
 Returns const iterator to the first element.
 
auto end () const noexcept -> iterator
 Returns iterator to the end.
 
auto cend () const noexcept -> const_iterator
 Returns const iterator to the end.
 
bool contains (const entity_type entity) const noexcept
 Checks whether an entity exists in the set.
 
auto current (const entity_type entity) const noexcept -> version_type
 Returns the current version of an entity.
 
auto find (const entity_type entity) const noexcept -> const_iterator
 Finds an entity iterator.
 
auto index (const entity_type entity) const noexcept -> size_type
 Returns the dense index of an entity.
 
auto erase (const entity_type entity) -> void
 Removes an entity.
 
auto remove (const entity_type entity) -> bool
 Removes an entity if present.
 
template<typename Compare , typename Sort = utility::std_sort, typename... Args>
auto sort (Compare compare, Sort sort=Sort{}, Args &&... args) -> void
 Sorts entities using a comparator.
 
template<typename Compare , typename Sort = utility::std_sort, typename... Args>
auto sort_n (const size_type length, Compare compare, Sort sort=Sort{}, Args &&... args) -> void
 Sorts the first N entities.
 
auto clear () -> void
 Clears all entities.
 
auto invoke (const utility::hashed_string &tag, const entity_type entity) -> void
 Invokes a tagged callback on an entity.
 

Protected Types

using basic_iterator = iterator
 

Protected Member Functions

virtual auto call (const utility::hashed_string &tag, const entity_type entity) -> void
 Virtual callback hook.
 
void swap_only (const basic_iterator iterator)
 
auto swap_and_pop (const basic_iterator iterator) -> void
 
auto in_place_pop (const basic_iterator iterator) -> void
 
virtual auto pop (basic_iterator first, basic_iterator last) -> void
 
virtual auto pop_all () -> void
 
virtual auto try_emplace (const entity_type entity, const bool force_back) -> basic_iterator
 

Detailed Description

template<typename Entity, memory::allocator_for< Entity > Allocator = std::allocator<Entity>>
class sbx::ecs::basic_sparse_set< Entity, Allocator >

Sparse set container for entity identifiers.

Template Parameters
EntityEntity identifier type.
AllocatorAllocator type.

Constructor & Destructor Documentation

◆ basic_sparse_set() [1/4]

template<typename Entity , memory::allocator_for< Entity > Allocator>
sbx::ecs::basic_sparse_set< Entity, Allocator >::basic_sparse_set ( const deletion_policy  policy = deletion_policy::unspecified,
const allocator_type &  allocator = allocator_type{} 
)

Constructs an empty sparse set.

Parameters
policyDeletion policy.
allocatorAllocator instance.

◆ basic_sparse_set() [2/4]

template<typename Entity , memory::allocator_for< Entity > Allocator = std::allocator<Entity>>
sbx::ecs::basic_sparse_set< Entity, Allocator >::basic_sparse_set ( const basic_sparse_set< Entity, Allocator > &  other)
delete

Deleted copy constructor.

Copying a sparse set is explicitly disallowed to prevent accidental duplication of internal sparse and dense storage.

Parameters
otherSource sparse set.

◆ basic_sparse_set() [3/4]

template<typename Entity , memory::allocator_for< Entity > Allocator>
sbx::ecs::basic_sparse_set< Entity, Allocator >::basic_sparse_set ( basic_sparse_set< Entity, Allocator > &&  other)
noexcept

Move-constructs a sparse set.

Transfers ownership of the internal storage from the source instance. The moved-from sparse set is left in a valid but unspecified state.

Parameters
otherSource sparse set.

◆ basic_sparse_set() [4/4]

template<typename Entity , memory::allocator_for< Entity > Allocator>
sbx::ecs::basic_sparse_set< Entity, Allocator >::basic_sparse_set ( basic_sparse_set< Entity, Allocator > &&  other,
const allocator_type &  allocator 
)

Move-constructs a sparse set using a specific allocator.

Moves the contents of the source sparse set while rebinding storage to the provided allocator. If allocator propagation is not permitted, the allocators must compare equal.

Parameters
otherSource sparse set.
allocatorAllocator to use for the new instance.

◆ ~basic_sparse_set()

template<typename Entity , memory::allocator_for< Entity > Allocator>
sbx::ecs::basic_sparse_set< Entity, Allocator >::~basic_sparse_set
virtual

Destroys the sparse set.

Releases all allocated sparse pages and clears internal storage.

Member Function Documentation

◆ operator=() [1/2]

template<typename Entity , memory::allocator_for< Entity > Allocator>
auto sbx::ecs::basic_sparse_set< Entity, Allocator >::operator= ( basic_sparse_set< Entity, Allocator > &&  other) -> basic_sparse_set&
noexcept

Move-assigns a sparse set.

Transfers ownership of all internal storage from the source instance. Allocators must be compatible or always equal.

Parameters
otherSource sparse set.
Returns
Reference to this sparse set.

◆ operator=() [2/2]

template<typename Entity , memory::allocator_for< Entity > Allocator = std::allocator<Entity>>
auto sbx::ecs::basic_sparse_set< Entity, Allocator >::operator= ( const basic_sparse_set< Entity, Allocator > &  other) -> basic_sparse_set &=delete
delete

Deleted copy assignment operator.

Copy assignment is explicitly disallowed to avoid unsafe duplication of sparse mappings and dense storage.

Parameters
otherSource sparse set.
Returns
Reference to this sparse set.

◆ reserve()

template<typename Entity , memory::allocator_for< Entity > Allocator>
void sbx::ecs::basic_sparse_set< Entity, Allocator >::reserve ( const size_type  capacity)
virtual

Reserves dense storage capacity.

Reimplemented in sbx::ecs::basic_storage< Type, Entity, Allocator >.


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