Gaia-ECS v1.0.0
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename > Class Template Reference

Array with variable size of elements of type T allocated on heap. Allocates enough memory to support PageCapacity elements. Uses Allocator to allocate memory. More...

#include <sparse_storage.h>

Public Types

using value_type = T
 Stored value type.
 
using reference = T &
 Mutable value reference.
 
using const_reference = const T &
 Constant value reference.
 
using pointer = T *
 Mutable value pointer.
 
using const_pointer = const T *
 Constant value pointer.
 
using view_policy = mem::data_view_policy_aos< T >
 Data access policy.
 
using difference_type = detail::difference_type
 Type used for iterator distances.
 
using size_type = detail::size_type
 Type used for sizes and offsets.
 
using iterator = sparse_iterator< T, PageCapacity, Allocator >
 Mutable iterator type.
 
using const_iterator = const_sparse_iterator< T, PageCapacity, Allocator >
 Constant iterator type.
 
using page_type = detail::sparse_page< T, PageCapacity, Allocator >
 Internal sparse-page type.
 

Public Member Functions

 sparse_storage (const sparse_storage &other)
 Copy-constructs the storage.
 
sparse_storageoperator= (const sparse_storage &other)
 Copy-assigns the storage.
 
 sparse_storage (sparse_storage &&other) noexcept
 Move-constructs the storage.
 
sparse_storageoperator= (sparse_storage &&other) noexcept
 Move-assigns the storage.
 
