Nui
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
Nui::SelectablesRegistry< T > Class Template Reference

This container associates items with an id and allows for individual items to be "selected", which removes them from the container and stores them in a separate container. More...

#include <selectables_registry.hpp>

Classes

class  ConstIterator
 
struct  ItemWithId
 Wrapper around items that associates them with an id. More...
 
class  Iterator
 
class  IteratorBase
 Iterator that ignores items that are selected. More...
 
struct  RawRangeWrap
 
struct  SelectionResult
 

Public Types

using IdType = std::size_t
 Id type used to identify items. More...
 
using ItemContainerType = std::vector< ItemWithId >
 Type of the container that stores the items. More...
 
using IteratorType = Iterator< typename ItemContainerType::iterator >
 
using ConstIteratorType = ConstIterator< typename ItemContainerType::const_iterator >
 

Public Member Functions

 SelectablesRegistry ()=default
 
 SelectablesRegistry (const SelectablesRegistry &)=default
 
 SelectablesRegistry (SelectablesRegistry &&)=default
 
SelectablesRegistryoperator= (const SelectablesRegistry &)=default
 
SelectablesRegistryoperator= (SelectablesRegistry &&)=default
 
 ~SelectablesRegistry ()=default
 
IdType append (T const &element)
 Append an item to the container. More...
 
IdType append (T &&element)
 Append an item to the container. More...
 
template<typename... Args>
IdType emplace (Args &&... args)
 Emplace an item to the container. More...
 
IteratorType erase (IdType id)
 Erase/Remove an item from the container. More...
 
std::optional< T > pop (IdType id)
 Erase/Remove an item from the container and return it. More...
 
SelectionResult select (IdType id)
 Select an item. More...
 
std::size_t deselectAll (std::invocable< ItemWithId const & > auto const &callback)
 Deselects all items. More...
 
bool deselect (IdType id, std::invocable< ItemWithId const & > auto const &callback)
 Deselects item with id. More...
 
void clear ()
 
IteratorType get (IdType id)
 Get iterator to item with id. More...
 
ConstIteratorType get (IdType id) const
 Get iterator to item with id. More...
 
auto const & operator[] (IdType id) const
 Returns item by id. More...
 
auto & operator[] (IdType id)
 Returns item by id. More...
 
IteratorType begin ()
 Returns iterator to first unselected item or end. More...
 
ConstIteratorType begin () const
 Returns iterator to first unselected item or end. More...
 
ConstIteratorType cbegin () const
 Returns iterator to first unselected item or end. More...
 
IteratorType end ()
 Returns end iterator. More...
 
ConstIteratorType end () const
 Returns end iterator. More...
 
ConstIteratorType cend () const
 Returns end iterator. More...
 
bool empty () const
 Returns whether the container is empty. More...
 
std::size_t size () const
 Returns the amount of items in the container. More...
 
ItemContainerType::iterator rawBegin ()
 Returns an iterator to the underlying container. More...
 
ItemContainerType::iterator rawEnd ()
 Returns an iterator to the underlying container. More...
 
ItemContainerType::const_iterator rawBegin () const
 Returns a const iterator to the underlying container. More...
 
ItemContainerType::const_iterator rawConstBegin () const
 Returns a const iterator to the underlying container. More...
 
ItemContainerType::const_iterator rawEnd () const
 Returns a const iterator to the underlying container. More...
 
ItemContainerType::const_iterator rawConstEnd () const
 Returns a const iterator to the underlying container. More...
 
RawRangeWrap< SelectablesRegistry< T > * > rawRange ()
 Helper for range based for loops. More...
 
RawRangeWrap< SelectablesRegistry< T > const * > rawRange () const
 Helper for range based for loops. More...
 

Static Public Attributes

constexpr static auto invalidId = std::numeric_limits<IdType>::max()
 Invalid id value. More...
 

Detailed Description

template<typename T>
class Nui::SelectablesRegistry< T >

This container associates items with an id and allows for individual items to be "selected", which removes them from the container and stores them in a separate container.

This allows for efficient iteration over the selected items. Selected items can be reinserted into the container via deselect (or not when the deselect callback returns false).

