summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2011-02-19 23:05:47 +0000
committersmatz <smatz@openttd.org>2011-02-19 23:05:47 +0000
commit756cc6cf651aa5650f055c70f31f7e07391be8c6 (patch)
tree8bf5af85e6523ad91ce99606e2b068b9f7513976 /src/core
parent642fb19d4fe4fbb249ddc314f75a35282ce6d28d (diff)
downloadopenttd-756cc6cf651aa5650f055c70f31f7e07391be8c6.tar.xz
(svn r22116) -Codechange: use PoolBase::Clean() at more places
Diffstat (limited to 'src/core')
-rw-r--r--src/core/pool_func.cpp7
-rw-r--r--src/core/pool_func.hpp5
-rw-r--r--src/core/pool_type.hpp24
3 files changed, 27 insertions, 9 deletions
diff --git a/src/core/pool_func.cpp b/src/core/pool_func.cpp
index 7b65b96a4..999dbe3d9 100644
--- a/src/core/pool_func.cpp
+++ b/src/core/pool_func.cpp
@@ -24,14 +24,15 @@ PoolBase::~PoolBase()
}
/**
- * Clean all pools - calls Pool::CleanPool()
+ * Clean all pools of given type.
+ * @param pt pool types to clean.
*/
-/* static */ void PoolBase::CleanAll()
+/* static */ void PoolBase::Clean(PoolType pt)
{
PoolVector *pools = PoolBase::GetPools();
PoolBase **end = pools->End();
for (PoolBase **ppool = pools->Begin(); ppool != end; ppool++) {
PoolBase *pool = *ppool;
- pool->CleanPool();
+ if (pool->type & pt) pool->CleanPool();
}
}
diff --git a/src/core/pool_func.hpp b/src/core/pool_func.hpp
index 299aee86c..0d9c23165 100644
--- a/src/core/pool_func.hpp
+++ b/src/core/pool_func.hpp
@@ -17,14 +17,15 @@
#include "pool_type.hpp"
#define DEFINE_POOL_METHOD(type) \
- template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, bool Tcache, bool Tzero> \
- type Pool<Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero>
+ template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type, bool Tcache, bool Tzero> \
+ type Pool<Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero>
/**
* Create a clean pool.
* @param name The name for the pool.
*/
DEFINE_POOL_METHOD(inline)::Pool(const char *name) :
+ PoolBase(Tpool_type),
name(name),
size(0),
first_free(0),
diff --git a/src/core/pool_type.hpp b/src/core/pool_type.hpp
index 9f4f8d99c..e5e58238c 100644
--- a/src/core/pool_type.hpp
+++ b/src/core/pool_type.hpp
@@ -13,11 +13,25 @@
#define POOL_TYPE_HPP
#include "smallvec_type.hpp"
+#include "enum_type.hpp"
+
+/** Various types of a pool. */
+enum PoolType {
+ PT_NONE = 0x00, ///< No pool is selected.
+ PT_NORMAL = 0x01, ///< Normal pool containing game objects.
+ PT_NCLIENT = 0x02, ///< Network client pools.
+ PT_NADMIN = 0x04, ///< Network admin pool.
+ PT_DATA = 0x08, ///< NewGRF or other data, that is not reset together with normal pools.
+ PT_ALL = 0x0F, ///< All pool types.
+};
+DECLARE_ENUM_AS_BIT_SET(PoolType)
typedef SmallVector<struct PoolBase *, 4> PoolVector; ///< Vector of pointers to PoolBase
/** Base class for base of all pools. */
struct PoolBase {
+ const PoolType type; ///< Type of this pool.
+
/**
* Function used to access the vector of all pools.
* @return pointer to vector of all pools
@@ -28,12 +42,13 @@ struct PoolBase {
return pools;
}
- static void CleanAll();
+ static void Clean(PoolType);
/**
* Contructor registers this object in the pool vector.
+ * @param pt type of this pool.
*/
- PoolBase()
+ PoolBase(PoolType pt) : type(pt)
{
*PoolBase::GetPools()->Append() = this;
}
@@ -52,11 +67,12 @@ struct PoolBase {
* @tparam Tindex Type of the index for this pool
* @tparam Tgrowth_step Size of growths; if the pool is full increase the size by this amount
* @tparam Tmax_size Maximum size of the pool
+ * @tparam Tpool_type Type of this pool
* @tparam Tcache Whether to perform 'alloc' caching, i.e. don't actually free/malloc just reuse the memory
* @tparam Tzero Whether to zero the memory
* @warning when Tcache is enabled *all* instances of this pool's item must be of the same size.
*/
-template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, bool Tcache = false, bool Tzero = true>
+template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type = PT_NORMAL, bool Tcache = false, bool Tzero = true>
struct Pool : PoolBase {
static const size_t MAX_SIZE = Tmax_size; ///< Make template parameter accessible from outside
@@ -116,7 +132,7 @@ struct Pool : PoolBase {
* Base class for all PoolItems
* @tparam Tpool The pool this item is going to be part of
*/
- template <struct Pool<Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero> *Tpool>
+ template <struct Pool<Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero> *Tpool>
struct PoolItem {
Tindex index; ///< Index of this pool item