OpenTTD Source 20250428-master-g68ba2735ea
pool_func.hpp File Reference

Some methods of Pool are placed here in order to reduce compilation time and binary size. More...

#include "bitmath_func.hpp"
#include "math_func.hpp"
#include "pool_type.hpp"
#include "../error_func.h"
#include "../saveload/saveload_error.hpp"

Go to the source code of this file.

Macros

#define DEFINE_POOL_METHOD(type)
 Helper for defining the method's signature.
 
#define INSTANTIATE_POOL_METHODS(name)
 Force instantiation of pool methods so we don't get linker errors.
 

Functions

 DEFINE_POOL_METHOD (inline void)
 Resizes the pool so 'index' can be addressed.
 
 DEFINE_POOL_METHOD (inline size_t)
 Searches for first free index.
 
 DEFINE_POOL_METHOD (inline void *)
 Makes given index valid.
 
 DEFINE_POOL_METHOD (void *)
 Allocates new item.
 
 DEFINE_POOL_METHOD (void)
 Deallocates memory used by this index and marks item as free.
 

Detailed Description

Some methods of Pool are placed here in order to reduce compilation time and binary size.

Definition in file pool_func.hpp.

Macro Definition Documentation

◆ DEFINE_POOL_METHOD

#define DEFINE_POOL_METHOD (   type)
Value:
template <class Titem, typename Tindex, size_t Tgrowth_step, PoolType Tpool_type, bool Tcache> \
requires std::is_base_of_v<PoolIDBase, Tindex> \
Base class for all pools.

Helper for defining the method's signature.

Parameters
typeThe return type of the method.

Definition at line 24 of file pool_func.hpp.

◆ INSTANTIATE_POOL_METHODS

#define INSTANTIATE_POOL_METHODS (   name)
Value:
template void * name ## Pool::GetNew(size_t size); \
template void * name ## Pool::GetNew(size_t size, size_t index); \
template void name ## Pool::FreeItem(size_t size, size_t index); \
template void name ## Pool::CleanPool();
void CleanPool() override
Virtual method that deletes all items in the pool.

Force instantiation of pool methods so we don't get linker errors.

Only methods accessed from methods defined in pool.hpp need to be forcefully instantiated.

Definition at line 210 of file pool_func.hpp.

Function Documentation

◆ DEFINE_POOL_METHOD() [1/5]

DEFINE_POOL_METHOD ( inline  size_t)

Searches for first free index.

Returns
first free index, NO_FREE_ITEM on failure

Definition at line 59 of file pool_func.hpp.

References FindFirstBit().

◆ DEFINE_POOL_METHOD() [2/5]

DEFINE_POOL_METHOD ( inline void *  )

Makes given index valid.

Parameters
sizesize of item
indexindex of item
Precondition
index < this->size
this->Get(index) == nullptr

Definition at line 86 of file pool_func.hpp.

References SetBit().

◆ DEFINE_POOL_METHOD() [3/5]

DEFINE_POOL_METHOD ( inline void  )

Resizes the pool so 'index' can be addressed.

Parameters
indexindex we will allocate later
Precondition
index >= this->size
index < MAX_SIZE

Definition at line 35 of file pool_func.hpp.

References Align().

◆ DEFINE_POOL_METHOD() [4/5]

DEFINE_POOL_METHOD ( void *  )

Allocates new item.

Allocates new item with given index.

Parameters
sizesize of item
Returns
pointer to allocated item
Note
FatalError() on failure! (no free item)
Parameters
sizesize of item
indexindex of item
Returns
pointer to allocated item
Note
SlErrorCorruptFmt() on failure! (index out of range or already used)

Definition at line 114 of file pool_func.hpp.

◆ DEFINE_POOL_METHOD() [5/5]

DEFINE_POOL_METHOD ( void  )

Deallocates memory used by this index and marks item as free.

Destroys all items in the pool and resets all member variables.

Parameters
sizethe size of the freed object
indexitem to deallocate
Precondition
unit is allocated (non-nullptr)
Note
'delete nullptr' doesn't cause call of this function, so it is safe

Definition at line 159 of file pool_func.hpp.

References ClrBit().