GAIA_NODISCARD decltype(autooperator[] (sparse_id sid) noexcept
 Returns the value associated with a sparse identifier.
 
GAIA_NODISCARD decltype(autooperator[] (sparse_id sid) const noexcept
 Returns the value associated with a sparse identifier.
 
GAIA_NODISCARD bool has (sparse_id sid) const
 Checks whether an item with a sparse identifier exists.
 
GAIA_NODISCARD bool has (const T &arg) const
 Checks if an item arg exists within the storage.
 
template<typename TType >
decltype(autoadd (TType &&arg)
 Inserts the item arg into the storage.
 
decltype(autoset (sparse_id sid)
 Update the record at the index sid.
 
void del (sparse_id sid) noexcept
 Removes the item at the index sid from the storage.
 
void del (const T &arg) noexcept
 Removes the item arg from the storage.
 
void clear ()
 Clears the storage.
 
GAIA_NODISCARD size_type size () const noexcept
 Returns the number of items inserted into the storage.
 
GAIA_NODISCARD bool empty () const noexcept
 Checks if the storage is empty (no items inserted).
 
GAIA_NODISCARD decltype(autofront () noexcept
 Returns the first stored value.
 
GAIA_NODISCARD decltype(autofront () const noexcept
 Returns the first stored value.
 
GAIA_NODISCARD decltype(autoback () noexcept
 Returns the last stored value.
 
GAIA_NODISCARD decltype(autoback () const noexcept
 Returns the last stored value.
 
GAIA_NODISCARD auto begin () noexcept
 Returns an iterator to the first value.
 
GAIA_NODISCARD auto begin () const noexcept
 Returns an iterator to the first value.
 
GAIA_NODISCARD auto cbegin () const noexcept
 Returns a constant iterator to the first value.
 
GAIA_NODISCARD auto end () noexcept
 Returns an iterator past the last value.
 
GAIA_NODISCARD auto end () const noexcept
 Returns an iterator past the last value.
 
GAIA_NODISCARD auto cend () const noexcept
 Returns a constant iterator past the last value.
 
GAIA_NODISCARD bool operator== (const sparse_storage &other) const
 Checks whether two storages contain equal values at equal sparse identifiers.
 
GAIA_NODISCARD constexpr bool operator!= (const sparse_storage &other) const
 Checks whether two storages differ.
 

Detailed Description

template<typename T, uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
class gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >

Array with variable size of elements of type T allocated on heap. Allocates enough memory to support PageCapacity elements. Uses Allocator to allocate memory.

Template Parameters
TStored value type. param PageCapacity Number of sparse entries represented by each page. Must be a power of two.
AllocatorAllocator used by the storage pages.

Constructor & Destructor Documentation

◆ sparse_storage() [1/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::sparse_storage ( const sparse_storage< T, PageCapacity, Allocator, typename > &  other)
inline

Copy-constructs the storage.

Parameters
otherStorage to copy.

◆ sparse_storage() [2/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::sparse_storage ( sparse_storage< T, PageCapacity, Allocator, typename > &&  other)
inlinenoexcept

Move-constructs the storage.

Parameters
otherStorage to move from.

Member Function Documentation

◆ add()

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
template<typename TType >
decltype(auto) gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::add ( TType &&  arg)
inline

Inserts the item arg into the storage.

Parameters
argData
Returns
Reference to the inserted record or nothing in case it is has a SoA layout.
Template Parameters
TTypeInserted value type.

◆ back() [1/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD decltype(auto) gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::back ( ) const
inlinenoexcept

Returns the last stored value.

Returns
Constant reference to the last value.

◆ back() [2/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD decltype(auto) gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::back ( )
inlinenoexcept

Returns the last stored value.

Returns
Mutable reference to the last value.

◆ begin() [1/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD auto gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::begin ( ) const
inlinenoexcept

Returns an iterator to the first value.

Returns
Constant begin iterator.

◆ begin() [2/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD auto gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::begin ( )
inlinenoexcept

Returns an iterator to the first value.

Returns
Mutable begin iterator.

◆ cbegin()

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD auto gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::cbegin ( ) const
inlinenoexcept

Returns a constant iterator to the first value.

Returns
Constant begin iterator.

◆ cend()

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD auto gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::cend ( ) const
inlinenoexcept

Returns a constant iterator past the last value.

Returns
Constant end iterator.

◆ del() [1/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
void gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::del ( const T arg)
inlinenoexcept

Removes the item arg from the storage.

Parameters
argData

◆ del() [2/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
void gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::del ( sparse_id  sid)
inlinenoexcept

Removes the item at the index sid from the storage.

Parameters
sidSparse id

◆ empty()

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD bool gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::empty ( ) const
inlinenoexcept

Checks if the storage is empty (no items inserted).

Returns
True if the storage contains no items.

◆ end() [1/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD auto gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::end ( ) const
inlinenoexcept

Returns an iterator past the last value.

Returns
Constant end iterator.

◆ end() [2/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD auto gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::end ( )
inlinenoexcept

Returns an iterator past the last value.

Returns
Mutable end iterator.

◆ front() [1/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD decltype(auto) gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::front ( ) const
inlinenoexcept

Returns the first stored value.

Returns
Constant reference to the first value.

◆ front() [2/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD decltype(auto) gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::front ( )
inlinenoexcept

Returns the first stored value.

Returns
Mutable reference to the first value.

◆ has() [1/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD bool gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::has ( const T arg) const
inline

Checks if an item arg exists within the storage.

Parameters
argData
Returns
True if the item is present.

◆ has() [2/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD bool gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::has ( sparse_id  sid) const
inline

Checks whether an item with a sparse identifier exists.

Parameters
sidSparse identifier to find.
Returns
True if the identifier is present.

◆ operator!=()

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD constexpr bool gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::operator!= ( const sparse_storage< T, PageCapacity, Allocator, typename > &  other) const
inlineconstexpr

Checks whether two storages differ.

Parameters
otherStorage to compare.
Returns
True if the storages are not equal.

◆ operator=() [1/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
sparse_storage & gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::operator= ( const sparse_storage< T, PageCapacity, Allocator, typename > &  other)
inline

Copy-assigns the storage.

Parameters
otherStorage to copy.
Returns
This storage.

◆ operator=() [2/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
sparse_storage & gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::operator= ( sparse_storage< T, PageCapacity, Allocator, typename > &&  other)
inlinenoexcept

Move-assigns the storage.

Parameters
otherStorage to move from.
Returns
This storage.

◆ operator==()

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD bool gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::operator== ( const sparse_storage< T, PageCapacity, Allocator, typename > &  other) const
inline

Checks whether two storages contain equal values at equal sparse identifiers.

Parameters
otherStorage to compare.
Returns
True if the storages are equal.

◆ operator[]() [1/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD decltype(auto) gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::operator[] ( sparse_id  sid) const
inlinenoexcept

Returns the value associated with a sparse identifier.

Parameters
sidSparse identifier to access. It must exist.
Returns
Constant reference to the stored value.

◆ operator[]() [2/2]

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD decltype(auto) gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::operator[] ( sparse_id  sid)
inlinenoexcept

Returns the value associated with a sparse identifier.

Parameters
sidSparse identifier to access. It must exist.
Returns
Mutable reference to the stored value.

◆ set()

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
decltype(auto) gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::set ( sparse_id  sid)
inline

Update the record at the index sid.

Parameters
sidSparse id
Returns
Reference to the inserted record or nothing in case it is has a SoA layout.

◆ size()

template<typename T , uint32_t PageCapacity = 4096, typename Allocator = mem::DefaultAllocatorAdaptor, typename = void>
GAIA_NODISCARD size_type gaia::cnt::sparse_storage< T, PageCapacity, Allocator, typename >::size ( ) const
inlinenoexcept

Returns the number of items inserted into the storage.

Returns
Number of stored items.

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