CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
slimsig::slot_list< T, IDGenerator, FlagType, Allocator > Class Template Reference

#include <slot.h>

Inheritance diagram for slimsig::slot_list< T, IDGenerator, FlagType, Allocator >:

Public Types

using slot_id = decltype(slot_id_helper(std::declval< IDGenerator >()))
 
using slot = basic_slot< T, slot_id >
 
using callback = typename slot::callback
 
using allocator_type = typename std::allocator_traits< Allocator >::template rebind_traits< slot >::allocator_type
 
using container_type = std::vector< slot, allocator_type >
 
using value_type = typename container_type::value_type
 
using reference = typename container_type::reference
 
using const_reference = typename container_type::const_reference
 
using size_type = typename container_type::size_type
 
using pointer = typename container_type::pointer
 
using iterator = typename container_type::iterator
 
using const_iterator = typename container_type::const_iterator
 

Public Member Functions

 slot_list ()
 
 slot_list (allocator_type alloc)
 
 slot_list (slot_list &&)=default
 
 slot_list (const slot_list &)=default
 
bool try_lock ()
 
void lock ()
 
void unlock ()
 
bool locked () const noexcept(noexcept(bool(std::declval< FlagType >())))
 
slot_id push (const value_type &value)
 
slot_id push (value_type &&value)
 
template<class... Args>
slot_id emplace (Args &&... args)
 
template<class U , class... Args>
slot_id emplace_extended (Args &&... args)
 
iterator erase (const_iterator position)
 
iterator erase (const_iterator begin, const_iterator end)
 
iterator begin ()
 
iterator end ()
 
const_iterator cbegin () const
 
const_iterator cend () const
 
size_type active_size () const
 
reference back ()
 
const_reference cback () const
 
size_type pending_size () const
 
size_type total_size () const
 
void clear ()
 
bool active_empty () const
 
bool pending_empty () const
 
bool empty () const
 
iterator find (slot_id index) noexcept
 
const_iterator find (slot_id index) const noexcept
 

Detailed Description

template<class T, class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
class slimsig::slot_list< T, IDGenerator, FlagType, Allocator >

Specialized container adaptor for slot/callback values Because of some assumptions we can make about how signals will use this list, we can achieve great performance boosts over using a standard containers alone Requirements: T must meet all requirements of Container SlotID must be post-incrementable, equality comparable and less than comparable SlotID must always be unique for new values added to the list SlotID must always increase in value for new values (new slots must compare greater than old slots) SlotID must support default initilization The return of SlotID++ will be stored with each slot for access

We use this type of lookup for slots because we need a way to access slots after the vectors iterators have been invalidated, but we need to do this quickly.

To accomplish this we use a simple linear search if the container contains less than 4 elements Otherwise we use std::lower_bound to quickly locate the slot with this ID in the vector This requires the vector to be sorted with lower IDs (older slots) first

Because generally slots aren't removed or queried nearly as much as they are emitted Applications will see huge performance gains over using a list or a vector of shared_ptr's due to the memory being contigious. Additions are pretty snappy in most cases because we don't need to make allocations for every slot, only when we've exceeded our underlying vectors capacity

In multithreaded applications it's reccomended that SlotIDGenerator be an atomic type or use mutexes to syncronize.

This would be better with some sort of Optional type

Definition at line 156 of file slot.h.

Member Typedef Documentation

◆ allocator_type

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
using slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::allocator_type = typename std::allocator_traits<Allocator>::template rebind_traits<slot>::allocator_type

Definition at line 164 of file slot.h.

◆ callback

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
using slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::callback = typename slot::callback

Definition at line 163 of file slot.h.

◆ const_iterator

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
using slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::const_iterator = typename container_type::const_iterator

Definition at line 172 of file slot.h.

◆ const_reference

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
using slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::const_reference = typename container_type::const_reference

Definition at line 168 of file slot.h.

◆ container_type

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
using slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::container_type = std::vector<slot, allocator_type>

Definition at line 165 of file slot.h.

◆ iterator

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
using slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::iterator = typename container_type::iterator

Definition at line 171 of file slot.h.

◆ pointer

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
using slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::pointer = typename container_type::pointer

Definition at line 170 of file slot.h.

◆ reference

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
using slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::reference = typename container_type::reference

