# Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool > Struct Template Reference

Base class for all PoolItems. More...

`#include <pool_type.hpp>`

## Public Member Functions
FORCEINLINE void * | operator new (size_t size)
| Allocates space for new Titem.
FORCEINLINE void | operator delete (void *p)
| Marks Titem as free.
FORCEINLINE void * | operator new (size_t size, size_t index)
| Allocates space for new Titem with given index.
FORCEINLINE void * | operator new (size_t size, void *ptr)
| Allocates space for new Titem at given memory address.
## Static Public Member Functions
static FORCEINLINE bool | CanAllocateItem (size_t n=1)
| Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function().
static FORCEINLINE bool | CleaningPool ()
| Returns current state of pool cleaning - yes or no.
static FORCEINLINE bool | IsValidID (size_t index)
| Tests whether given index can be used to get valid (non-NULL) Titem.
static FORCEINLINE Titem * | Get (size_t index)
| Returs Titem with given index.
static FORCEINLINE Titem * | GetIfValid (size_t index)
| Returs Titem with given index.
static FORCEINLINE size_t | GetPoolSize ()
| Returns first unused index.
static FORCEINLINE size_t | GetNumItems ()
| Returns number of valid items in the pool.
static FORCEINLINE void | PostDestructor (size_t index)
| Dummy function called after destructor of each member.
## Data Fields
Tindex | index
| Index of this pool item.

## Detailed Description

### template<class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, bool Tcache = false, bool Tzero = true>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero > * Tpool>
struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >

Base class for all PoolItems.

Template Parameters:

  | Tpool | The pool this item is going to be part of

Definition at line 82 of file pool_type.hpp.

## Member Function Documentation

template<class Titem , typename Tindex , size_t Tgrowth_step, size_t Tmax_size, bool Tcache = false, bool Tzero = true>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero > * Tpool>

static FORCEINLINE bool Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::CanAllocateItem | ( | size_t | n = `1` | ) | `[inline, static]`

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

Tests whether we can allocate 'n' items

Parameters:

  | n | number of items we want to allocate

Returns:
  true if 'n' items can be allocated

Definition at line 151 of file pool_type.hpp.

template<class Titem , typename Tindex , size_t Tgrowth_step, size_t Tmax_size, bool Tcache = false, bool Tzero = true>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero > * Tpool>

static FORCEINLINE bool Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::CleaningPool | ( |  | ) | `[inline, static]`

Returns current state of pool cleaning - yes or no.

Returns:
  true iff we are cleaning the pool now

Definition at line 160 of file pool_type.hpp.

template<class Titem , typename Tindex , size_t Tgrowth_step, size_t Tmax_size, bool Tcache = false, bool Tzero = true>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero > * Tpool>

static FORCEINLINE Titem* Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::Get | ( | size_t | index | ) | `[inline, static]`

Returs Titem with given index.

Parameters:

  | index | of item to get

Returns:
  pointer to Titem

Precondition:
  index < this->first_unused

Reimplemented in SpecializedStation< T, Tis_waypoint >, SpecializedVehicle< T, Type >, SpecializedStation< Station, false >, SpecializedStation< Waypoint, true >, SpecializedVehicle< DisasterVehicle, VEH_DISASTER >, SpecializedVehicle< Ship, VEH_SHIP >, SpecializedVehicle< Train, VEH_TRAIN >, SpecializedVehicle< Aircraft, VEH_AIRCRAFT >, SpecializedVehicle< EffectVehicle, VEH_EFFECT >, and SpecializedVehicle< RoadVehicle, VEH_ROAD >.

Definition at line 181 of file pool_type.hpp.

template<class Titem , typename Tindex , size_t Tgrowth_step, size_t Tmax_size, bool Tcache = false, bool Tzero = true>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero > * Tpool>

static FORCEINLINE Titem* Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::GetIfValid | ( | size_t | index | ) | `[inline, static]`

Returs Titem with given index.

Parameters:

  | index | of item to get

Returns:
  pointer to Titem

Note:
  returns NULL for invalid index

Reimplemented in SpecializedStation< T, Tis_waypoint >, SpecializedVehicle< T, Type >, SpecializedStation< Station, false >, SpecializedStation< Waypoint, true >, SpecializedVehicle< DisasterVehicle, VEH_DISASTER >, SpecializedVehicle< Ship, VEH_SHIP >, SpecializedVehicle< Train, VEH_TRAIN >, SpecializedVehicle< Aircraft, VEH_AIRCRAFT >, SpecializedVehicle< EffectVehicle, VEH_EFFECT >, and SpecializedVehicle< RoadVehicle, VEH_ROAD >.

