Nui
|
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 | |
SelectablesRegistry & | operator= (const SelectablesRegistry &)=default |
SelectablesRegistry & | operator= (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... | |
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).
T | Type of the items to store. |
using Nui::SelectablesRegistry< T >::ConstIteratorType = ConstIterator<typename ItemContainerType::const_iterator> |
using Nui::SelectablesRegistry< T >::IdType = std::size_t |
Id type used to identify items.
using Nui::SelectablesRegistry< T >::ItemContainerType = std::vector<ItemWithId> |
Type of the container that stores the items.
using Nui::SelectablesRegistry< T >::IteratorType = Iterator<typename ItemContainerType::iterator> |
|
default |
|
default |
|
default |
|
default |
|
inline |
Append an item to the container.
element | A new item to append. |
|
inline |
Append an item to the container.
element | A new item to append. |
|
inline |
Returns iterator to first unselected item or end.
|
inline |
Returns iterator to first unselected item or end.
|
inline |
Returns iterator to first unselected item or end.
|
inline |
Returns end iterator.
|
inline |
|
inline |
Deselects item with id.
Will reinsert item when callback returns true.
id | id of the item to deselect |
callback | callback to execute on the item |
|
inline |
Deselects all items.
Will reinsert items when callback returns true.
callback | callback to execute on each item. |
|
inline |
Emplace an item to the container.
Args | Types of the arguments to forward to the constructor of the item. |
args | Arguments to forward to the constructor of the item. |
|
inline |
Returns whether the container is empty.
|
inline |
Returns end iterator.
|
inline |
Returns end iterator.
|
inline |
Erase/Remove an item from the container.
id | Id of the item to erase. |
|
inline |
Get iterator to item with id.
id | Id of the item to get. |
|
inline |
Get iterator to item with id.
id | Id of the item to get. |
|
default |
|
default |
|
inline |
Returns item by id.
id | Id of the item to get. |
|
inline |
Returns item by id.
id | Id of the item to get. |
|
inline |
Erase/Remove an item from the container and return it.
id | Id of the item to get and erase. |
|
inline |
Returns an iterator to the underlying container.
|
inline |
Returns a const iterator to the underlying container.
|
inline |
Returns a const iterator to the underlying container.
|
inline |
Returns a const iterator to the underlying container.
|
inline |
Returns an iterator to the underlying container.
|
inline |
Returns a const iterator to the underlying container.
|
inline |
Helper for range based for loops.
|
inline |
Helper for range based for loops.
|
inline |
Select an item.
id | The id of the item to select. |
|
inline |
Returns the amount of items in the container.
|
staticconstexpr |
Invalid id value.