dbertoni 01/04/30 14:21:12
Modified: c/src/Include XalanObjectCache.hpp
Log:
Use typedef for iterator, and improve exception safety of get().
Revision Changes Path
1.3 +50 -5 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XalanObjectCache.hpp 2001/04/30 18:05:53 1.2
+++ XalanObjectCache.hpp 2001/04/30 21:21:09 1.3
@@ -65,6 +65,7 @@
#include <Include/STLHelper.hpp>
+#include <Include/XalanAutoPtr.hpp>
@@ -108,16 +109,22 @@
// that's the cheapest thing.
if (m_availableList.size() == 0)
{
- m_busyList.push_back(create());
+ XalanAutoPtr<ObjectType> theNewObject(create());
+
+ m_busyList.push_back(theNewObject.get());
+
+ return theNewObject.release();
}
else
{
- m_busyList.push_back(m_availableList.back());
+ ObjectType* const theObject =
m_availableList.back();
+ m_busyList.push_back(theObject);
+
m_availableList.pop_back();
- }
- return m_busyList.back();
+ return theObject;
+ }
}
bool
@@ -126,8 +133,10 @@
#if !defined(XALAN_NO_NAMESPACES)
using std::find;
#endif
+
+ typedef typename VectorType::iterator IteratorType;
- const VectorType::iterator i =
+ const IteratorType i =
find(
m_busyList.begin(),
m_busyList.end(),
@@ -187,6 +196,42 @@
VectorType m_busyList;
};
+
+template<class ObjectType>
+class GetReleaseCachedObject
+{
+public:
+
+ typedef XalanObjectCache<ObjectType> CacheType;
+
+ GetReleaseCachedObject(CacheType& theCache) :
+ m_cache(theCache),
+ m_cachedObject(theCache.get())
+ {
+ }
+
+ ~GetReleaseCachedObject()
+ {
+ m_cache.release(m_cachedObject);
+ }
+
+ ObjectType*
+ get() const
+ {
+ return m_cachedObject;
+ }
+
+private:
+
+ // Not implemented...
+ GetReleaseCachedObject(const GetReleaseCachedObject<ObjectType>&);
+
+
+ // Data members...
+ CacheType& m_cache;
+
+ ObjectType* const m_cachedObject;
+};
template<class ObjectType>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]