GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
Registry.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_CORE_DATA_REGISTRY_HPP
5#define GREM_CORE_DATA_REGISTRY_HPP
6
8
14
15#include <compare> // std::strong_ordering
16#include <cstddef> // std::size_t
17#include <iterator> // std::reverse_iterator, std::random_access_iterator_tag
18#include <stdexcept> // std::length_error, std::out_of_range
19#include <type_traits> // std::conditional_t
20#include <utility> // std::move, std::forward, std::swap, std::exchange
21
22namespace grem {
23
24template <typename T, typename ElementID, typename Container>
25class Registry; // Forward declaration.
26
32template <typename Self>
34public:
35 using GREM_private_DerivedFromRegistryElementIDBaseTag = void;
36
37 using Identifier = uint32_t;
38 using Index = uint16_t;
39 using Generation = uint16_t;
40 using Flags = uint8_t;
41
43 static constexpr Index MAX_INDEX = Limits<Index>::MAX - 1;
44 static constexpr Generation MAX_GENERATION = (1 << 14) - 1;
45 static constexpr Flags ALL_FLAGS = 0b11;
46
50 constexpr RegistryElementIDBase() noexcept = default;
51
61 constexpr RegistryElementIDBase(Index index, Generation generation, Flags flags)
62 : value((uint32_t{flags} << 30) | ((uint32_t{generation} & 0x3FFF) << 16) | uint32_t{index}) {}
63
70 constexpr explicit operator bool() const noexcept {
71 return *this != RegistryElementIDBase{};
72 }
73
80 [[nodiscard]] constexpr Identifier getIdentifier() const noexcept {
81 return value;
82 }
83
89 [[nodiscard]] constexpr Index getIndex() const noexcept {
90 return static_cast<Index>(value & uint32_t{Limits<Index>::MAX});
91 }
92
98 [[nodiscard]] constexpr Generation getGeneration() const noexcept {
99 return static_cast<Generation>((value >> 16) & MAX_GENERATION);
100 }
101
107 [[nodiscard]] constexpr Flags getFlags() const noexcept {
108 return static_cast<Flags>(value >> 30);
109 }
110
118 [[nodiscard]] constexpr bool operator==(const RegistryElementIDBase& other) const noexcept = default;
119
127 [[nodiscard]] constexpr std::strong_ordering operator<=>(const RegistryElementIDBase& other) const noexcept = default;
128
137 [[nodiscard]] friend constexpr bool operator==(const Self& a, const Self& b) noexcept {
138 return *static_cast<const RegistryElementIDBase*>(&a) == *static_cast<const RegistryElementIDBase*>(&b);
139 }
140
149 [[nodiscard]] friend constexpr std::strong_ordering operator<=>(const Self& a, const Self& b) noexcept {
150 return *static_cast<const RegistryElementIDBase*>(&a) <=> *static_cast<const RegistryElementIDBase*>(&b);
151 }
152
153private:
154 uint32_t value = Limits<uint32_t>::MAX;
155};
156
163
174template <typename T, typename ElementID = RegistryElementID, typename Container = ArrayList<T>>
175class Registry {
176private:
177 using Index = typename RegistryElementID::Index;
178 using Generation = typename RegistryElementID::Generation;
179 using Flags = typename RegistryElementID::Flags;
180
181 static constexpr Index MAX_INDEX = RegistryElementID::MAX_INDEX;
182 static constexpr Flags ALL_FLAGS = RegistryElementID::ALL_FLAGS;
183
184 template <bool Const>
185 class Iterator {
186 private:
187 using UnderlyingIterator = std::conditional_t<Const, typename Container::const_iterator, typename Container::iterator>;
188
189 public:
190 using difference_type = ptrdiff_t;
193 using iterator_category = std::random_access_iterator_tag;
194
195 struct pointer {
196 reference ref;
197
198 [[nodiscard]] constexpr reference* operator->() noexcept {
199 return &ref;
200 }
201 };
202
203 Iterator() noexcept = default;
204
205 constexpr Iterator(const ElementID* elementID, UnderlyingIterator it) noexcept
206 : elementID(elementID)
207 , it(std::move(it)) {}
208
209 constexpr operator Iterator<true>() const noexcept requires(!Const) {
210 return Iterator<true>{elementID, it};
211 }
212
213 [[nodiscard]] constexpr reference operator*() const {
214 return reference{*elementID, *it};
215 }
216
217 [[nodiscard]] constexpr pointer operator->() const {
218 return pointer{**this};
219 }
220
221 [[nodiscard]] constexpr reference operator[](difference_type n) const {
222 return *(*this + n);
223 }
224
225 constexpr Iterator& operator++() {
226 ++elementID;
227 ++it;
228 return *this;
229 }
230
231 constexpr Iterator& operator--() {
232 --elementID;
233 --it;
234 return *this;
235 }
236
237 constexpr Iterator operator++(int) {
238 Iterator old = *this;
239 ++*this;
240 return old;
241 }
242
243 constexpr Iterator operator--(int) {
244 Iterator old = *this;
245 --*this;
246 return old;
247 }
248
249 constexpr Iterator& operator+=(difference_type n) {
250 elementID += n;
251 it += n;
252 return *this;
253 }
254
255 constexpr Iterator& operator-=(difference_type n) {
256 elementID -= n;
257 it -= n;
258 return *this;
259 }
260
261 [[nodiscard]] friend constexpr Iterator operator+(Iterator a, difference_type b) {
262 return a += b;
263 }
264
265 [[nodiscard]] friend constexpr Iterator operator+(difference_type a, Iterator b) {
266 return b += a;
267 }
268
269 [[nodiscard]] friend constexpr Iterator operator-(Iterator a, difference_type b) {
270 return a -= b;
271 }
272
273 [[nodiscard]] friend constexpr difference_type operator-(Iterator a, Iterator b) {
274 GREM_ASSERT(a.elementID - b.elementID == a.it - b.it);
275 return static_cast<difference_type>(a.it - b.it);
276 }
277
278 [[nodiscard]] friend constexpr bool operator==(Iterator a, Iterator b) {
279 GREM_ASSERT(a.elementID - b.elementID == a.it - b.it);
280 return a.it == b.it;
281 }
282
283 [[nodiscard]] friend constexpr auto operator<=>(Iterator a, Iterator b) {
284 GREM_ASSERT(a.elementID - b.elementID == a.it - b.it);
285 return a.it <=> b.it;
286 }
287
288 private:
289 const ElementID* elementID;
290 UnderlyingIterator it;
291 };
292
293public:
294 using iterator = Iterator<false>;
295 using const_iterator = Iterator<true>;
296 using value_type = typename iterator::value_type;
297 using allocator_type = typename Container::allocator_type;
298 using size_type = typename Container::size_type;
299 using difference_type = typename iterator::difference_type;
300 using reference = typename iterator::reference;
301 using const_reference = typename const_iterator::reference;
302 using pointer = typename iterator::pointer;
303 using const_pointer = typename const_iterator::pointer;
304 using reverse_iterator = std::reverse_iterator<iterator>;
305 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
306
307 constexpr Registry() noexcept(noexcept(allocator_type()))
309
310 constexpr explicit Registry(const allocator_type& allocator) noexcept
311 : slots(allocator)
312 , elementIDs(allocator)
313 , elements(allocator) {}
314
315 constexpr ~Registry() = default;
316
317 constexpr Registry(const Registry& other)
318 : Registry(other, std::allocator_traits<allocator_type>::select_on_container_copy_construction(other.get_allocator())) {}
319
320 constexpr Registry(Registry&& other) noexcept
321 : Registry(std::move(other), other.get_allocator()) {}
322
323 constexpr Registry(const Registry& other, const allocator_type& allocator)
324 : nextAvailableSlotIndex(other.nextAvailableSlotIndex)
325 , slots(other.slots, allocator)
326 , elementIDs(other.elementIDs, allocator)
327 , elements(other.elements, allocator) {}
328
329 constexpr Registry(Registry&& other, const allocator_type& allocator) noexcept // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
330 : nextAvailableSlotIndex(std::exchange(other.nextAvailableSlotIndex, Index{0}))
331 , slots(std::move(other.slots), allocator)
332 , elementIDs(std::move(other.elementIDs), allocator)
333 , elements(std::move(other.elements), allocator) {}
334
335 constexpr Registry& operator=(const Registry& other) = default;
336 constexpr Registry& operator=(Registry&&) noexcept(
337 std::allocator_traits<
338 allocator_type>::propagate_on_container_move_assignment::value || // NOLINT(cppcoreguidelines-noexcept-move-operations, performance-noexcept-move-constructor)
339 std::allocator_traits<allocator_type>::is_always_equal::value) = default;
340
341 constexpr ElementID setFlags(ElementID key, ElementID::Flags newFlags) {
342 const Index slotIndex = key.getIndex();
343 if (slotIndex < slots.size() && (key.getGeneration() & 1) != 0) {
344 ElementID& slot = slots[slotIndex];
345 if (slot.getGeneration() == key.getGeneration()) {
346 const Index idIndex = slot.getIndex();
347 slot = ElementID{idIndex, key.getGeneration(), newFlags};
348 const ElementID newElementID{slotIndex, key.getGeneration(), newFlags};
349 GREM_ASSERT(elementIDs[idIndex].getGeneration() == key.getGeneration());
350 elementIDs[idIndex] = newElementID;
351 return newElementID;
352 }
353 }
354 return {};
355 }
356
357 [[nodiscard]] constexpr const Container& getElements() const noexcept {
358 return elements;
359 }
360
361 [[nodiscard]] constexpr allocator_type get_allocator() const noexcept {
362 return elements.get_allocator();
363 }
364
365 [[nodiscard]] constexpr T* data() noexcept requires(requires(Container c) { c.data(); }) {
366 return elements.data();
367 }
368
369 [[nodiscard]] constexpr const T* data() const noexcept requires(requires(const Container c) { c.data(); }) {
370 return elements.data();
371 }
372
373 [[nodiscard]] constexpr iterator begin() noexcept {
374 return iterator{elementIDs.data(), elements.begin()};
375 }
376
377 [[nodiscard]] constexpr const_iterator begin() const noexcept {
378 return const_iterator{elementIDs.data(), elements.begin()};
379 }
380
381 [[nodiscard]] constexpr const_iterator cbegin() const noexcept {
382 return begin();
383 }
384
385 [[nodiscard]] constexpr iterator end() noexcept {
386 return iterator{elementIDs.data() + size(), elements.end()};
387 }
388
389 [[nodiscard]] constexpr const_iterator end() const noexcept {
390 return const_iterator{elementIDs.data() + size(), elements.end()};
391 }
392
393 [[nodiscard]] constexpr const_iterator cend() const noexcept {
394 return end();
395 }
396
397 [[nodiscard]] constexpr reverse_iterator rbegin() noexcept {
398 return reverse_iterator{end()};
399 }
400
401 [[nodiscard]] constexpr const_reverse_iterator rbegin() const noexcept {
402 return const_reverse_iterator{end()};
403 }
404
405 [[nodiscard]] constexpr const_reverse_iterator crbegin() const noexcept {
406 return rbegin();
407 }
408
409 [[nodiscard]] constexpr reverse_iterator rend() noexcept {
410 return reverse_iterator{begin()};
411 }
412
413 [[nodiscard]] constexpr const_reverse_iterator rend() const noexcept {
415 }
416
417 [[nodiscard]] constexpr const_reverse_iterator crend() const noexcept {
418 return rend();
419 }
420
421 [[nodiscard]] constexpr bool empty() const noexcept {
422 return elements.empty();
423 }
424
425 [[nodiscard]] constexpr size_type size() const noexcept {
426 return elements.size();
427 }
428
429 [[nodiscard]] constexpr size_type max_size() const noexcept {
430 return min(min(slots.max_size(), elements.max_size()), static_cast<size_type>(static_cast<size_type>(MAX_INDEX) + 1));
431 }
432
433 [[nodiscard]] constexpr bool contains(ElementID key) const noexcept {
434 const Index slotIndex = key.getIndex();
435 return slotIndex < slots.size() && (key.getGeneration() & 1) != 0 && slots[slotIndex].getGeneration() == key.getGeneration();
436 }
437
438 [[nodiscard]] constexpr iterator find(ElementID key) noexcept {
439 if (contains(key)) {
440 return begin() + static_cast<difference_type>(slots[key.getIndex()].getIndex());
441 }
442 return end();
443 }
444
445 [[nodiscard]] constexpr const_iterator find(ElementID key) const noexcept {
446 if (contains(key)) {
447 return begin() + static_cast<difference_type>(slots[key.getIndex()].getIndex());
448 }
449 return end();
450 }
451
452 [[nodiscard]] constexpr ElementID id(size_type pos) const {
453 GREM_ASSERT(pos < elementIDs.size());
454 return elementIDs[pos];
455 }
456
457 [[nodiscard]] constexpr ElementID id(const_iterator pos) const {
458 const Index idIndex = static_cast<Index>(pos - cbegin());
459 GREM_ASSERT(idIndex < elementIDs.size());
460 return elementIDs[idIndex];
461 }
462
463 [[nodiscard]] constexpr T& at(ElementID key) {
464 if (const auto it = find(key); it != end()) {
465 return it->second;
466 }
467 throw std::out_of_range{"!contains(key)"};
468 }
469
470 [[nodiscard]] constexpr const T& at(ElementID key) const {
471 if (const auto it = find(key); it != end()) {
472 return it->second;
473 }
474 throw std::out_of_range{"!contains(key)"};
475 }
476
477 [[nodiscard]] constexpr T& operator[](ElementID key) {
478 const Index slotIndex = key.getIndex();
479 GREM_ASSERT(slotIndex < slots.size());
480 GREM_ASSERT(slots[slotIndex].getGeneration() == key.getGeneration());
481 return elements[slots[slotIndex].getIndex()];
482 }
483
484 [[nodiscard]] constexpr const T& operator[](ElementID key) const {
485 const Index slotIndex = key.getIndex();
486 GREM_ASSERT(slotIndex < slots.size());
487 GREM_ASSERT(slots[slotIndex].getGeneration() == key.getGeneration());
488 return elements[slots[slotIndex].getIndex()];
489 }
490
491 [[nodiscard]] constexpr reference at(size_type pos) {
492 if (pos >= size()) {
493 throw std::out_of_range{"pos >= size()"};
494 }
495 return *(begin() + static_cast<difference_type>(pos));
496 }
497
498 [[nodiscard]] constexpr const_reference at(size_type pos) const {
499 if (pos >= size()) {
500 throw std::out_of_range{"pos >= size()"};
501 }
502 return *(begin() + static_cast<difference_type>(pos));
503 }
504
505 [[nodiscard]] constexpr reference operator[](size_type pos) {
506 return *(begin() + static_cast<difference_type>(pos));
507 }
508
509 [[nodiscard]] constexpr const_reference operator[](size_type pos) const {
510 return *(begin() + static_cast<difference_type>(pos));
511 }
512
513 template <typename ColumnType>
514 [[nodiscard]] constexpr decltype(auto) column() requires(requires(Container c) { c.template column<ColumnType>(); }) {
515 return elements.template column<ColumnType>();
516 }
517
518 template <typename ColumnType>
519 [[nodiscard]] constexpr decltype(auto) column() const requires(requires(const Container c) { c.template column<ColumnType>(); }) {
520 return elements.template column<ColumnType>();
521 }
522
523 template <size_t ColumnIndex>
524 [[nodiscard]] constexpr decltype(auto) column() requires(requires(Container c) { c.template column<ColumnIndex>(); }) {
525 return elements.template column<ColumnIndex>();
526 }
527
528 template <size_t ColumnIndex>
529 [[nodiscard]] constexpr decltype(auto) column() const requires(requires(const Container c) { c.template column<ColumnIndex>(); }) {
530 return elements.template column<ColumnIndex>();
531 }
532
533 constexpr void reserve(size_type newCapacity) {
534 if (newCapacity > max_size()) {
535 throw std::length_error{"newCap > max_size()"};
536 }
537 slots.reserve(newCapacity);
538 elementIDs.reserve(newCapacity);
539 elements.reserve(newCapacity);
540 }
541
542 [[nodiscard]] constexpr size_type capacity() const noexcept {
543 return slots.capacity();
544 }
545
546 constexpr void shrink_to_fit() {
547 slots.shrink_to_fit();
548 elementIDs.shrink_to_fit();
549 elements.shrink_to_fit();
550 }
551
552 constexpr void clear() noexcept {
553 elements.clear();
554 elementIDs.clear();
555
556 // Make all generation entries available for reuse.
557 for (Index slotIndex = 0; slotIndex < slots.size(); ++slotIndex) {
558 const Generation generation = slots[slotIndex].getGeneration();
559 const Generation destroyedGeneration = generation + (generation & 1); // Make sure that the generation counter is even (marking invalid).
560 slots[slotIndex] = ElementID{static_cast<Index>(slotIndex + 1), destroyedGeneration, Flags{}};
561 }
562 nextAvailableSlotIndex = 0;
563 }
564
565 constexpr iterator insert(const T& value) {
566 return emplace(value);
567 }
568
569 constexpr iterator insert(T&& value) {
570 return emplace(std::move(value));
571 }
572
573 template <typename... Args>
574 constexpr iterator emplace(Args&&... args) {
575 return emplaceWithFlags(Flags{}, std::forward<Args>(args)...);
576 }
577
578 template <typename... Args>
579 constexpr iterator emplaceWithFlags(Flags flags, Args&&... args) {
580 GREM_ASSERT(elements.size() == elementIDs.size());
581
582 if (size() >= max_size()) {
583 throw std::length_error{"size() >= max_size()"};
584 }
585
586 const Index idIndex = static_cast<Index>(size());
587 ElementID& elementID = elementIDs.push_back_unspecified_value();
588
589 Index slotIndex = static_cast<Index>(slots.size());
590 Generation generation = 1;
591 if (nextAvailableSlotIndex >= slotIndex) {
592 GREM_ASSERT(nextAvailableSlotIndex == slotIndex);
593 GREM_ASSERT(slotIndex == idIndex);
594 try {
595 slots.push_back(ElementID{idIndex, generation, flags});
596 try {
597 elements.emplace_back(std::forward<Args>(args)...);
598 } catch (...) {
599 slots.pop_back();
600 throw;
601 }
602 ++nextAvailableSlotIndex;
603 } catch (...) {
604 elementIDs.pop_back();
605 throw;
606 }
607 } else {
608 try {
609 elements.emplace_back(std::forward<Args>(args)...);
610 } catch (...) {
611 elementIDs.pop_back();
612 throw;
613 }
614 slotIndex = nextAvailableSlotIndex;
615 nextAvailableSlotIndex = slots[slotIndex].getIndex();
616 // Note: The generation counter is incremented both on insertion and on removal.
617 // This means that you can identify which generation slots are invalid based on whether the generation is even (invalid) or odd (valid),
618 // and it also solves the problem of newly created elements' generations comparing equal to deleted elements' generations in previous copies of the registry.
619 // The downside is that it effectively cuts the range of generation indices in half, but since we have a whole 14 bits to work with, that should be fine for most use cases.
620 generation = static_cast<Generation>(slots[slotIndex].getGeneration() + 1);
621 slots[slotIndex] = ElementID{idIndex, generation, flags};
622 }
623
624 elementID = ElementID{slotIndex, generation, flags};
625 return begin() + static_cast<difference_type>(idIndex);
626 }
627
628 constexpr size_type erase(ElementID key) {
629 if (!contains(key)) {
630 return 0;
631 }
632 eraseImplementation(key.getIndex());
633 return 1;
634 }
635
637 return eraseImplementation(id(pos).getIndex());
638 }
639
640 constexpr void swap(Registry& other) noexcept(
641 noexcept(elements.swap(other.elements)) && noexcept(elementIDs.swap(other.elementIDs))) { // NOLINT(cppcoreguidelines-noexcept-swap, performance-noexcept-swap)
642 using std::swap;
643 swap(nextAvailableSlotIndex, other.nextAvailableSlotIndex);
644 swap(slots, other.slots);
645 swap(elementIDs, other.elementIDs);
646 swap(elements, other.elements);
647 }
648
649 template <typename Predicate>
650 friend constexpr size_type erase_if(Registry& c, Predicate predicate) {
651 const size_type oldSize = c.size();
652 iterator it = c.begin();
653 while (it != c.end()) {
654 if (predicate(*it)) {
655 it = c.erase(it);
656 } else {
657 ++it;
658 }
659 }
660 return oldSize - c.size();
661 }
662
663private:
664 using ElementIDAllocator = typename std::allocator_traits<allocator_type>::template rebind_alloc<ElementID>;
665
666 iterator eraseImplementation(Index slotIndex) {
667 GREM_ASSERT(!empty());
668 GREM_ASSERT(elements.size() == elementIDs.size());
669
670 // Move the last element's data to the destroyed element's index.
671 const Index idIndex = slots[slotIndex].getIndex();
672 const Generation generation = slots[slotIndex].getGeneration();
673 const Index lastIDIndex = static_cast<Index>(size() - 1);
674 const ElementID lastElementID = elementIDs[lastIDIndex];
675 const Index lastSlotIndex = lastElementID.getIndex();
676 if (lastSlotIndex != slotIndex) {
677 elements[idIndex] = std::move(elements[lastIDIndex]);
678 elementIDs[idIndex] = lastElementID;
679 slots[lastSlotIndex] = ElementID{idIndex, lastElementID.getGeneration(), lastElementID.getFlags()}; // Repoint the last element's slot to its new index.
680 }
681 elements.pop_back();
682 elementIDs.pop_back();
683
684 // Make the destroyed element's slot available for reuse.
685 slots[slotIndex] = ElementID{nextAvailableSlotIndex, static_cast<Generation>(generation + 1), Flags{}};
686 nextAvailableSlotIndex = slotIndex;
687
688 return begin() + static_cast<difference_type>(idIndex);
689 }
690
691 Index nextAvailableSlotIndex = 0;
694 Container elements;
695};
696
697template <typename ColumnType, typename T, typename ElementID, typename Container>
698[[nodiscard]] constexpr decltype(auto) column(Registry<T, ElementID, Container>& r) requires(requires(Container c) { c.template column<ColumnType>(); }) {
699 return r.template column<ColumnType>();
700}
701
702template <typename ColumnType, typename T, typename ElementID, typename Container>
703[[nodiscard]] constexpr decltype(auto) column(const Registry<T, ElementID, Container>& r) requires(requires(const Container c) { c.template column<ColumnType>(); }) {
704 return r.template column<ColumnType>();
705}
706
707template <size_t ColumnIndex, typename T, typename ElementID, typename Container>
708[[nodiscard]] constexpr decltype(auto) column(Registry<T, ElementID, Container>& r) requires(requires(Container c) { c.template column<ColumnIndex>(); }) {
709 return r.template column<ColumnIndex>();
710}
711
712template <size_t ColumnIndex, typename T, typename ElementID, typename Container>
713[[nodiscard]] constexpr decltype(auto) column(const Registry<T, ElementID, Container>& r) requires(requires(const Container c) { c.template column<ColumnIndex>(); }) {
714 return r.template column<ColumnIndex>();
715}
716
717} // namespace grem
718
719namespace grem::pmr {
720
721template <typename T, typename ElementID>
723
724} // namespace grem::pmr
725
726template <typename ElementID>
727requires(requires { typename ElementID::GREM_private_DerivedFromRegistryElementIDBaseTag; }) struct std::hash<ElementID> {
728 [[nodiscard]] std::size_t operator()(const ElementID& elementID) const {
729 return hasher(elementID.getIdentifier());
730 }
731
732private:
733 [[no_unique_address]] std::hash<typename grem::RegistryElementID::Identifier> hasher;
734};
735
736#endif
#define GREM_ASSERT(expression)
Definition assertions.hpp:77
Definition Buffer.hpp:28
constexpr Flags getFlags() const noexcept
Get the user-defined flags of the element.
Definition Registry.hpp:107
friend constexpr std::strong_ordering operator<=>(const Self &a, const Self &b) noexcept
Compare two handles.
Definition Registry.hpp:149
friend constexpr bool operator==(const Self &a, const Self &b) noexcept
Compare two handles for equality.
Definition Registry.hpp:137
constexpr Index getIndex() const noexcept
Get the index of the element's generation slot.
Definition Registry.hpp:89
static constexpr Index INVALID_INDEX
Reserved index value for an invalid element handle.
Definition Registry.hpp:42
uint8_t Flags
User-defined flags index type.
Definition Registry.hpp:40
constexpr bool operator==(const RegistryElementIDBase &other) const noexcept=default
Compare this handle to another for equality.
uint16_t Generation
Generation counter type.
Definition Registry.hpp:39
static constexpr Index MAX_INDEX
Maximum valid index value.
Definition Registry.hpp:43
constexpr std::strong_ordering operator<=>(const RegistryElementIDBase &other) const noexcept=default
Compare this handle to another.
static constexpr Generation MAX_GENERATION
Maximum valid generation counter value.
Definition Registry.hpp:44
uint32_t Identifier
Underlying value type.
Definition Registry.hpp:37
uint16_t Index
Index type.
Definition Registry.hpp:38
constexpr Identifier getIdentifier() const noexcept
Get a unique identifier for the underlying representation of the element handle.
Definition Registry.hpp:80
constexpr RegistryElementIDBase() noexcept=default
Construct an invalid element handle.
static constexpr Flags ALL_FLAGS
Maximum valid set of user-defined flags.
Definition Registry.hpp:45
constexpr Generation getGeneration() const noexcept
Get the generation counter value of the element.
Definition Registry.hpp:98
Tightly packed set of elements with stable IDs, supporting fast iteration as well as amortized O(1) i...
Definition Registry.hpp:175
constexpr const T & operator[](ElementID key) const
Definition Registry.hpp:484
constexpr ElementID id(size_type pos) const
Definition Registry.hpp:452
friend constexpr size_type erase_if(Registry &c, Predicate predicate)
Definition Registry.hpp:650
constexpr allocator_type get_allocator() const noexcept
Definition Registry.hpp:361
constexpr ElementID id(const_iterator pos) const
Definition Registry.hpp:457
constexpr Registry & operator=(const Registry &other)=default
constexpr iterator find(ElementID key) noexcept
Definition Registry.hpp:438
constexpr Registry(Registry &&other, const allocator_type &allocator) noexcept
Definition Registry.hpp:329
constexpr const Container & getElements() const noexcept
Definition Registry.hpp:357
constexpr size_type max_size() const noexcept
Definition Registry.hpp:429
constexpr Registry(Registry &&other) noexcept
Definition Registry.hpp:320
constexpr const_iterator begin() const noexcept
Definition Registry.hpp:377
constexpr decltype(auto) column()
Definition Registry.hpp:514
constexpr const_reference operator[](size_type pos) const
Definition Registry.hpp:509
constexpr size_type size() const noexcept
Definition Registry.hpp:425
typename iterator::difference_type difference_type
Definition Registry.hpp:299
constexpr iterator emplaceWithFlags(Flags flags, Args &&... args)
Definition Registry.hpp:579
constexpr bool contains(ElementID key) const noexcept
Definition Registry.hpp:433
constexpr const_iterator cbegin() const noexcept
Definition Registry.hpp:381
typename Container::allocator_type allocator_type
Definition Registry.hpp:297
constexpr ~Registry()=default
constexpr const_reverse_iterator rbegin() const noexcept
Definition Registry.hpp:401
constexpr void swap(Registry &other) noexcept(noexcept(elements.swap(other.elements)) &&noexcept(elementIDs.swap(other.elementIDs)))
Definition Registry.hpp:640
typename iterator::reference reference
Definition Registry.hpp:300
constexpr reverse_iterator rbegin() noexcept
Definition Registry.hpp:397
constexpr Registry(const Registry &other)
Definition Registry.hpp:317
typename const_iterator::reference const_reference
Definition Registry.hpp:301
constexpr Registry(const Registry &other, const allocator_type &allocator)
Definition Registry.hpp:323
constexpr const_reverse_iterator crend() const noexcept
Definition Registry.hpp:417
typename const_iterator::pointer const_pointer
Definition Registry.hpp:303
constexpr void reserve(size_type newCapacity)
Definition Registry.hpp:533
constexpr iterator begin() noexcept
Definition Registry.hpp:373
constexpr void shrink_to_fit()
Definition Registry.hpp:546
constexpr Registry() noexcept(noexcept(allocator_type()))
Definition Registry.hpp:307
constexpr bool empty() const noexcept
Definition Registry.hpp:421
constexpr iterator erase(const_iterator pos)
Definition Registry.hpp:636
constexpr reverse_iterator rend() noexcept
Definition Registry.hpp:409
constexpr const_iterator cend() const noexcept
Definition Registry.hpp:393
constexpr T * data() noexcept
Definition Registry.hpp:365
constexpr iterator insert(const T &value)
Definition Registry.hpp:565
constexpr void clear() noexcept
Definition Registry.hpp:552
constexpr decltype(auto) column() const
Definition Registry.hpp:519
constexpr const_reverse_iterator rend() const noexcept
Definition Registry.hpp:413
constexpr size_type capacity() const noexcept
Definition Registry.hpp:542
constexpr const T & at(ElementID key) const
Definition Registry.hpp:470
constexpr const_iterator end() const noexcept
Definition Registry.hpp:389
std::reverse_iterator< iterator > reverse_iterator
Definition Registry.hpp:304
constexpr const_reference at(size_type pos) const
Definition Registry.hpp:498
typename Container::size_type size_type
Definition Registry.hpp:298
constexpr decltype(auto) column()
Definition Registry.hpp:524
constexpr size_type erase(ElementID key)
Definition Registry.hpp:628
Iterator< false > iterator
Definition Registry.hpp:294
constexpr decltype(auto) column() const
Definition Registry.hpp:529
constexpr reference at(size_type pos)
Definition Registry.hpp:491
constexpr const_reverse_iterator crbegin() const noexcept
Definition Registry.hpp:405
constexpr Registry & operator=(Registry &&) noexcept(std::allocator_traits< allocator_type >::propagate_on_container_move_assignment::value||//NOLINT(cppcoreguidelines-noexcept-move-operations, performance-noexcept-move-constructor) std::allocator_traits< allocator_type >::is_always_equal::value)=default
typename iterator::value_type value_type
Definition Registry.hpp:296
Iterator< true > const_iterator
Definition Registry.hpp:295
constexpr reference operator[](size_type pos)
Definition Registry.hpp:505
constexpr const T * data() const noexcept
Definition Registry.hpp:369
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition Registry.hpp:305
constexpr iterator emplace(Args &&... args)
Definition Registry.hpp:574
constexpr iterator end() noexcept
Definition Registry.hpp:385
constexpr T & at(ElementID key)
Definition Registry.hpp:463
constexpr Registry(const allocator_type &allocator) noexcept
Definition Registry.hpp:310
constexpr const_iterator find(ElementID key) const noexcept
Definition Registry.hpp:445
constexpr ElementID setFlags(ElementID key, ElementID::Flags newFlags)
Definition Registry.hpp:341
constexpr iterator insert(T &&value)
Definition Registry.hpp:569
constexpr T & operator[](ElementID key)
Definition Registry.hpp:477
Definition concepts.hpp:106
Definition Allocation.hpp:554
grem::Registry< T, ElementID, pmr::ArrayList< T > > Registry
Definition Registry.hpp:722
Definition aliases.hpp:9
constexpr auto find(input_range auto &&range, const auto &value)
Definition algorithms.hpp:242
constexpr auto move(input_range auto &&range, auto outputIterator)
Definition algorithms.hpp:669
constexpr decltype(auto) column(Registry< T, ElementID, Container > &r)
Definition Registry.hpp:698
constexpr bool contains(input_range auto &&range, const auto &value)
Definition algorithms.hpp:299
GREM_ALWAYS_INLINE constexpr decltype(auto) min(A &&a, B &&b)
Get the smaller of two values, or the first value if they are equivalent.
Definition fundamentals.hpp:585
static constexpr T MAX
Definition fundamentals.hpp:29
Definition Pair.hpp:53
Opaque handle to a specific element in a Registry.
Definition Registry.hpp:160
constexpr RegistryElementIDBase() noexcept=default
Construct an invalid element handle.
Definition Registry.hpp:195
constexpr reference * operator->() noexcept
Definition Registry.hpp:198
reference ref
Definition Registry.hpp:196
std::size_t operator()(const ElementID &elementID) const
Definition Registry.hpp:728