# PoolItem< T, Tid, Tpool > Struct Template Reference

Generalization for all pool items that are saved in the savegame. More...

`#include <oldpool.h>`

Inheritance diagram for PoolItem< T, Tid, Tpool >:

## Public Member Functions
virtual | ~PoolItem ()
| We like to have the correct class destructed.
| PoolItem ()
| Constructor of given class.
void * | operator new (size_t size)
| An overriden version of new that allocates memory on the pool.
void | operator delete (void *p)
| 'Free' the memory allocated by the overriden new.
void * | operator new (size_t size, int index)
| An overriden version of new, so you can directly allocate a new object with the correct index when one is loading the savegame.
void | operator delete (void *p, int index)
| 'Free' the memory allocated by the overriden new.
void * | operator new (size_t size, T *pn)
| An overriden version of new, so you can use the vehicle instance instead of a newly allocated piece of memory.
void | operator delete (void *p, T *pn)
| 'Free' the memory allocated by the overriden new.
## Static Public Member Functions
static bool | CanAllocateItem ()
| Check whether we can allocate an item in this pool.
## Data Fields
Tid | index
| The pool-wide index of this object.
## Static Protected Member Functions
static T * | AllocateRaw ()
| Allocate a pool item; possibly allocate a new block in the pool.
static T * | AllocateRaw (uint &first)
| Allocate a pool item; possibly allocate a new block in the pool.
static bool | CleaningPool ()
| Are we cleaning this pool?
## Static Private Member Functions
static T * | AllocateSafeRaw (uint &first)
| Allocate a pool item; possibly allocate a new block in the pool.

## Detailed Description

### template<typename T, typename Tid, OldMemoryPool< T > * Tpool>
struct PoolItem< T, Tid, Tpool >

Generalization for all pool items that are saved in the savegame.

It specifies all the mechanics to access the pool easily.

Definition at line 164 of file oldpool.h.

## Constructor & Destructor Documentation

template<typename T, typename Tid, OldMemoryPool< T > * Tpool>

virtual PoolItem< T, Tid, Tpool >::~PoolItem | ( |  | ) | `[inline, virtual]`

We like to have the correct class destructed.

Warning:
  It is called even for object allocated on stack, so it is not present in the TPool! Then, index is undefined, not associated with TPool in any way.

Note:
  The idea is to free up allocated memory etc.

Definition at line 177 of file oldpool.h.

template<typename T, typename Tid, OldMemoryPool< T > * Tpool>

PoolItem< T, Tid, Tpool >::PoolItem | ( |  | ) | `[inline]`

Constructor of given class.

Warning:
  It is called even for object allocated on stack, so it may not be present in TPool! Then, index is undefined, not associated with TPool in any way.

Note:
  The idea is to initialize variables (except index)

Definition at line 189 of file oldpool.h.

## Member Function Documentation

template<typename T, typename Tid, OldMemoryPool< T > * Tpool>

void* PoolItem< T, Tid, Tpool >::operator new | ( | size_t | size | ) | `[inline]`

An overriden version of new that allocates memory on the pool.

Parameters:

  | size | the size of the variable (unused)

Returns:
  the memory that is 'allocated'

Definition at line 199 of file oldpool.h.

template<typename T, typename Tid, OldMemoryPool< T > * Tpool>

void PoolItem< T, Tid, Tpool >::operator delete | ( | void * | p | ) | `[inline]`

'Free' the memory allocated by the overriden new.

Parameters:

  | p | the memory to 'free'

Note:
  we only update Tpool->first_free_index

Definition at line 209 of file oldpool.h.

template<typename T, typename Tid, OldMemoryPool< T > * Tpool>

void* PoolItem< T, Tid, Tpool >::operator new | ( | size_t | size,
|  | int | index |
| ) |  |  | `[inline]`

An overriden version of new, so you can directly allocate a new object with the correct index when one is loading the savegame.

Parameters:

  | size | the size of the variable (unused)
  | index | the index of the object

Returns:
  the memory that is 'allocated'

