7 #ifndef Navigation_IterablePool_H
8 #define Navigation_IterablePool_H
18 template <
typename T>
class IterablePool;
24 class IterablePool_Iterator
29 KY_INLINE IterablePool_Iterator();
30 KY_INLINE IterablePool_Iterator(const IterablePool<T>* iterablePool) { Init(iterablePool); }
31 KY_INLINE
void Init(
const IterablePool<T>* iterablePool);
32 KY_INLINE
bool Next();
33 KY_INLINE T& Get()
const {
return *m_ptr; }
36 const IterablePool<T>* m_iterablePool;
57 typedef PoolHandle<T> Handle;
58 typedef PoolKey<T> Key;
59 typedef IterablePool_Iterator<T> Iterator;
65 OnNew(IterablePool* pool) : m_pool(pool), m_oldChunkCount(pool->GetChunkCount()) {}
66 Key Do(Key compactKey);
67 Handle Do(Handle handle);
74 explicit IterablePool(MemoryHeap* heap,
KyInt32 memStat, PoolChunkSize::Mode chunkSizeMode = PoolChunkSize::ByteSize,
KyUInt32 byteOrSlotCount = 256) :
75 m_basePool(heap, memStat, chunkSizeMode, byteOrSlotCount) {}
77 void Init(PoolChunkSize::Mode chunkSizeMode,
KyUInt32 byteOrSlotCount) { m_basePool.Init(chunkSizeMode, byteOrSlotCount); }
79 ~IterablePool() { Clear(); }
81 KY_INLINE
KyUInt32 GetCount()
const {
return m_basePool.GetCount(); }
86 KY_INLINE Key New_CompactKey() { OnNew onNew(
this);
return onNew.Do(m_basePool.New_CompactKey()); }
87 KY_INLINE Key New_CompactKey(
const T& data) { OnNew onNew(
this);
return onNew.Do(m_basePool.New_CompactKey(data)); }
89 KY_INLINE
void New_CompactKeyAndPtr(Key& key, T*& ptr) { OnNew onNew(
this); m_basePool.New_CompactKeyAndPtr(key, ptr); onNew.Do(key); }
91 KY_INLINE
const T& Get(Key key)
const {
return m_basePool.Get(key); }
92 KY_INLINE T& Get(Key key) {
return m_basePool.Get(key); }
94 KY_INLINE
void Delete(Key key) { m_basePool.Delete(key); m_bitField.UnsetBit(GetGlobalIdx(key)); }
97 KY_INLINE Handle New_Handle() { OnNew onNew(
this);
return onNew.Do(m_basePool.New_Handle()); }
98 KY_INLINE Handle New_Handle(
const T& data) { OnNew onNew(
this);
return onNew.Do(m_basePool.New_Handle(data)); }
99 KY_INLINE
void Delete(
const Handle& handle) { m_basePool.Delete(handle); m_bitField.UnsetBit(GetGlobalIdx(handle)); }
102 KY_INLINE T* New_Ptr() { OnNew onNew(
this);
return onNew.Do(m_basePool.New_Ptr()); }
103 KY_INLINE T* New_Ptr(
const T& data) { OnNew onNew(
this);
return onNew.Do(m_basePool.New_Ptr()); }
104 KY_INLINE
void Delete(T* ptr) { m_basePool.Delete(ptr); m_bitField.UnsetBit(GetGlobalIdx(ptr)); }
107 KY_INLINE Key Handle2CompactKey(
const Handle& h)
const {
return m_basePool.Handle2CompactKey(h); }
108 KY_INLINE Handle CompactKey2Handle(Key key)
const {
return m_basePool.CompactKey2Handle(key); }
110 KY_INLINE
KyUInt32 GetChunkCount()
const {
return m_basePool.GetChunkCount(); }
111 KY_INLINE
KyUInt32 GetNbSlotsByChunk()
const {
return m_basePool.GetNbSlotsByChunk(); }
113 KY_INLINE
KyUInt32 Ptr2ChunkIdx(T* ptr)
const {
return m_basePool.Ptr2ChunkIdx(ptr); }
114 KY_INLINE
KyUInt32 Ptr2IdxInChunk(
KyUInt32 chunkIdx, T* ptr)
const {
return m_basePool.Ptr2IdxInChunk(chunkIdx, ptr); }
116 KY_INLINE T& Get(
KyUInt32 chunkIdx,
KyUInt32 idxInChunk)
const {
return m_basePool.Get(chunkIdx, idxInChunk); }
118 KY_INLINE
KyUInt32 GetGlobalIdx(
const Handle& handle) {
return m_basePool.GetGlobalIdx(handle); }
119 KY_INLINE
KyUInt32 GetGlobalIdx(Key key) {
return m_basePool.GetGlobalIdx(key); }
120 KY_INLINE
KyUInt32 GetGlobalIdx(T* ptr) {
return m_basePool.GetGlobalIdx(ptr); }
123 KY_INLINE
bool Next(Iterator& it)
const;
134 #endif // Navigation_IterablePool_H
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36