Template Parameters
TType of the items to store.

Member Typedef Documentation

◆ ConstIteratorType

template<typename T >
using Nui::SelectablesRegistry< T >::ConstIteratorType = ConstIterator<typename ItemContainerType::const_iterator>

◆ IdType

template<typename T >
using Nui::SelectablesRegistry< T >::IdType = std::size_t

Id type used to identify items.

◆ ItemContainerType

template<typename T >
using Nui::SelectablesRegistry< T >::ItemContainerType = std::vector<ItemWithId>

Type of the container that stores the items.

◆ IteratorType

template<typename T >
using Nui::SelectablesRegistry< T >::IteratorType = Iterator<typename ItemContainerType::iterator>

Constructor & Destructor Documentation

◆ SelectablesRegistry() [1/3]

template<typename T >
Nui::SelectablesRegistry< T >::SelectablesRegistry ( )
default

◆ SelectablesRegistry() [2/3]

template<typename T >
Nui::SelectablesRegistry< T >::SelectablesRegistry ( const SelectablesRegistry< T > &  )
default

◆ SelectablesRegistry() [3/3]

template<typename T >
Nui::SelectablesRegistry< T >::SelectablesRegistry ( SelectablesRegistry< T > &&  )
default

◆ ~SelectablesRegistry()

template<typename T >
Nui::SelectablesRegistry< T >::~SelectablesRegistry ( )
default

Member Function Documentation

◆ append() [1/2]

template<typename T >
IdType Nui::SelectablesRegistry< T >::append ( T &&  element)
inline

Append an item to the container.

Parameters
elementA new item to append.
Returns
IdType The id of the new item.

◆ append() [2/2]

template<typename T >
IdType Nui::SelectablesRegistry< T >::append ( T const &  element)
inline

Append an item to the container.

Parameters
elementA new item to append.
Returns
IdType The id of the new item.

◆ begin() [1/2]

template<typename T >
IteratorType Nui::SelectablesRegistry< T >::begin ( )
inline

Returns iterator to first unselected item or end.

◆ begin() [2/2]

template<typename T >
ConstIteratorType Nui::SelectablesRegistry< T >::begin ( ) const
inline

Returns iterator to first unselected item or end.

◆ cbegin()

template<typename T >
ConstIteratorType Nui::SelectablesRegistry< T >::cbegin ( ) const
inline

Returns iterator to first unselected item or end.

◆ cend()

template<typename T >
ConstIteratorType Nui::SelectablesRegistry< T >::cend ( ) const
inline

Returns end iterator.

◆ clear()

template<typename T >
void Nui::SelectablesRegistry< T >::clear ( )
inline

◆ deselect()

template<typename T >
bool Nui::SelectablesRegistry< T >::deselect ( IdType  id,
std::invocable< ItemWithId const & > auto const &  callback 
)
inline

Deselects item with id.

Will reinsert item when callback returns true.

Parameters
idid of the item to deselect
callbackcallback to execute on the item
Returns
true Deselected and reinserted item
false Either did not find item or item was not reinserted

◆ deselectAll()

template<typename T >
std::size_t Nui::SelectablesRegistry< T >::deselectAll ( std::invocable< ItemWithId const & > auto const &  callback)
inline

Deselects all items.

Will reinsert items when callback returns true.

Parameters
callbackcallback to execute on each item.
Returns
std::size_t Amount of reinserted elements.

◆ emplace()

template<typename T >
template<typename... Args>
IdType Nui::SelectablesRegistry< T >::emplace ( Args &&...  args)
inline

Emplace an item to the container.

Template Parameters
ArgsTypes of the arguments to forward to the constructor of the item.
Parameters
argsArguments to forward to the constructor of the item.
Returns
IdType The id of the new item.

◆ empty()

template<typename T >
bool Nui::SelectablesRegistry< T >::empty ( ) const
inline

Returns whether the container is empty.

◆ end() [1/2]

template<typename T >
IteratorType Nui::SelectablesRegistry< T >::end ( )
inline

Returns end iterator.

◆ end() [2/2]

template<typename T >
ConstIteratorType Nui::SelectablesRegistry< T >::end ( ) const
inline