Definition at line 221 of file oldpool.h.

template<typename T, typename Tid, OldMemoryPool< T > * Tpool>

void PoolItem< T, Tid, Tpool >::operator delete | ( | void * | p,
|  | int | index |
| ) |  |  | `[inline]`

'Free' the memory allocated by the overriden new.

Parameters:

  | p | the memory to 'free'
  | index | the original parameter given to create the memory

Note:
  we only update Tpool->first_free_index

Definition at line 234 of file oldpool.h.

template<typename T, typename Tid, OldMemoryPool< T > * Tpool>

void* PoolItem< T, Tid, Tpool >::operator new | ( | size_t | size,
|  | T * | pn |
| ) |  |  | `[inline]`

An overriden version of new, so you can use the vehicle instance instead of a newly allocated piece of memory.

Parameters:

  | size | the size of the variable (unused)
  | pn | the already existing object to use as 'storage' backend

Returns:
  the memory that is 'allocated'

Definition at line 246 of file oldpool.h.

template<typename T, typename Tid, OldMemoryPool< T > * Tpool>

void PoolItem< T, Tid, Tpool >::operator delete | ( | void * | p,
|  | T * | pn |
| ) |  |  | `[inline]`

'Free' the memory allocated by the overriden new.

Parameters:

  | p | the memory to 'free'
  | pn | the pointer that was given to 'new' on creation.

Note:
  we only update Tpool->first_free_index

Definition at line 257 of file oldpool.h.

template<typename T, typename Tid, OldMemoryPool< T > * Tpool>

static T* PoolItem< T, Tid, Tpool >::AllocateSafeRaw | ( | uint & | first | ) | `[inline, static, private]`

Allocate a pool item; possibly allocate a new block in the pool.

Parameters:

  | first | the first pool item to start searching

Precondition:
  first <= Tpool->GetSize()

Returns:
  the allocated pool item (or NULL when the pool is full).

Definition at line 269 of file oldpool.h.

Referenced by PoolItem< Sign, uint16,&_Sign_pool >::AllocateRaw().

template<typename T, typename Tid, OldMemoryPool< T > * Tpool>

static T* PoolItem< T, Tid, Tpool >::AllocateRaw | ( |  | ) | `[inline, static, protected]`

Allocate a pool item; possibly allocate a new block in the pool.

Returns:
  the allocated pool item (or NULL when the pool is full).

Definition at line 295 of file oldpool.h.

Referenced by PoolItem< Sign, uint16,&_Sign_pool >::AllocateSafeRaw(), and PoolItem< Sign, uint16,&_Sign_pool >::operator new().

template<typename T, typename Tid, OldMemoryPool< T > * Tpool>

static T* PoolItem< T, Tid, Tpool >::AllocateRaw | ( | uint & | first | ) | `[inline, static, protected]`

Allocate a pool item; possibly allocate a new block in the pool.

Parameters:

  | first | the first pool item to start searching

Returns:
  the allocated pool item (or NULL when the pool is full).

Definition at line 305 of file oldpool.h.

template<typename T, typename Tid, OldMemoryPool< T > * Tpool>

static bool PoolItem< T, Tid, Tpool >::CleaningPool | ( |  | ) | `[inline, static, protected]`

Are we cleaning this pool?

Returns:
  true if we are

Definition at line 316 of file oldpool.h.

Referenced by RoadStop::~RoadStop().

template<typename T, typename Tid, OldMemoryPool< T > * Tpool>

static bool PoolItem< T, Tid, Tpool >::CanAllocateItem | ( |  | ) | `[inline, static]`

Check whether we can allocate an item in this pool.

This to prevent the need to actually construct the object and then destructing it again, which could be *very* costly.

Returns:
  true if and only if at least ONE item can be allocated.

Definition at line 328 of file oldpool.h.

Referenced by AddEngineReplacement(), PoolItem< Sign, uint16,&_Sign_pool >::CanAllocateItem(), CmdBuildRoadStop(), and CreateNewIndustryHelper().

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

- src/oldpool.h