dbertoni 01/04/30 11:05:57
Modified: c/src/Include XalanObjectCache.hpp
Log:
Finished implementation.
Revision Changes Path
1.2 +54 -23 xml-xalan/c/src/Include/XalanObjectCache.hpp
Index: XalanObjectCache.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/Include/XalanObjectCache.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XalanObjectCache.hpp 2001/04/20 22:51:58 1.1
+++ XalanObjectCache.hpp 2001/04/30 18:05:53 1.2
@@ -64,15 +64,19 @@
+#include <Include/STLHelper.hpp>
+
+
+
template<class ObjectType>
class XalanObjectCache
{
public:
#if defined(XALAN_NO_NAMESPACES)
- typedef vector<ObjectType*> VectorType;
+ typedef vector<ObjectType*> VectorType;
#else
- typedef std::vector<KeyType> VectorType;
+ typedef std::vector<ObjectType*> VectorType;
#endif
explicit
@@ -97,6 +101,52 @@
DeleteFunctor<ObjectType>());
}
+ ObjectType*
+ get()
+ {
+ // We'll always return the back of the free list, since
+ // that's the cheapest thing.
+ if (m_availableList.size() == 0)
+ {
+ m_busyList.push_back(create());
+ }
+ else
+ {
+ m_busyList.push_back(m_availableList.back());
+
+ m_availableList.pop_back();
+ }
+
+ return m_busyList.back();
+ }
+
+ bool
+ release(ObjectType* theInstance)
+ {
+#if !defined(XALAN_NO_NAMESPACES)
+ using std::find;
+#endif
+
+ const VectorType::iterator i =
+ find(
+ m_busyList.begin(),
+ m_busyList.end(),
+ theInstance);
+
+ if (i == m_busyList.end())
+ {
+ return false;
+ }
+ else
+ {
+ m_availableList.push_back(theInstance);
+
+ m_busyList.erase(i);
+
+ return true;
+ }
+ }
+
virtual void
reset()
{
@@ -130,14 +180,11 @@
XalanObjectCache<ObjectType>&
operator=(const XalanObjectCache<ObjectType>& theRHS);
- bool
- operator==(const XalanObjectCache<ObjectType>& theRHS) const;
-
// Data members
- VectorType m_availableVector;
+ VectorType m_availableList;
- VectorType m_busyVector;
+ VectorType m_busyList;
};
@@ -147,12 +194,6 @@
{
public:
- explicit
- XalanObjectCacheDefault() :
- XalanObjectCache()
- {
- }
-
protected:
virtual ObjectType*
@@ -162,16 +203,6 @@
}
private:
-
- // There are not defined...
- XalanObjectCacheDefault(const XalanObjectCacheDefault<ObjectType>&
theRHS);
-
- XalanObjectCacheDefault<ObjectType>&
- operator=(const XalanObjectCacheDefault<ObjectType>& theRHS);
-
- bool
- operator==(const XalanObjectCacheDefault<ObjectType>& theRHS) const;
-
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]