10#ifndef SAVELOAD_OLDPOOL_H
11#define SAVELOAD_OLDPOOL_H
33 this->
items.shrink_to_fit();
41 Item *
Get(
size_t ref_index)
43 if (ref_index == 0)
return nullptr;
44 assert(ref_index <= this->
items.size());
45 return &this->
items[ref_index - 1];
55 assert(pool_index < UINT32_MAX);
56 if (pool_index >= this->
items.size()) this->
items.resize(pool_index + 1);
57 return this->
items[pool_index];
65 template <
typename Taction>
68 for (Item *item = this->
Get(ref_index); item !=
nullptr; item = this->
Get(item->next)) {
81 TransformItems(ref_index, [&list](
const auto &item) { list.push_back(std::move(item)); });
Helper class to handle conversion of linked-list style pools to plain vectors.
Item & Allocate(size_t pool_index)
Allocate an old item with the given pool index.
std::vector< T > TransformToVector(size_t ref_index)
Convert an old linked-list of items into a plain vector of items.
void Clear()
Clear all items from this old pool.
std::vector< Item > items
void TransformItems(size_t ref_index, Taction action)
Traverse an old linked-list of items and perform an action on each one in turn.
Item * Get(size_t ref_index)
Get a pointer to an old item with the given reference index.
#define T
Climate temperate.
Container for each item with linked-list indexes.
uint32_t index
This item's index (1-based).
uint32_t next
The next item's index (1-based).