OpenTTD Source 20260208-master-g43af8e94d0
Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool > Struct Template Reference

Base class for all PoolItems. More...

#include <pool_type.hpp>

Public Types

typedef struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > Pool
 Type of the pool this item is going to be part of.

Public Member Functions

 PoolItem (Tindex index)
 Construct the item.
void * operator new (size_t)=delete
 Do not use new PoolItem, but rather PoolItem::Create.
void operator delete (void *p, size_t size)
 Marks Titem as free.
void * operator new (size_t size, Tindex index)=delete
 Do not use new (index) PoolItem(...), but rather PoolItem::CreateAtIndex(index, ...).
void * operator new (size_t, void *ptr)=delete
 Do not use new (address) PoolItem(...).

Static Public Member Functions

template<typename T = Titem, typename... Targs>
static T * Create (Targs &&... args)
 Creates a new T-object in the associated pool.
template<typename T = Titem, typename... Targs>
static T * CreateAtIndex (Tindex index, Targs &&... args)
 Creates a new T-object in the associated pool.
static bool CanAllocateItem (size_t n=1)
 Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function().
static bool CleaningPool ()
 Returns current state of pool cleaning - yes or no.
static bool IsValidID (auto index)
 Tests whether given index can be used to get valid (non-nullptr) Titem.
static Titem * Get (auto index)
 Returns Titem with given index.
static Titem * GetIfValid (auto index)
 Returns Titem with given index.
static size_t GetPoolSize ()
 Returns first unused index.
static size_t GetNumItems ()
 Returns number of valid items in the pool.
static void PostDestructor (size_t index)
 Dummy function called after destructor of each member.
static Pool::IterateWrapper< Titem > Iterate (size_t from=0)
 Returns an iterable ensemble of all valid Titem.

Data Fields

const Tindex index
 Index of this pool item.

Detailed Description

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >

Base class for all PoolItems.

Template Parameters
TpoolThe pool this item is going to be part of

Definition at line 290 of file pool_type.hpp.

Member Typedef Documentation

◆ Pool

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
typedef struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::Pool

Type of the pool this item is going to be part of.

Definition at line 300 of file pool_type.hpp.

Constructor & Destructor Documentation

◆ PoolItem()

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::PoolItem ( Tindex index)
inline

Construct the item.

Parameters
indexThe index of this PoolItem in the pool.

Definition at line 297 of file pool_type.hpp.

References index.

Member Function Documentation

◆ CanAllocateItem()

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
bool Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::CanAllocateItem ( size_t n = 1)
inlinestatic

Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function().

Tests whether we can allocate 'n' items

Parameters
nnumber of items we want to allocate
Returns
true if 'n' items can be allocated

Definition at line 360 of file pool_type.hpp.

◆ CleaningPool()

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
bool Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::CleaningPool ( )
inlinestatic

Returns current state of pool cleaning - yes or no.

Returns
true iff we are cleaning the pool now

Definition at line 369 of file pool_type.hpp.

◆ Create()

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
template<typename T = Titem, typename... Targs>
T * Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::Create ( Targs &&... args)
inlinestatic

Creates a new T-object in the associated pool.

Parameters
argsThe arguments to the constructor.
Returns
The created object.

Definition at line 333 of file pool_type.hpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::data, and index.

◆ CreateAtIndex()

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
template<typename T = Titem, typename... Targs>
T * Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::CreateAtIndex ( Tindex index,
Targs &&... args )
inlinestatic

Creates a new T-object in the associated pool.

Parameters
indexThe to allocate the object at.
argsThe arguments to the constructor.
Returns
The created object.

Definition at line 347 of file pool_type.hpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::data, and index.

◆ Get()

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
Titem * Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::Get ( auto index)
inlinestatic

Returns Titem with given index.

Parameters
indexof item to get
Returns
pointer to Titem
Precondition
index < this->first_unused

Definition at line 390 of file pool_type.hpp.

References index.

◆ GetIfValid()

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
Titem * Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::GetIfValid ( auto index)
inlinestatic

Returns Titem with given index.

Parameters
indexof item to get
Returns
pointer to Titem
Note
returns nullptr for invalid index

Definition at line 401 of file pool_type.hpp.

References index.

◆ GetNumItems()

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
size_t Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::GetNumItems ( )
inlinestatic

Returns number of valid items in the pool.

Returns
number of valid items in the pool

Definition at line 420 of file pool_type.hpp.

◆ GetPoolSize()

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
size_t Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::GetPoolSize ( )
inlinestatic

Returns first unused index.

Useful when iterating over all pool items.

Returns
first unused index

Definition at line 411 of file pool_type.hpp.

◆ IsValidID()

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
bool Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::IsValidID ( auto index)
inlinestatic

Tests whether given index can be used to get valid (non-nullptr) Titem.

Parameters
indexindex to examine
Returns
true if PoolItem::Get(index) will return non-nullptr pointer

Definition at line 379 of file pool_type.hpp.

References index.

◆ Iterate()

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
Pool::IterateWrapper< Titem > Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::Iterate ( size_t from = 0)
inlinestatic

Returns an iterable ensemble of all valid Titem.

Parameters
fromindex of the first Titem to consider
Returns
an iterable ensemble of all valid Titem

Definition at line 439 of file pool_type.hpp.

◆ operator delete()

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
void Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::operator delete ( void * p,
size_t size )
inline

Marks Titem as free.

Its memory is released

Parameters
pmemory to free
sizeThe size that was allocated during allocation.
Note
the item has to be allocated in the pool!

Definition at line 311 of file pool_type.hpp.

◆ PostDestructor()

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
void Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::PostDestructor ( size_t index)
inlinestatic

Dummy function called after destructor of each member.

If you want to use it, override it in PoolItem's subclass.

Parameters
indexindex of deleted item
Note
when this function is called, PoolItem::Get(index) == nullptr.
it's called only when !CleaningPool()

Definition at line 432 of file pool_type.hpp.

References index.

Field Documentation

◆ index

template<class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type = PoolType::Normal, bool Tcache = false>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache > * Tpool>
const Tindex Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index

Index of this pool item.

Definition at line 291 of file pool_type.hpp.

Referenced by Create(), CreateAtIndex(), Get(), GetIfValid(), IsValidID(), operator new(), PoolItem(), and PostDestructor().


The documentation for this struct was generated from the following file: