OpenTTD Source  20241108-master-g80f628063a
pool_func.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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 <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "../stdafx.h"
11 #include "pool_type.hpp"
12 
13 #include "../safeguards.h"
14 
19 /* virtual */ PoolBase::~PoolBase()
20 {
21  PoolVector *pools = PoolBase::GetPools();
22  pools->erase(std::find(pools->begin(), pools->end(), this));
23  if (pools->empty()) delete pools;
24 }
25 
30 /* static */ void PoolBase::Clean(PoolType pt)
31 {
32  for (PoolBase *pool : *PoolBase::GetPools()) {
33  if (pool->type & pt) pool->CleanPool();
34  }
35 }
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
std::vector< struct PoolBase * > PoolVector
Vector of pointers to PoolBase.
Definition: pool_type.hpp:26
PoolType
Various types of a pool.
Definition: pool_type.hpp:16
Base class for base of all pools.
Definition: pool_type.hpp:29
static void Clean(PoolType)
Clean all pools of given type.
Definition: pool_func.cpp:30
static PoolVector * GetPools()
Function used to access the vector of all pools.
Definition: pool_type.hpp:36
virtual ~PoolBase()
Destructor removes this object from the pool vector and deletes the vector itself if this was the las...
Definition: pool_func.cpp:19