3#include <Foundation/Memory/AllocatorWrapper.h>
4#include <Foundation/Types/Id.h>
16template <
typename IdType,
typename ValueType>
20 using IndexType =
typename IdType::StorageType;
21 using TypeOfId = IdType;
40 const ValueType&
Value()
const;
54 IndexType m_CurrentIndex;
55 IndexType m_CurrentCount;
89 void Reserve(IndexType capacity);
101 IdType
Insert(
const ValueType& value);
104 IdType
Insert(ValueType&& value);
107 bool Remove(
const IdType
id, ValueType* out_pOldValue =
nullptr);
110 bool TryGetValue(
const IdType
id, ValueType& out_value)
const;
113 bool TryGetValue(
const IdType
id, ValueType*& out_pValue)
const;
116 const ValueType&
operator[](
const IdType
id)
const;
128 bool Contains(
const IdType
id)
const;
145 CAPACITY_ALIGNMENT = 16
157 IndexType m_Capacity;
159 IndexType m_FreelistEnqueue;
160 IndexType m_FreelistDequeue;
164 void SetCapacity(IndexType uiCapacity);
165 void InitializeFreelist(IndexType uiStart, IndexType uiEnd);
169template <
typename IdType,
typename ValueType,
typename AllocatorWrapper = plDefaultAllocatorWrapper>
183#include <Foundation/Containers/Implementation/IdTable_inl.h>
Base class for all memory allocators.
Definition Allocator.h:23
Const iterator.
Definition IdTable.h:25
bool IsValid() const
Checks whether this iterator points to a valid element.
Definition IdTable_inl.h:20
const ValueType & Value() const
Returns the 'value' of the element that this iterator points to.
Definition IdTable_inl.h:46
bool operator==(const typename plIdTableBase< IdType, ValueType >::ConstIterator &it2) const
Checks whether the two iterators point to the same element.
Definition IdTable_inl.h:26
void Next()
Advances the iterator to the next element in the map. The iterator will not be valid anymore,...
Definition IdTable_inl.h:52
void operator++()
Shorthand for 'Next'.
Definition IdTable_inl.h:65
IdType Id() const
Returns the 'id' of the element that this iterator points to.
Definition IdTable_inl.h:40
bool operator!=(const typename plIdTableBase< IdType, ValueType >::ConstIterator &it2) const
Checks whether the two iterators point to the same element.
Definition IdTable_inl.h:33
Implementation of an id mapping table which stores id/value pairs.
Definition IdTable.h:18
~plIdTableBase()
Destructor.
Definition IdTable_inl.h:113
IndexType GetCount() const
Returns the number of active entries in the table.
Definition IdTable_inl.h:168
const ValueType & operator[](const IdType id) const
Returns the value to the given id. Does bounds checks in debug builds.
Definition IdTable_inl.h:291
bool TryGetValue(const IdType id, ValueType &out_value) const
Returns if an entry with the given id was found and if found writes out the corresponding value to ou...
Definition IdTable_inl.h:267
void Clear()
Clears the table.
Definition IdTable_inl.h:180
void Reserve(IndexType capacity)
Expands the table so it can at least store the given capacity.
Definition IdTable_inl.h:149
Iterator GetIterator()
Returns an Iterator to the very first element.
Definition IdTable_inl.h:335
const ValueType & GetValueUnchecked(const IndexType index) const
Returns the value at the given index. Does bounds checks in debug builds but does not check for stale...
Definition IdTable_inl.h:314
bool Contains(const IdType id) const
Returns if the table contains an entry corresponding to the given id.
Definition IdTable_inl.h:328
void operator=(const plIdTableBase< IdType, ValueType > &rhs)
Copies the data from another table into this one.
Definition IdTable_inl.h:128
plIdTableBase(plAllocator *pAllocator)
Creates an empty id-table. Does not allocate any data yet.
Definition IdTable_inl.h:89
bool IsFreelistValid() const
Returns whether the internal free-list is valid. For testing purpose only.
Definition IdTable_inl.h:353
bool Remove(const IdType id, ValueType *out_pOldValue=nullptr)
Removes the entry with the given id. Returns if an entry was removed and optionally writes out the ol...
Definition IdTable_inl.h:237
IdType Insert(const ValueType &value)
Inserts the value into the table and returns the corresponding id.
Definition IdTable_inl.h:201
bool IsEmpty() const
Returns true, if the table does not contain any elements.
Definition IdTable_inl.h:174
plAllocator * GetAllocator() const
Returns the allocator that is used by this instance.
Definition IdTable_inl.h:347
Iterator with write access.
Definition IdTable.h:60
ValueType & Value()
Returns the 'value' of the element that this iterator points to.
Definition IdTable_inl.h:80