OpenTTD Source 20241224-master-gf74b0cf984
|
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. | |
Public Member Functions inherited from PoolBase | |
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 |
Name of this pool. | |
size_t | size |
Current allocated size. | |
size_t | first_free |
No item with index lower than this is free (doesn't say anything about this one!) | |
size_t | first_unused |
This and all higher indexes are free (doesn't say anything about first_unused-1 !) | |
size_t | items |
Number of used indexes (non-nullptr) | |
bool | cleaning |
True if cleaning pool (deleting all items) | |
Titem ** | data |
Pointer to array of pointers to Titem. | |
std::vector< BitmapStorage > | used_bitmap |
Bitmap of used indices. | |
Data Fields inherited from PoolBase | |
const PoolType | type |
Type of this pool. | |
Static Public Attributes | |
static constexpr size_t | MAX_SIZE = Tmax_size |
Make template parameter accessible from outside. | |
static constexpr size_t | BITMAP_SIZE = std::numeric_limits<BitmapStorage>::digits |
Private Member Functions | |
void * | AllocateItem (size_t size, size_t index) |
void | ResizeFor (size_t index) |
size_t | FindFirstFree () |
void * | GetNew (size_t size) |
void * | GetNew (size_t size, size_t index) |
void | FreeItem (size_t index) |
Private Attributes | |
AllocCache * | alloc_cache |
Cache of freed pointers. | |
Static Private Attributes | |
static const size_t | NO_FREE_ITEM = MAX_UVALUE(size_t) |
Constant to indicate we can't allocate any more items. | |
Additional Inherited Members | |
Static Public Member Functions inherited from PoolBase | |
static PoolVector * | GetPools () |
Function used to access the vector of all pools. | |
static void | Clean (PoolType) |
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 |
Tmax_size | Maximum size of the pool |
Tpool_type | Type of this pool |
Tcache | Whether to perform 'alloc' caching, i.e. don't actually free/malloc just reuse the memory |
Tzero | Whether to zero the memory |
Definition at line 80 of file pool_type.hpp.
using Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::BitmapStorage = size_t |
Definition at line 86 of file pool_type.hpp.
|
inline |
Tests whether we can allocate 'n' items.
n | number of items we want to allocate |
Definition at line 133 of file pool_type.hpp.
|
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 112 of file pool_type.hpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::first_unused.
Referenced by StoryBookWindow::GetSelPage(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::IsValidID().
|
inline |
Tests whether given index can be used to get valid (non-nullptr) Titem.
index | index to examine |
Definition at line 123 of file pool_type.hpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::Get().
Referenced by StoryBookWindow::GetSelPage(), StoryBookWindow::IsFirstPageSelected(), StoryBookWindow::IsLastPageSelected(), StoryBookWindow::OnInvalidateData(), StoryBookWindow::SelectNextPage(), and StoryBookWindow::SelectPrevPage().
|
private |
Cache of freed pointers.
Definition at line 404 of file pool_type.hpp.
|
staticconstexpr |
Definition at line 87 of file pool_type.hpp.
bool Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::cleaning |
True if cleaning pool (deleting all items)
Definition at line 98 of file pool_type.hpp.
Titem** Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::data |
Pointer to array of pointers to Titem.
Definition at line 100 of file pool_type.hpp.
size_t Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::first_free |
No item with index lower than this is free (doesn't say anything about this one!)
Definition at line 92 of file pool_type.hpp.
size_t Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::first_unused |
This and all higher indexes are free (doesn't say anything about first_unused-1 !)
Definition at line 93 of file pool_type.hpp.
Referenced by Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::Get().
size_t Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::items |
Number of used indexes (non-nullptr)
Definition at line 94 of file pool_type.hpp.
Referenced by CmdCreateStoryPage(), and CmdCreateStoryPageElement().
|
staticconstexpr |
Make template parameter accessible from outside.
Definition at line 84 of file pool_type.hpp.
Referenced by AfterLoadGame(), ServerNetworkAdminSocketHandler::AllowConnection(), ServerNetworkGameSocketHandler::AllowConnection(), GenerateTowns(), GetNumberOfIndustries(), SmallMapWindow::OnInit(), GenerateLandscapeWindow::OnQueryTextFinished(), PrepareUnload(), ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(), and GenerateLandscapeWindow::UpdateWidgetSize().
const char* const Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::name |
Name of this pool.
Definition at line 89 of file pool_type.hpp.
|
staticprivate |
Constant to indicate we can't allocate any more items.
Definition at line 392 of file pool_type.hpp.
size_t Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::size |
Current allocated size.
Definition at line 91 of file pool_type.hpp.
Referenced by Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::operator new(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::operator new().
std::vector<BitmapStorage> Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::used_bitmap |
Bitmap of used indices.
Definition at line 101 of file pool_type.hpp.