Gaia-ECS v1.0.0
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage > Struct Template Reference

Implicit list. Rather than with pointers, items. More...

#include <ilist.h>

Public Types

using internal_storage = TInternalStorage
 Underlying slot storage type.
 
using value_type = TListItem
 Stored item type.
 
using reference = TListItem &
 Mutable item reference.
 
using const_reference = const TListItem &
 Immutable item reference.
 
using pointer = TListItem *
 Mutable item pointer.
 
using const_pointer = const TListItem *
 Immutable item pointer.
 
using difference_type = typename internal_storage::difference_type
 Underlying iterator distance type.
 
using size_type = typename internal_storage::size_type
 Underlying size and index type.
 
using iterator = typename internal_storage::iterator
 Mutable storage iterator.
 
using const_iterator = typename internal_storage::const_iterator
 Immutable storage iterator.
 
using iterator_category = typename internal_storage::iterator_category
 Underlying iterator category tag.
 

Public Member Functions

GAIA_NODISCARD pointer data () noexcept
 Returns contiguous item storage.
 
GAIA_NODISCARD const_pointer data () const noexcept
 Returns contiguous item storage.
 
GAIA_NODISCARD reference operator[] (size_type index)
 Returns an item slot by index.
 
GAIA_NODISCARD const_reference operator[] (size_type index) const
 Returns an item slot by index.
 
void clear ()
 Removes all slots and resets the free list.
 
GAIA_NODISCARD size_type get_next_free_item () const noexcept
 Returns the free-list head.
 
GAIA_NODISCARD size_type get_free_items () const noexcept
 Returns the number of recyclable slots.
 
GAIA_NODISCARD size_type item_count () const noexcept
 Returns the number of live items.
 
GAIA_NODISCARD size_type size () const noexcept
 Returns the total number of allocated slots.
 
GAIA_NODISCARD bool empty () const noexcept
 Checks whether no slots have been allocated.
 
GAIA_NODISCARD size_type capacity () const noexcept
 Returns slot capacity.
 
GAIA_NODISCARD iterator begin () noexcept
 Returns a mutable iterator to the first storage slot.
 
GAIA_NODISCARD const_iterator begin () const noexcept
 Returns an immutable iterator to the first storage slot.
 
GAIA_NODISCARD const_iterator cbegin () const noexcept
 Returns an immutable iterator to the first storage slot.
 
GAIA_NODISCARD iterator end () noexcept
 Returns the mutable storage end sentinel.
 
GAIA_NODISCARD const_iterator end () const noexcept
 Returns the immutable storage end sentinel.
 
GAIA_NODISCARD const_iterator cend () const noexcept
 Returns the immutable storage end sentinel.
 
void reserve (size_type cap)
 Reserves storage for slots.
 
GAIA_NODISCARD TItemHandle alloc (void *ctx)
 Allocates a new item in the list.
 
GAIA_NODISCARD TItemHandle alloc ()
 Allocates a new item in the list.
 
TListItemfree (TItemHandle handle)
 Invalidates handle. Every time an item is deallocated its generation is increased by one.
 
void validate () const
 Verifies that the implicit linked list is valid.
 

Public Attributes

internal_storage m_items
 Implicit list items.
 
size_type m_nextFreeIdx = (size_type)-1
 Index of the next item to recycle.
 
size_type m_freeItems = 0
 Number of items to recycle.
 

Detailed Description

template<typename TListItem, typename TItemHandle, typename TInternalStorage = darray_ilist_storage<TListItem>>
struct gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >

Implicit list. Rather than with pointers, items.

Template Parameters
TListItemare linked together through an internal indexing mechanism. To the outside world they are presented as
TItemHandle.All items are stored in a container instance of the type
TInternalStorage.
TListItemneeds to expose slot metadata through ilist_item_traits<TListItem> and expose a constructor that initializes the slot index and generation.

Member Function Documentation

◆ alloc() [1/2]

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD TItemHandle gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::alloc ( )
inline

Allocates a new item in the list.

Returns
Handle to the new item

◆ alloc() [2/2]

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD TItemHandle gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::alloc ( void ctx)
inline

Allocates a new item in the list.

Parameters
ctxContext forwarded to TListItem::create().
Returns
Handle to the new item

◆ begin() [1/2]

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD const_iterator gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::begin ( ) const
inlinenoexcept

Returns an immutable iterator to the first storage slot.

Returns
Immutable iterator to the first slot.

◆ begin() [2/2]

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD iterator gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::begin ( )
inlinenoexcept

Returns a mutable iterator to the first storage slot.

Returns
Mutable iterator to the first slot.

◆ capacity()

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD size_type gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::capacity ( ) const
inlinenoexcept

Returns slot capacity.

Returns
Number of slots available without growing storage.

◆ cbegin()

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD const_iterator gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::cbegin ( ) const
inlinenoexcept

Returns an immutable iterator to the first storage slot.

Returns
Immutable iterator to the first slot.

◆ cend()

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD const_iterator gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::cend ( ) const
inlinenoexcept

Returns the immutable storage end sentinel.

Returns
Immutable iterator following the last slot.

◆ data() [1/2]

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD const_pointer gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::data ( ) const
inlinenoexcept

Returns contiguous item storage.

Returns
Const pointer to the first slot.

◆ data() [2/2]

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD pointer gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::data ( )
inlinenoexcept

Returns contiguous item storage.

Returns
Pointer to the first slot.

◆ empty()

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD bool gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::empty ( ) const
inlinenoexcept

Checks whether no slots have been allocated.

Returns
True when size() is zero. False otherwise.

◆ end() [1/2]

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD const_iterator gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::end ( ) const
inlinenoexcept

Returns the immutable storage end sentinel.

Returns
Immutable iterator following the last slot.

◆ end() [2/2]

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD iterator gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::end ( )
inlinenoexcept

Returns the mutable storage end sentinel.

Returns
Mutable iterator following the last slot.

◆ free()

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
TListItem & gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::free ( TItemHandle  handle)
inline

Invalidates handle. Every time an item is deallocated its generation is increased by one.

Parameters
handleHandle
Returns
Reference to the recycled item slot.

◆ get_free_items()

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD size_type gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::get_free_items ( ) const
inlinenoexcept

Returns the number of recyclable slots.

Returns
Number of slots linked through the free list.

◆ get_next_free_item()

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD size_type gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::get_next_free_item ( ) const
inlinenoexcept

Returns the free-list head.

Returns
Index of the next recyclable slot, or the handle type's invalid id.

◆ item_count()

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD size_type gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::item_count ( ) const
inlinenoexcept

Returns the number of live items.

Returns
Total slot count minus recyclable slot count.

◆ operator[]() [1/2]

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD reference gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::operator[] ( size_type  index)
inline

Returns an item slot by index.

Parameters
indexSlot index.
Returns
Mutable reference to the slot.

◆ operator[]() [2/2]

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD const_reference gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::operator[] ( size_type  index) const
inline

Returns an item slot by index.

Parameters
indexSlot index.
Returns
Immutable reference to the slot.

◆ reserve()

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
void gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::reserve ( size_type  cap)
inline

Reserves storage for slots.

Parameters
capMinimum requested slot capacity.

◆ size()

template<typename TListItem , typename TItemHandle , typename TInternalStorage = darray_ilist_storage<TListItem>>
GAIA_NODISCARD size_type gaia::cnt::ilist< TListItem, TItemHandle, TInternalStorage >::size ( ) const
inlinenoexcept

Returns the total number of allocated slots.

Returns
Live and recyclable slot count.

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