diff --git a/mozilla/base/src/nsDeque.cpp b/mozilla/base/src/nsDeque.cpp index 7641099e2fb..163913a6906 100644 --- a/mozilla/base/src/nsDeque.cpp +++ b/mozilla/base/src/nsDeque.cpp @@ -25,10 +25,11 @@ * @update gess4/18/98 * @return new deque */ -nsDeque::nsDeque(PRBool aOwnsMemory) { +nsDeque::nsDeque(PRBool aOwnsMemory, DEQUE_FREEOBJECT pFreeProc ) { mOwnsMemory=aOwnsMemory; mCapacity=eGrowthDelta; mOrigin=mSize=0; + mFreeProc = pFreeProc; mData=new void*[mCapacity]; } @@ -72,6 +73,19 @@ nsDeque& nsDeque::Empty() { return *this; } +/** + * Sets the memory object free procedure. + * + * @update jevering6/10/98 + * @param pFreeProc is pointer to the free procedure + * @return + */ + +void nsDeque::SetFreeProc(DEQUE_FREEOBJECT pFreeProc) +{ + mFreeProc = pFreeProc; +} + /** * Remove and delete all items from container * @@ -84,7 +98,10 @@ nsDeque& nsDeque::Erase() { void* temp; while(iter1!=iter2) { temp=(iter1++); - delete temp; + if (mFreeProc) + (*mFreeProc)(temp); + else + delete temp; } return Empty(); } diff --git a/mozilla/base/src/nsDeque.h b/mozilla/base/src/nsDeque.h index df125683135..89373539924 100644 --- a/mozilla/base/src/nsDeque.h +++ b/mozilla/base/src/nsDeque.h @@ -53,6 +53,7 @@ public: virtual nsDequeFunctor& operator()(void* anObject)=0; }; +typedef void (* DEQUE_FREEOBJECT)(void *); /****************************************************** * Here comes the nsDeque class itself... @@ -71,7 +72,7 @@ public: class NS_BASE nsDeque { friend class nsDequeIterator; public: - nsDeque(PRBool aOwnsMemory=PR_TRUE); + nsDeque(PRBool aOwnsMemory=PR_TRUE,DEQUE_FREEOBJECT pFreeProc=0); ~nsDeque(); /** @@ -83,7 +84,16 @@ friend class nsDequeIterator; * @return int contains element count */ PRInt32 GetSize() const; - + + /** + * Sets the memory object free procedure. + * + * @update jevering6/10/98 + * @param pFreeProc is pointer to the free procedure + * @return + */ + + void SetFreeProc(DEQUE_FREEOBJECT pFreeProc = 0); /** * Pushes new member onto the end of the deque @@ -175,7 +185,7 @@ protected: PRInt32 mOrigin; PRBool mOwnsMemory; void** mData; - + DEQUE_FREEOBJECT mFreeProc; private: @@ -188,7 +198,7 @@ private: * @param * @return */ - nsDeque(const nsDeque& other); + nsDeque(const nsDeque& other, DEQUE_FREEOBJECT pFreeProc); /** * Deque assignment operator (PRIVATE) diff --git a/mozilla/xpcom/ds/nsDeque.cpp b/mozilla/xpcom/ds/nsDeque.cpp index 7641099e2fb..163913a6906 100644 --- a/mozilla/xpcom/ds/nsDeque.cpp +++ b/mozilla/xpcom/ds/nsDeque.cpp @@ -25,10 +25,11 @@ * @update gess4/18/98 * @return new deque */ -nsDeque::nsDeque(PRBool aOwnsMemory) { +nsDeque::nsDeque(PRBool aOwnsMemory, DEQUE_FREEOBJECT pFreeProc ) { mOwnsMemory=aOwnsMemory; mCapacity=eGrowthDelta; mOrigin=mSize=0; + mFreeProc = pFreeProc; mData=new void*[mCapacity]; } @@ -72,6 +73,19 @@ nsDeque& nsDeque::Empty() { return *this; } +/** + * Sets the memory object free procedure. + * + * @update jevering6/10/98 + * @param pFreeProc is pointer to the free procedure + * @return + */ + +void nsDeque::SetFreeProc(DEQUE_FREEOBJECT pFreeProc) +{ + mFreeProc = pFreeProc; +} + /** * Remove and delete all items from container * @@ -84,7 +98,10 @@ nsDeque& nsDeque::Erase() { void* temp; while(iter1!=iter2) { temp=(iter1++); - delete temp; + if (mFreeProc) + (*mFreeProc)(temp); + else + delete temp; } return Empty(); } diff --git a/mozilla/xpcom/ds/nsDeque.h b/mozilla/xpcom/ds/nsDeque.h index df125683135..89373539924 100644 --- a/mozilla/xpcom/ds/nsDeque.h +++ b/mozilla/xpcom/ds/nsDeque.h @@ -53,6 +53,7 @@ public: virtual nsDequeFunctor& operator()(void* anObject)=0; }; +typedef void (* DEQUE_FREEOBJECT)(void *); /****************************************************** * Here comes the nsDeque class itself... @@ -71,7 +72,7 @@ public: class NS_BASE nsDeque { friend class nsDequeIterator; public: - nsDeque(PRBool aOwnsMemory=PR_TRUE); + nsDeque(PRBool aOwnsMemory=PR_TRUE,DEQUE_FREEOBJECT pFreeProc=0); ~nsDeque(); /** @@ -83,7 +84,16 @@ friend class nsDequeIterator; * @return int contains element count */ PRInt32 GetSize() const; - + + /** + * Sets the memory object free procedure. + * + * @update jevering6/10/98 + * @param pFreeProc is pointer to the free procedure + * @return + */ + + void SetFreeProc(DEQUE_FREEOBJECT pFreeProc = 0); /** * Pushes new member onto the end of the deque @@ -175,7 +185,7 @@ protected: PRInt32 mOrigin; PRBool mOwnsMemory; void** mData; - + DEQUE_FREEOBJECT mFreeProc; private: @@ -188,7 +198,7 @@ private: * @param * @return */ - nsDeque(const nsDeque& other); + nsDeque(const nsDeque& other, DEQUE_FREEOBJECT pFreeProc); /** * Deque assignment operator (PRIVATE)