Returns end iterator.

◆ erase()

template<typename T >
IteratorType Nui::SelectablesRegistry< T >::erase ( IdType  id)
inline

Erase/Remove an item from the container.

Parameters
idId of the item to erase.
Returns
IteratorType Iterator to the next item.

◆ get() [1/2]

template<typename T >
IteratorType Nui::SelectablesRegistry< T >::get ( IdType  id)
inline

Get iterator to item with id.

Parameters
idId of the item to get.
Returns
IteratorType Iterator to the item.

◆ get() [2/2]

template<typename T >
ConstIteratorType Nui::SelectablesRegistry< T >::get ( IdType  id) const
inline

Get iterator to item with id.

Parameters
idId of the item to get.
Returns
ConstIteratorType Iterator to the item.

◆ operator=() [1/2]

template<typename T >
SelectablesRegistry& Nui::SelectablesRegistry< T >::operator= ( const SelectablesRegistry< T > &  )
default

◆ operator=() [2/2]

template<typename T >
SelectablesRegistry& Nui::SelectablesRegistry< T >::operator= ( SelectablesRegistry< T > &&  )
default

◆ operator[]() [1/2]

template<typename T >
auto& Nui::SelectablesRegistry< T >::operator[] ( IdType  id)
inline

Returns item by id.

Parameters
idId of the item to get.
Returns
auto& Reference to the item.

◆ operator[]() [2/2]

template<typename T >
auto const& Nui::SelectablesRegistry< T >::operator[] ( IdType  id) const
inline

Returns item by id.

Parameters
idId of the item to get.
Returns
auto const& Reference to the item.

◆ pop()

template<typename T >
std::optional<T> Nui::SelectablesRegistry< T >::pop ( IdType  id)
inline

Erase/Remove an item from the container and return it.

Parameters
idId of the item to get and erase.
Returns
std::optional<T> The erased item.

◆ rawBegin() [1/2]

template<typename T >
ItemContainerType::iterator Nui::SelectablesRegistry< T >::rawBegin ( )
inline

Returns an iterator to the underlying container.

◆ rawBegin() [2/2]

template<typename T >
ItemContainerType::const_iterator Nui::SelectablesRegistry< T >::rawBegin ( ) const
inline

Returns a const iterator to the underlying container.

◆ rawConstBegin()

template<typename T >
ItemContainerType::const_iterator Nui::SelectablesRegistry< T >::rawConstBegin ( ) const
inline

Returns a const iterator to the underlying container.

◆ rawConstEnd()

template<typename T >
ItemContainerType::const_iterator Nui::SelectablesRegistry< T >::rawConstEnd ( ) const
inline

Returns a const iterator to the underlying container.

◆ rawEnd() [1/2]

template<typename T >
ItemContainerType::iterator Nui::SelectablesRegistry< T >::rawEnd ( )
inline

Returns an iterator to the underlying container.

◆ rawEnd() [2/2]

template<typename T >
ItemContainerType::const_iterator Nui::SelectablesRegistry< T >::rawEnd ( ) const
inline

Returns a const iterator to the underlying container.

◆ rawRange() [1/2]

template<typename T >
RawRangeWrap<SelectablesRegistry<T>*> Nui::SelectablesRegistry< T >::rawRange ( )
inline

Helper for range based for loops.

Returns
RawRangeWrap

◆ rawRange() [2/2]

template<typename T >
RawRangeWrap<SelectablesRegistry<T> const*> Nui::SelectablesRegistry< T >::rawRange ( ) const
inline

Helper for range based for loops.

Returns
RawRangeWrap

◆ select()

template<typename T >
SelectionResult Nui::SelectablesRegistry< T >::select ( IdType  id)
inline

Select an item.

Parameters
idThe id of the item to select.
Returns
SelectionResult The result of the selection.

◆ size()

template<typename T >
std::size_t Nui::SelectablesRegistry< T >::size ( ) const
inline

Returns the amount of items in the container.

Member Data Documentation

◆ invalidId

template<typename T >
constexpr static auto Nui::SelectablesRegistry< T >::invalidId = std::numeric_limits<IdType>::max()
staticconstexpr

Invalid id value.


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