Definition at line 167 of file slot.h.

◆ size_type

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
using slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::size_type = typename container_type::size_type

Definition at line 169 of file slot.h.

◆ slot

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
using slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::slot = basic_slot<T, slot_id>

Definition at line 162 of file slot.h.

◆ slot_id

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
using slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::slot_id = decltype(slot_id_helper(std::declval<IDGenerator>()))

Definition at line 161 of file slot.h.

◆ value_type

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
using slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::value_type = typename container_type::value_type

Definition at line 166 of file slot.h.

Constructor & Destructor Documentation

◆ slot_list() [1/4]

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::slot_list ( )
inline

Definition at line 174 of file slot.h.

◆ slot_list() [2/4]

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::slot_list ( allocator_type  alloc)
inline

Definition at line 175 of file slot.h.

◆ slot_list() [3/4]

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::slot_list ( slot_list< T, IDGenerator, FlagType, Allocator > &&  )
default

◆ slot_list() [4/4]

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::slot_list ( const slot_list< T, IDGenerator, FlagType, Allocator > &  )
default

Member Function Documentation

◆ active_empty()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
bool slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::active_empty ( ) const
inline

Definition at line 252 of file slot.h.

◆ active_size()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
size_type slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::active_size ( ) const
inline

Definition at line 246 of file slot.h.

◆ back()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
reference slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::back ( )
inline

Definition at line 247 of file slot.h.

◆ begin()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
iterator slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::begin ( )
inline

Definition at line 242 of file slot.h.

◆ cback()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
const_reference slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::cback ( ) const
inline

Definition at line 248 of file slot.h.

◆ cbegin()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
const_iterator slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::cbegin ( ) const
inline

Definition at line 244 of file slot.h.

◆ cend()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
const_iterator slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::cend ( ) const
inline

Definition at line 245 of file slot.h.

◆ clear()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
void slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::clear ( )
inline

Definition at line 251 of file slot.h.

◆ emplace()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
template<class... Args>
slot_id slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::emplace ( Args &&...  args)
inline

Definition at line 222 of file slot.h.

◆ emplace_extended()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
template<class U , class... Args>
slot_id slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::emplace_extended ( Args &&...  args)
inline

Definition at line 230 of file slot.h.

◆ empty()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
bool slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::empty ( ) const
inline

Definition at line 254 of file slot.h.

◆ end()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
iterator slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::end ( )
inline

Definition at line 243 of file slot.h.

◆ erase() [1/2]

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
iterator slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::erase ( const_iterator  begin,
const_iterator  end 
)
inline

Definition at line 240 of file slot.h.

◆ erase() [2/2]

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
iterator slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::erase ( const_iterator  position)
inline

Definition at line 239 of file slot.h.

◆ find() [1/2]

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
const_iterator slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::find ( slot_id  index) const
inlinenoexcept

Definition at line 267 of file slot.h.

◆ find() [2/2]

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
iterator slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::find ( slot_id  index)
inlinenoexcept

Definition at line 256 of file slot.h.

◆ lock()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
void slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::lock ( )
inline

Definition at line 180 of file slot.h.

◆ locked()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
bool slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::locked ( ) const
inlinenoexcept

Definition at line 203 of file slot.h.

◆ pending_empty()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
bool slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::pending_empty ( ) const
inline

Definition at line 253 of file slot.h.

◆ pending_size()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
size_type slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::pending_size ( ) const
inline

Definition at line 249 of file slot.h.

◆ push() [1/2]

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
slot_id slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::push ( const value_type value)
inline

Definition at line 205 of file slot.h.

◆ push() [2/2]

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
slot_id slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::push ( value_type &&  value)
inline

Definition at line 213 of file slot.h.

◆ total_size()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
size_type slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::total_size ( ) const
inline

Definition at line 250 of file slot.h.

◆ try_lock()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
bool slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::try_lock ( )
inline

Definition at line 179 of file slot.h.

◆ unlock()

template<class T , class IDGenerator = std::size_t, class FlagType = bool, class Allocator = std::allocator<std::function<T>>>
void slimsig::slot_list< T, IDGenerator, FlagType, Allocator >::unlock ( )
inline

Definition at line 183 of file slot.h.


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