OpenTTD Source: SimplePool< Titem, Tindex, Tgrowth_step, Tmax_size > Class Template Reference

OpenTTD Source 12.2

Data Structures | Public Member Functions | Private Member Functions | Private Attributes
SimplePool< Titem, Tindex, Tgrowth_step, Tmax_size > Class Template Reference

A simplified pool which stores values instead of pointers and doesn't redefine operator new/delete. More...

`#include <smallstack_type.hpp>`

## Data Structures
struct | SimplePoolPoolItem

## Public Member Functions
std::mutex & | GetMutex ()
| Get the mutex. More...
Titem & | Get (Tindex index)
| Get the item at position index. More...
Tindex | Create ()
| Create a new item and return its index. More...
void | Destroy (Tindex index)
| Destroy (or rather invalidate) the item at the given index. More...

## Private Member Functions
Tindex | FindFirstFree ()

## Private Attributes
Tindex | first_unused
Tindex | first_free
std::mutex | mutex
std::vector< SimplePoolPoolItem > | data

## Detailed Description

### template<typename Titem, typename Tindex, Tindex Tgrowth_step, Tindex Tmax_size>
class SimplePool< Titem, Tindex, Tgrowth_step, Tmax_size >

A simplified pool which stores values instead of pointers and doesn't redefine operator new/delete.

It also never zeroes memory and always reuses it.

Definition at line 22 of file smallstack_type.hpp.

## Member Function Documentation

## ◆ Create()

template<typename Titem , typename Tindex , Tindex Tgrowth_step, Tindex Tmax_size>

Tindex SimplePool< Titem, Tindex, Tgrowth_step, Tmax_size >::Create | ( |  | ) |
| inline

Create a new item and return its index.

Returns
  Index of new item.

Definition at line 43 of file smallstack_type.hpp.

Referenced by SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Push().

## ◆ Destroy()

template<typename Titem , typename Tindex , Tindex Tgrowth_step, Tindex Tmax_size>

void SimplePool< Titem, Tindex, Tgrowth_step, Tmax_size >::Destroy | ( | Tindex | index | ) |
| inline

Destroy (or rather invalidate) the item at the given index.

Parameters

  index | Index of item to be destroyed.

Definition at line 58 of file smallstack_type.hpp.

Referenced by SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Pop().

## ◆ Get()

template<typename Titem , typename Tindex , Tindex Tgrowth_step, Tindex Tmax_size>

Titem& SimplePool< Titem, Tindex, Tgrowth_step, Tmax_size >::Get | ( | Tindex | index | ) |
| inline

Get the item at position index.

Returns
  Item at index.

Definition at line 37 of file smallstack_type.hpp.

Referenced by SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Branch(), SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Contains(), SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Pop(), and SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Push().

## ◆ GetMutex()

template<typename Titem , typename Tindex , Tindex Tgrowth_step, Tindex Tmax_size>

std::mutex& SimplePool< Titem, Tindex, Tgrowth_step, Tmax_size >::GetMutex | ( |  | ) |
| inline

Get the mutex.

We don't lock the mutex in the pool methods as the SmallStack isn't necessarily in a consistent state after each method.

Returns
  Mutex.

Definition at line 31 of file smallstack_type.hpp.

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

- src/core/smallstack_type.hpp