18 #if !defined(XALAN_OBJECTCACHE_HEADER_GUARD) 19 #define XALAN_OBJECTCACHE_HEADER_GUARD 33 XALAN_CPP_NAMESPACE_BEGIN
37 template<
class ObjectType>
45 typedef ObjectType ThisType;
49 ThisType*
const theResult =
50 new (theGuard.get()) ThisType();
60 template<
class ObjectType>
68 typedef ObjectType ThisType;
72 ThisType*
const theResult =
73 new (theGuard.get()) ThisType(theManager);
83 template<
class ObjectType>
96 template<
class ObjectType>
104 theInstance->clear();
110 #if defined(XALAN_OBJECT_CACHE_KEEP_BUSY_LIST) 114 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS) 115 class CreateFunctorType,
116 class DeleteFunctorType,
117 class ResetFunctorType>
129 typedef ObjectType CacheObjectType;
133 MemoryManager& theManager,
134 XalanSize_t initialListSize = 0) :
135 m_availableList(theManager),
136 m_busyList(theManager)
138 m_availableList.reserve(initialListSize);
140 m_busyList.reserve(initialListSize);
147 #if !defined(XALAN_NO_STD_NAMESPACE) 152 m_availableList.begin(),
153 m_availableList.end(),
154 m_deleteFunctor(theManager));
162 if (m_availableList.empty() ==
true)
164 ObjectType*
const theNewObject = m_createFunctor(m_availableList.getMemoryManager());
166 m_busyList.push_back(theNewObject);
172 ObjectType*
const theObject = m_availableList.back();
174 m_busyList.push_back(theObject);
176 m_availableList.pop_back();
183 release(ObjectType* theInstance)
185 #if !defined(XALAN_NO_STD_NAMESPACE) 189 typedef typename VectorType::iterator IteratorType;
191 const IteratorType i =
197 if (i == m_busyList.end())
203 m_resetFunctor(theInstance);
205 m_availableList.push_back(theInstance);
216 while (m_busyList.empty() ==
false)
218 ObjectType*
const theInstance = m_busyList.back();
220 m_resetFunctor(theInstance);
222 m_availableList.push_back(theInstance);
224 m_busyList.pop_back();
229 CreateFunctorType m_createFunctor;
231 DeleteFunctorType m_deleteFunctor;
233 ResetFunctorType m_resetFunctor;
245 VectorType m_availableList;
247 VectorType m_busyList;
258 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS) 259 class CreateFunctorType,
260 class DeleteFunctorType,
261 class ResetFunctorType>
277 XalanSize_t initialListSize = 0) :
278 m_deleteFunctor(theManager),
279 m_availableList(theManager)
281 m_availableList.reserve(initialListSize);
288 #if !defined(XALAN_NO_STD_NAMESPACE) 293 m_availableList.begin(),
294 m_availableList.end(),
303 if (m_availableList.empty() ==
true)
305 return m_createFunctor(m_availableList.getMemoryManager());
309 ObjectType*
const theObject = m_availableList.back();
311 m_availableList.pop_back();
320 m_resetFunctor(theInstance);
322 m_availableList.push_back(theInstance);
349 VectorType m_availableList;
358 template<
class XalanObjectCacheType>
367 m_cachedObject(theCache.get())
373 if (m_cachedObject != 0)
375 m_cache.release(m_cachedObject);
382 return m_cachedObject;
388 CacheObjectType*
const temp = m_cachedObject;
402 XalanObjectCacheType& m_cache;
404 CacheObjectType* m_cachedObject;
409 template<
class ObjectType>
413 DefaultCacheCreateFunctor<ObjectType>,
414 DeleteFunctor<ObjectType>,
415 DefaultCacheResetFunctor<ObjectType> >
427 MemoryManager& theManager,
428 XalanSize_t initialListSize = 0) :
429 BaseClassType(theManager, initialListSize)
436 template<
class ObjectType>
440 DefaultCacheCreateFunctorMemMgr<ObjectType>,
441 DeleteFunctor<ObjectType>,
442 DefaultCacheResetFunctor<ObjectType> >
454 MemoryManager& theManager,
455 XalanSize_t initialListSize = 0) :
456 BaseClassType(theManager, initialListSize)
463 XALAN_CPP_NAMESPACE_END
XalanObjectCache< ObjectType, DefaultCacheCreateFunctor< ObjectType >, DeleteFunctor< ObjectType >, DefaultCacheResetFunctor< ObjectType > > BaseClassType
ObjectType CacheObjectType
XalanObjectCache< ObjectType, DefaultCacheCreateFunctorMemMgr< ObjectType >, DeleteFunctor< ObjectType >, DefaultCacheResetFunctor< ObjectType > > BaseClassType
void operator()(ObjectType *) const
ResetFunctorType m_resetFunctor
void operator()(ObjectType *theInstance) const
XalanMemoryManagerObjectCacheDefault(MemoryManager &theManager, XalanSize_t initialListSize=0)
XalanVector< ObjectType * > VectorType
CacheObjectType * release()
DeleteFunctorType m_deleteFunctor
ObjectType * operator()(MemoryManager &theManager) const
ObjectType * operator()(MemoryManager &theManager) const
XalanObjectCacheDefault(MemoryManager &theManager, XalanSize_t initialListSize=0)
CreateFunctorType m_createFunctor
XalanObjectCache(MemoryManager &theManager, XalanSize_t initialListSize=0)
XalanObjectCacheType::CacheObjectType CacheObjectType
GuardCachedObject(XalanObjectCacheType &theCache)
bool release(ObjectType *theInstance)