61 virtual void CleanPool() = 0;
68 PoolBase(
const PoolBase &other);
82 template <
class Titem,
typename Tindex,
size_t Tgrowth_step,
size_t Tmax_size, PoolType Tpool_type = PT_NORMAL,
bool Tcache = false,
bool Tzero = true>
85 assert_compile((uint64)(Tmax_size - 1) >> 8 *
sizeof(Tindex) == 0);
102 Pool(
const char *name);
111 inline Titem *
Get(
size_t index)
113 assert(index < this->first_unused);
114 return this->data[index];
124 return index < this->first_unused && this->
Get(index) != NULL;
134 bool ret = this->items <= Tmax_size - n;
136 this->checked = ret ? n : 0;
145 template <struct Pool<Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero> *Tpool>
155 inline void *
operator new(
size_t size)
157 return Tpool->GetNew(size);
165 inline void operator delete(
void *p)
167 if (p == NULL)
return;
168 Titem *pn = (Titem *)p;
169 assert(pn == Tpool->Get(pn->index));
170 Tpool->FreeItem(pn->index);
183 return Tpool->GetNew(size, index);
194 inline void *
operator new(
size_t size,
void *ptr)
196 for (
size_t i = 0; i < Tpool->first_unused; i++) {
203 assert(ptr != Tpool->data[i]);
218 return Tpool->CanAllocate(n);
227 return Tpool->cleaning;
237 return Tpool->IsValidID(index);
246 static inline Titem *
Get(
size_t index)
248 return Tpool->Get(index);
259 return index < Tpool->first_unused ? Tpool->Get(index) : NULL;
269 return Tpool->first_unused;
306 void *AllocateItem(
size_t size,
size_t index);
307 void ResizeFor(
size_t index);
308 size_t FindFirstFree();
310 void *GetNew(
size_t size);
311 void *GetNew(
size_t size,
size_t index);
313 void FreeItem(
size_t index);
316 #define FOR_ALL_ITEMS_FROM(type, iter, var, start) \ 317 for (size_t iter = start; var = NULL, iter < type::GetPoolSize(); iter++) \ 318 if ((var = type::Get(iter)) != NULL) 320 #define FOR_ALL_ITEMS(type, iter, var) FOR_ALL_ITEMS_FROM(type, iter, var, 0) size_t first_unused
This and all higher indexes are free (doesn't say anything about first_unused-1 !) ...
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Simple vector class that allows allocating an item without the need to copy this->data needlessly...
static Titem * Get(size_t index)
Returns Titem with given index.
static PoolVector * GetPools()
Function used to access the vector of all pools.
bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
Base class for base of all pools.
Tindex index
Index of this pool item.
AllocCache * alloc_cache
Cache of freed pointers.
Simple vector template class.
Normal pool containing game objects.
Type (helpers) for enums.
T * Append(uint to_add=1)
Append an item and return it.
static const size_t MAX_SIZE
Make template parameter accessible from outside.
static void PostDestructor(size_t index)
Dummy function called after destructor of each member.
static size_t GetPoolSize()
Returns first unused index.
Titem * Get(size_t index)
Returns Titem with given index.
static const size_t NO_FREE_ITEM
Constant to indicate we can't allocate any more items.
PoolBase(PoolType pt)
Constructor registers this object in the pool vector.
Helper struct to cache 'freed' PoolItems so we do not need to allocate them again.
bool cleaning
True if cleaning pool (deleting all items)
NewGRF or other data, that is not reset together with normal pools.
Titem ** data
Pointer to array of pointers to Titem.
size_t items
Number of used indexes (non-NULL)
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
AllocCache * next
The next in our 'cache'.
Base class for all PoolItems.
Base class for all pools.
size_t first_free
No item with index lower than this is free (doesn't say anything about this one!) ...
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
PoolType
Various types of a pool.
static size_t GetNumItems()
Returns number of valid items in the pool.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
bool CanAllocate(size_t n=1)
Tests whether we can allocate 'n' items.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
size_t size
Current allocated size.
SmallVector< struct PoolBase *, 4 > PoolVector
Vector of pointers to PoolBase.
const char *const name
Name of this pool.
const PoolType type
Type of this pool.
virtual void CleanPool()
Virtual method that deletes all items in the pool.