OpenTTD Source 20250312-master-gcdcc6b491d
|
Base class for all pools. More...
#include <pool_type.hpp>
Data Structures | |
struct | AllocCache |
Helper struct to cache 'freed' PoolItems so we do not need to allocate them again. More... | |
struct | IterateWrapper |
struct | IterateWrapperFiltered |
struct | PoolItem |
Base class for all PoolItems. More... | |
struct | PoolIterator |
Iterator to iterate all valid T of a pool. More... | |
struct | PoolIteratorFiltered |
Iterator to iterate all valid T of a pool. More... | |
Public Types | |
using | BitmapStorage = size_t |
Public Member Functions | |
Pool (const char *name) | |
void | CleanPool () override |
Virtual method that deletes all items in the pool. | |
Titem * | Get (size_t index) |
Returns Titem with given index. | |
bool | IsValidID (size_t index) |
Tests whether given index can be used to get valid (non-nullptr) Titem. | |
bool | CanAllocate (size_t n=1) |
Tests whether we can allocate 'n' items. | |
![]() | |
PoolBase (PoolType pt) | |
Constructor registers this object in the pool vector. | |
virtual | ~PoolBase () |
Destructor removes this object from the pool vector and deletes the vector itself if this was the last item removed. | |
Data Fields | |
const char *const | name = nullptr |
Name of this pool. | |
size_t | first_free = 0 |
No item with index lower than this is free (doesn't say anything about this one!) | |
size_t | first_unused = 0 |
This and all higher indexes are free (doesn't say anything about first_unused-1 !) | |
size_t | items = 0 |
Number of used indexes (non-nullptr) | |
bool | cleaning = false |
True if cleaning pool (deleting all items) | |
std::vector< Titem * > | data {} |
Pointers to Titem. | |
std::vector< BitmapStorage > | used_bitmap {} |
Bitmap of used indices. | |
![]() | |
const PoolType | type |
Type of this pool. | |
Static Public Attributes | |
static constexpr size_t | MAX_SIZE = Tindex::End().base() |
Make template parameter accessible from outside. | |
static constexpr size_t | BITMAP_SIZE = std::numeric_limits<BitmapStorage>::digits |
Static Private Member Functions | |
static constexpr size_t | GetRawIndex (size_t index) |
template<typename T > requires std::is_base_of_v<PoolIDBase, T> | |
static constexpr size_t | GetRawIndex (const T &index) |
Private Attributes | |
AllocCache * | alloc_cache = nullptr |
Cache of freed pointers. | |
std::allocator< uint8_t > | allocator {} |
Static Private Attributes | |
static const size_t | NO_FREE_ITEM = std::numeric_limits<size_t>::max() |
Constant to indicate we can't allocate any more items. | |
Additional Inherited Members | |
![]() | |
static PoolVector * | GetPools () |
Function used to access the vector of all pools. | |
static void | Clean (PoolTypes) |
Clean all pools of given type. | |
Base class for all pools.
Titem | Type of the class/struct that is going to be pooled |
Tindex | Type of the index for this pool |
Tgrowth_step | Size of growths; if the pool is full increase the size by this amount |
Tpool_type | Type of this pool |
Tcache | Whether to perform 'alloc' caching, i.e. don't actually deallocated/allocate just reuse the memory |
Definition at line 133 of file pool_type.hpp.
using Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::BitmapStorage = size_t |
Definition at line 137 of file pool_type.hpp.
|
inline |
Definition at line 153 of file pool_type.hpp.
|
inline |
Tests whether we can allocate 'n' items.
n | number of items we want to allocate |
Definition at line 183 of file pool_type.hpp.
References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::MAX_SIZE.
|
overridevirtual |
Virtual method that deletes all items in the pool.
Implements PoolBase.
Referenced by AfterLoadStoryBook(), ResetNewGRFData(), and SetupEngines().
|
inline |
Returns Titem with given index.
index | of item to get |
Definition at line 162 of file pool_type.hpp.
References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::data, and Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::first_unused.
Referenced by Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::IsValidID().
|
inlinestaticconstexprprivate |
Definition at line 466 of file pool_type.hpp.
|
inlinestaticconstexprprivate |
Definition at line 464 of file pool_type.hpp.
|
inline |
Tests whether given index can be used to get valid (non-nullptr) Titem.
index | index to examine |
Definition at line 173 of file pool_type.hpp.
References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::Get().
|
private |
Cache of freed pointers.
Definition at line 452 of file pool_type.hpp.
|
private |
Definition at line 453 of file pool_type.hpp.
|
staticconstexpr |
Definition at line 138 of file pool_type.hpp.
bool Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::cleaning = false |
True if cleaning pool (deleting all items)
Definition at line 148 of file pool_type.hpp.
std::vector<Titem *> Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::data {} |
Pointers to Titem.
Definition at line 150 of file pool_type.hpp.
Referenced by Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::Get().
size_t Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::first_free = 0 |
No item with index lower than this is free (doesn't say anything about this one!)
Definition at line 142 of file pool_type.hpp.
size_t Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::first_unused = 0 |
This and all higher indexes are free (doesn't say anything about first_unused-1 !)
Definition at line 143 of file pool_type.hpp.
Referenced by Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::Get().
size_t Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::items = 0 |
Number of used indexes (non-nullptr)
Definition at line 144 of file pool_type.hpp.
|
staticconstexpr |
Make template parameter accessible from outside.
Definition at line 135 of file pool_type.hpp.
Referenced by AfterLoadGame(), ServerNetworkGameSocketHandler::AllowConnection(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::CanAllocate(), GenerateTowns(), GetNumberOfIndustries(), SmallMapWindow::OnInit(), GenerateLandscapeWindow::OnQueryTextFinished(), PrepareUnload(), ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(), and GenerateLandscapeWindow::UpdateWidgetSize().
const char* const Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::name = nullptr |
Name of this pool.
Definition at line 140 of file pool_type.hpp.
|
staticprivate |
Constant to indicate we can't allocate any more items.
Definition at line 440 of file pool_type.hpp.
std::vector<BitmapStorage> Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::used_bitmap {} |
Bitmap of used indices.
Definition at line 151 of file pool_type.hpp.