CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

pooledscfclass.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2004 by Jorrit Tyberghein
00003               (C) 2004 by Frank Richter
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_UTIL_POOLEDSCFCLASS_H__
00021 #define __CS_UTIL_POOLEDSCFCLASS_H__
00022 
00031 #include "scf.h"
00032 
00033 #define SCF_DECLARE_IBASE_POOLED_DECL(Class, parentClass)\
00034   Class Pool                                            \
00035   {                                                     \
00036     parentClass* pool;                                  \
00037   public:                                               \
00038     Pool ();                                            \
00039     ~Pool ();                                           \
00040     parentClass* Alloc ();                              \
00041     void Recycle (parentClass* instance);               \
00042   };                                                    \
00043   friend class Pool;                                    \
00044   Pool* scfPool;                                        \
00045   parentClass* poolNext;                                \
00046   virtual void PoolRecycle ();                          \
00047   SCF_DECLARE_IBASE                                     \
00048   
00049 
00074 #define SCF_DECLARE_IBASE_POOLED(parentClass) \
00075   SCF_DECLARE_IBASE_POOLED_DECL(class, parentClass)
00076 
00080 #define SCF_DECLARE_IBASE_POOLED_EXTERN(Extern, parentClass) \
00081   SCF_DECLARE_IBASE_POOLED_DECL(class Extern, parentClass)
00082 
00087 #define SCF_CONSTRUCT_IBASE_POOLED(Pool)                \
00088   SCF_CONSTRUCT_IBASE(0);                               \
00089   poolNext = 0;                                         \
00090   scfPool = (Pool)
00091   
00095 #define SCF_IMPLEMENT_IBASE_POOL_CTOR(Class)            \
00096 Class::Pool::Pool ()                                    \
00097 {                                                       \
00098   pool = 0;                                             \
00099 }                                               
00100     
00104 #define SCF_IMPLEMENT_IBASE_POOL_DTOR(Class)            \
00105 Class::Pool::~Pool ()                                   \
00106 {                                                       \
00107   while (pool != 0)                                     \
00108   {                                                     \
00109     Class* n = pool->poolNext;                          \
00110     pool->PoolRecycle ();                               \
00111     delete pool;                                        \
00112     pool = n;                                           \
00113   }                                                     \
00114 }                                                       
00115 
00119 #define SCF_IMPLEMENT_IBASE_POOL_ALLOC(Class)           \
00120 Class* Class::Pool::Alloc ()                            \
00121 {                                                       \
00122   Class* newInst;                                       \
00123   if (pool != 0)                                        \
00124   {                                                     \
00125     newInst = pool;                                     \
00126     pool = pool->poolNext;                              \
00127   }                                                     \
00128   else                                                  \
00129     newInst = new Class (this);                         \
00130   return newInst;                                       \
00131 }
00132 
00136 #define SCF_IMPLEMENT_IBASE_POOL_RECYCLE(Class)         \
00137 void Class::Pool::Recycle (Class* instance)             \
00138 {                                                       \
00139   instance->PoolRecycle ();                             \
00140   instance->poolNext = pool;                            \
00141   pool = instance;                                      \
00142 }
00143 
00147 #define SCF_IMPLEMENT_IBASE_POOL(Class)                 \
00148   SCF_IMPLEMENT_IBASE_POOL_CTOR(Class)                  \
00149   SCF_IMPLEMENT_IBASE_POOL_DTOR(Class)                  \
00150   SCF_IMPLEMENT_IBASE_POOL_ALLOC(Class)                 \
00151   SCF_IMPLEMENT_IBASE_POOL_RECYCLE(Class)
00152   
00156 #define SCF_IMPLEMENT_IBASE_INCREF_POOLED(Class)        \
00157 void Class::IncRef ()                                   \
00158 {                                                       \
00159   scfRefCount++;                                        \
00160 }
00161 
00165 #define SCF_IMPLEMENT_IBASE_DECREF_POOLED(Class)        \
00166 void Class::DecRef ()                                   \
00167 {                                                       \
00168   if (scfRefCount == 1)                                 \
00169   {                                                     \
00170     scfPool->Recycle (this);                            \
00171     return;                                             \
00172   }                                                     \
00173   scfRefCount--;                                        \
00174 }
00175 
00179 #define SCF_IMPLEMENT_IBASE_POOLED(Class)               \
00180   SCF_IMPLEMENT_IBASE_POOL(Class)                       \
00181   SCF_IMPLEMENT_IBASE_INCREF_POOLED(Class)              \
00182   SCF_IMPLEMENT_IBASE_DECREF_POOLED(Class)              \
00183   SCF_IMPLEMENT_IBASE_GETREFCOUNT(Class)                \
00184   SCF_IMPLEMENT_IBASE_REFOWNER(Class)                   \
00185   SCF_IMPLEMENT_IBASE_REMOVE_REF_OWNERS(Class)          \
00186   SCF_IMPLEMENT_IBASE_QUERY(Class)
00187 
00191 #define SCF_IMPLEMENT_DEFAULT_POOLRECYCLE(Class)        \
00192 void Class::PoolRecycle () { }
00193 
00196 #endif // __CS_UTIL_POOLEDSCFCLASS_H__

Generated for Crystal Space by doxygen 1.3.9.1