Definition at line 192 of file pool_type.hpp.

template<class Titem , typename Tindex , size_t Tgrowth_step, size_t Tmax_size, bool Tcache = false, bool Tzero = true>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero > * Tpool>

static FORCEINLINE size_t Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::GetNumItems | ( |  | ) | `[inline, static]`

Returns number of valid items in the pool.

Returns:
  number of valid items in the pool

Definition at line 211 of file pool_type.hpp.

template<class Titem , typename Tindex , size_t Tgrowth_step, size_t Tmax_size, bool Tcache = false, bool Tzero = true>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero > * Tpool>

static FORCEINLINE size_t Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::GetPoolSize | ( |  | ) | `[inline, static]`

Returns first unused index.

Useful when iterating over all pool items.

Returns:
  first unused index

Definition at line 202 of file pool_type.hpp.

template<class Titem , typename Tindex , size_t Tgrowth_step, size_t Tmax_size, bool Tcache = false, bool Tzero = true>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero > * Tpool>

static FORCEINLINE bool Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::IsValidID | ( | size_t | index | ) | `[inline, static]`

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

Parameters:

  | index | index to examine

Returns:
  true if PoolItem::Get(index) will return non-NULL pointer

Reimplemented in SpecializedStation< T, Tis_waypoint >, SpecializedVehicle< T, Type >, SpecializedStation< Station, false >, SpecializedStation< Waypoint, true >, SpecializedVehicle< DisasterVehicle, VEH_DISASTER >, SpecializedVehicle< Ship, VEH_SHIP >, SpecializedVehicle< Train, VEH_TRAIN >, SpecializedVehicle< Aircraft, VEH_AIRCRAFT >, SpecializedVehicle< EffectVehicle, VEH_EFFECT >, and SpecializedVehicle< RoadVehicle, VEH_ROAD >.

Definition at line 170 of file pool_type.hpp.

template<class Titem , typename Tindex , size_t Tgrowth_step, size_t Tmax_size, bool Tcache = false, bool Tzero = true>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero > * Tpool>

FORCEINLINE void Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::operator delete | ( | void * | p | ) | `[inline]`

Marks Titem as free.

Its memory is released

Parameters:

  | p | memory to free

Note:
  the item has to be allocated in the pool!

Definition at line 101 of file pool_type.hpp.

template<class Titem , typename Tindex , size_t Tgrowth_step, size_t Tmax_size, bool Tcache = false, bool Tzero = true>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero > * Tpool>

FORCEINLINE void* Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::operator new | ( | size_t | size,
|  | void * | ptr |
| ) |  |  | `[inline]`

Allocates space for new Titem at given memory address.

Parameters:

  | size | size of Titem
  | ptr | where are we allocating the item?

Returns:
  pointer to allocated memory (== ptr)

Note:
  use of this is strongly discouraged

Precondition:
  the memory must not be allocated in the Pool!

Definition at line 129 of file pool_type.hpp.

template<class Titem , typename Tindex , size_t Tgrowth_step, size_t Tmax_size, bool Tcache = false, bool Tzero = true>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero > * Tpool>

FORCEINLINE void* Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::operator new | ( | size_t | size,
|  | size_t | index |
| ) |  |  | `[inline]`

Allocates space for new Titem with given index.

Parameters:

  | size | size of Titem
  | index | index of item

Returns:
  pointer to allocated memory

Note:
  can never fail (return NULL), use CanAllocate() to check first!

Precondition:
  index has to be unused! Else it will crash

Definition at line 116 of file pool_type.hpp.

template<class Titem , typename Tindex , size_t Tgrowth_step, size_t Tmax_size, bool Tcache = false, bool Tzero = true>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero > * Tpool>

FORCEINLINE void* Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::operator new | ( | size_t | size | ) | `[inline]`

Allocates space for new Titem.

Parameters:

  | size | size of Titem

Returns:
  pointer to allocated memory

Note:
  can never fail (return NULL), use CanAllocate() to check first!

Definition at line 91 of file pool_type.hpp.

template<class Titem , typename Tindex , size_t Tgrowth_step, size_t Tmax_size, bool Tcache = false, bool Tzero = true>
template<struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero > * Tpool>

static FORCEINLINE void Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::PostDestructor | ( | size_t | index | ) | `[inline, static]`

Dummy function called after destructor of each member.

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

Parameters:

  | index | index of deleted item

Note:
  when this function is called, PoolItem::Get(index) == NULL.
  it's called only when !CleaningPool()

Reimplemented in BaseStation, Company, Industry, and Town.

Definition at line 223 of file pool_type.hpp.

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

- src/core/pool_type.hpp