Fixed double ended queue to accept a callback in the constructor

to a function which frees the inserted objects.
This commit is contained in:
jevering 1998-06-12 01:36:24 +00:00
Родитель 403e806203
Коммит b4c345c05c
4 изменённых файлов: 66 добавлений и 12 удалений

Просмотреть файл

@ -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();
}

Просмотреть файл

@ -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)

Просмотреть файл

@ -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();
}

Просмотреть файл

@ -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)