51 template <
typename... Args>
54 ,
item{T{std::forward<Args>(args)...}}
81 constexpr static auto invalidId = std::numeric_limits<IdType>::max();
90 template <
typename WrappedIterator>
150 return !(lhs == rhs);
156 for (std::size_t i = 0; i < offset && tmp !=
endIterator_; ++i)
171 for (std::size_t i = 0; i < offset && *
this !=
endIterator_; ++i)
177 for (std::size_t i = 0; i < offset && *
this !=
beginIterator_; ++i)
192 template <
typename WrappedIterator>
207 throw std::runtime_error{
"Dereferencing end iterator"};
214 throw std::runtime_error{
"Dereferencing end iterator"};
219 template <
typename WrappedIterator>
230 throw std::runtime_error{
"Dereferencing end iterator"};
237 throw std::runtime_error{
"Dereferencing end iterator"};
261 items_.push_back(
ItemWithId{id_, std::optional<T>{element}});
278 items_.push_back(
ItemWithId{id_, std::optional<T>{std::move(element)}});
294 template <
typename... Args>
314 const auto p = findItem(
id);
315 if (p == std::end(items_))
321 auto result = condense();
322 return {result, items_.begin(), items_.end()};
333 const auto p = findItem(
id);
334 if (p == std::end(items_))
337 const auto result = std::move(p->item);
365 const auto iter = findItem(
id);
366 if (iter == std::end(items_))
367 return {
nullptr,
false,
false};
368 if (!iter->item.has_value())
369 return {
nullptr,
true,
true};
373 const auto selectedIter = selected_.insert(std::move(*iter)).first;
380 .alreadySelected =
false,
390 std::size_t
deselectAll(std::invocable<ItemWithId const&>
auto const& callback)
392 std::size_t result = 0;
393 for (
auto const& selected : selected_)
395 auto const id = selected.id;
396 if (callback(selected))
398 auto entry = findItem(
id);
399 if (entry != std::end(items_))
406 entry->item = std::move(
const_cast<ItemWithId&
>(selected).item);
425 auto const iter = selected_.find(
ItemWithId{id, std::nullopt});
426 if (iter == std::end(selected_))
431 auto entry = findItem(
id);
432 if (entry != std::end(items_))
439 selected_.erase(iter);
440 if (selected_.empty())
461 auto iter = findItem(
id);
462 if (iter == std::end(items_))
464 return IteratorType{iter, items_.begin(), items_.end()};
475 auto iter = findItem(
id);
476 if (iter == std::end(items_))
508 return {items_.begin(), items_.begin(), items_.end()};
516 return {items_.begin(), items_.begin(), items_.end()};
524 return {items_.cbegin(), items_.begin(), items_.end()};
532 return {items_.end(), items_.begin(), items_.end()};
540 return {items_.end(), items_.begin(), items_.end()};
548 return {items_.cend(), items_.begin(), items_.end()};
556 return itemCount_ == 0;
572 return items_.begin();
578 typename ItemContainerType::iterator
rawEnd()
586 typename ItemContainerType::const_iterator
rawBegin()
const
588 return items_.begin();
596 return items_.cbegin();
602 typename ItemContainerType::const_iterator
rawEnd()
const
612 return items_.cend();
615 template <
typename RegistryPtr>
619 typename ItemContainerType::iterator
begin()
const
623 typename ItemContainerType::iterator
end()
const
627 typename ItemContainerType::iterator
cbegin()
const
631 typename ItemContainerType::iterator
cend()
const
658 typename ItemContainerType::iterator findItem(
IdType id)
661 std::lower_bound(std::begin(items_), std::end(items_),
id, [](
auto const& lhs,
auto const& rhs) {
665 if (p == std::end(items_) || p->id !=
id)
666 return std::end(items_);
669 typename ItemContainerType::const_iterator findItem(
IdType id)
const
672 std::lower_bound(std::begin(items_), std::end(items_),
id, [](
auto const& lhs,
auto const& rhs) {
676 if (p == std::end(items_) || p->id !=
id)
677 return std::end(items_);
683 if (selected_.empty() && itemCount_ < (items_.size() / 2))
689 [](
auto const& item) {
694 return std::end(items_);
700 std::set<ItemWithId> selected_{};
Definition selectables_registry.hpp:194
auto const & operator*() const
Definition selectables_registry.hpp:204
auto const * operator->() const
Definition selectables_registry.hpp:211
ConstIterator(typename ItemContainerType::iterator iter)
Definition selectables_registry.hpp:200
Iterator that ignores items that are selected.
Definition selectables_registry.hpp:92
bool isEnd() const
Definition selectables_registry.hpp:181
WrappedIterator beginIterator_
Definition selectables_registry.hpp:188
IteratorBase(IteratorBase const &)=default
IteratorBase operator+(std::size_t offset) const
Definition selectables_registry.hpp:153
friend bool operator!=(const IteratorBase &lhs, const IteratorBase &rhs)
Definition selectables_registry.hpp:148
IteratorBase(WrappedIterator wrapped, WrappedIterator begin, WrappedIterator end)
Definition selectables_registry.hpp:94
friend bool operator==(const IteratorBase &lhs, const IteratorBase &rhs)
Definition selectables_registry.hpp:143
IteratorBase & operator++()
Definition selectables_registry.hpp:111
IteratorBase & operator--()
Definition selectables_registry.hpp:126
WrappedIterator endIterator_
Definition selectables_registry.hpp:189
IteratorBase & operator=(IteratorBase const &)=default
IteratorBase & operator=(IteratorBase &&)=default
IteratorBase & operator+=(std::size_t offset)
Definition selectables_registry.hpp:169
IteratorBase operator-(std::size_t offset) const
Definition selectables_registry.hpp:161
WrappedIterator wrappedIterator_
Definition selectables_registry.hpp:187
IteratorBase(IteratorBase &&)=default
IteratorBase operator--(int)
Definition selectables_registry.hpp:136
IteratorBase operator++(int)
Definition selectables_registry.hpp:119
IteratorBase & operator-=(std::size_t offset)
Definition selectables_registry.hpp:175
Definition selectables_registry.hpp:221
auto & operator*()
Definition selectables_registry.hpp:227
auto * operator->()
Definition selectables_registry.hpp:234
This container associates items with an id and allows for individual items to be "selected",...
Definition selectables_registry.hpp:31
ConstIteratorType cend() const
Returns end iterator.
Definition selectables_registry.hpp:546
ItemContainerType::const_iterator rawConstEnd() const
Returns a const iterator to the underlying container.
Definition selectables_registry.hpp:610
auto & operator[](IdType id)
Returns item by id.
Definition selectables_registry.hpp:498
auto const & operator[](IdType id) const
Returns item by id.
Definition selectables_registry.hpp:487
ItemContainerType::const_iterator rawBegin() const
Returns a const iterator to the underlying container.
Definition selectables_registry.hpp:586
SelectablesRegistry & operator=(SelectablesRegistry &&)=default
IteratorType begin()
Returns iterator to first unselected item or end.
Definition selectables_registry.hpp:506
IteratorType erase(IdType id)
Erase/Remove an item from the container.
Definition selectables_registry.hpp:312
ConstIteratorType begin() const
Returns iterator to first unselected item or end.
Definition selectables_registry.hpp:514
IteratorType end()
Returns end iterator.
Definition selectables_registry.hpp:530
ConstIteratorType end() const
Returns end iterator.
Definition selectables_registry.hpp:538
SelectablesRegistry(SelectablesRegistry &&)=default
ItemContainerType::const_iterator rawConstBegin() const
Returns a const iterator to the underlying container.
Definition selectables_registry.hpp:594
IdType emplace(Args &&... args)
Emplace an item to the container.
Definition selectables_registry.hpp:295
std::size_t IdType
Id type used to identify items.
Definition selectables_registry.hpp:34
std::size_t deselectAll(std::invocable< ItemWithId const & > auto const &callback)
Deselects all items.
Definition selectables_registry.hpp:390
ItemContainerType::iterator rawBegin()
Returns an iterator to the underlying container.
Definition selectables_registry.hpp:570
ConstIteratorType cbegin() const
Returns iterator to first unselected item or end.
Definition selectables_registry.hpp:522
bool deselect(IdType id, std::invocable< ItemWithId const & > auto const &callback)
Deselects item with id.
Definition selectables_registry.hpp:423
SelectionResult select(IdType id)
Select an item.
Definition selectables_registry.hpp:363
SelectablesRegistry(const SelectablesRegistry &)=default
RawRangeWrap< SelectablesRegistry< T > const * > rawRange() const
Helper for range based for loops.
Definition selectables_registry.hpp:652
ItemContainerType::iterator rawEnd()
Returns an iterator to the underlying container.
Definition selectables_registry.hpp:578
IdType append(T &&element)
Append an item to the container.
Definition selectables_registry.hpp:276
SelectablesRegistry()=default
RawRangeWrap< SelectablesRegistry< T > * > rawRange()
Helper for range based for loops.
Definition selectables_registry.hpp:642
std::vector< ItemWithId > ItemContainerType
Type of the container that stores the items.
Definition selectables_registry.hpp:78
static constexpr auto invalidId
Invalid id value.
Definition selectables_registry.hpp:81
bool empty() const
Returns whether the container is empty.
Definition selectables_registry.hpp:554
IteratorType get(IdType id)
Get iterator to item with id.
Definition selectables_registry.hpp:459
SelectablesRegistry & operator=(const SelectablesRegistry &)=default
ItemContainerType::const_iterator rawEnd() const
Returns a const iterator to the underlying container.
Definition selectables_registry.hpp:602
~SelectablesRegistry()=default
ConstIteratorType get(IdType id) const
Get iterator to item with id.
Definition selectables_registry.hpp:473
std::optional< T > pop(IdType id)
Erase/Remove an item from the container and return it.
Definition selectables_registry.hpp:331
IdType append(T const &element)
Append an item to the container.
Definition selectables_registry.hpp:259
void clear()
Definition selectables_registry.hpp:445
std::size_t size() const
Returns the amount of items in the container.
Definition selectables_registry.hpp:562
Definition file_dialog.hpp:6
Definition selectables_registry.hpp:18
Wrapper around items that associates them with an id.
Definition selectables_registry.hpp:40
ItemWithId(IdType id, std::optional< T > item)
Definition selectables_registry.hpp:60
ItemWithId & operator=(ItemWithId &&)=default
ItemWithId & operator=(ItemWithId const &)=default
std::optional< T > item
The item.
Definition selectables_registry.hpp:49
ItemWithId(IdType id, T item)
Definition selectables_registry.hpp:56
bool operator<(ItemWithId const &other) const
Compares the id of the item.
Definition selectables_registry.hpp:71
ItemWithId(IdType id, Detail::InplaceTag, Args &&... args)
Definition selectables_registry.hpp:52
ItemWithId(ItemWithId &&)=default
IdType id
Id of the item.
Definition selectables_registry.hpp:42
ItemWithId(ItemWithId const &)=default
Definition selectables_registry.hpp:617
RegistryPtr registry
Definition selectables_registry.hpp:618
ItemContainerType::iterator end() const
Definition selectables_registry.hpp:623
ItemContainerType::iterator cend() const
Definition selectables_registry.hpp:631
ItemContainerType::iterator begin() const
Definition selectables_registry.hpp:619
ItemContainerType::iterator cbegin() const
Definition selectables_registry.hpp:627
Definition selectables_registry.hpp:346
std::optional< T > * item
Pointer to the selected item (may be nullptr).
Definition selectables_registry.hpp:348
bool found
Whether the item was found.
Definition selectables_registry.hpp:351
bool alreadySelected
Whether the item was already selected.
Definition selectables_registry.hpp:354