Go to the documentation of this file.
1 /* $Id: pool_func.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <>.
8  */
12 #include "../stdafx.h"
13 #include "pool_type.hpp"
15 #include "../safeguards.h"
21 /* virtual */ PoolBase::~PoolBase()
22 {
23  PoolVector *pools = PoolBase::GetPools();
24  pools->Erase(pools->Find(this));
25  if (pools->Length() == 0) delete pools;
26 }
32 /* static */ void PoolBase::Clean(PoolType pt)
33 {
34  PoolVector *pools = PoolBase::GetPools();
35  PoolBase **end = pools->End();
36  for (PoolBase **ppool = pools->Begin(); ppool != end; ppool++) {
37  PoolBase *pool = *ppool;
38  if (pool->type & pt) pool->CleanPool();
39  }
40 }
static PoolVector * GetPools()
Function used to access the vector of all pools.
Definition: pool_type.hpp:39
virtual void CleanPool()=0
Virtual method that deletes all items in the pool.
Base class for base of all pools.
Definition: pool_type.hpp:32
const T * Begin() const
Get the pointer to the first item (const)
static void Clean(PoolType)
Clean all pools of given type.
Definition: pool_func.cpp:32
Simple vector template class.
Defintion of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle...
const T * End() const
Get the pointer behind the last valid item (const)
uint Length() const
Get the number of items in the list.
virtual ~PoolBase()
Destructor removes this object from the pool vector and deletes the vector itself if this was the las...
Definition: pool_func.cpp:21
const T * Find(const T &item) const
Search for the first occurrence of an item.
Various types of a pool.
Definition: pool_type.hpp:19
void Erase(T *item)
Removes given item from this vector.
const PoolType type
Type of this pool.
Definition: pool_type.hpp:33