1998-04-22 18:28:48 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-04-22 18:28:48 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-04-22 18:28:48 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-04-22 18:28:48 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-04-22 18:28:48 +00:00
|
|
|
*/
|
|
|
|
|
1999-01-15 19:20:51 +00:00
|
|
|
|
1998-04-22 18:28:48 +00:00
|
|
|
#include "nsDeque.h"
|
1998-05-21 02:27:34 +00:00
|
|
|
#include "nsCRT.h"
|
1999-07-16 17:31:00 +00:00
|
|
|
#include <stdio.h>
|
1998-04-22 18:28:48 +00:00
|
|
|
|
1998-08-21 02:03:56 +00:00
|
|
|
//#define _SELFTEST_DEQUE 1
|
|
|
|
#undef _SELFTEST_DEQUE
|
|
|
|
|
1998-04-22 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* Standard constructor
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @return new deque
|
|
|
|
*/
|
1999-02-26 06:33:54 +00:00
|
|
|
nsDeque::nsDeque(nsDequeFunctor* aDeallocator) {
|
|
|
|
mDeallocator=aDeallocator;
|
1998-04-22 18:28:48 +00:00
|
|
|
mOrigin=mSize=0;
|
1999-07-16 17:31:00 +00:00
|
|
|
mData=mBuffer; // don't allocate space until you must
|
|
|
|
mCapacity=sizeof(mBuffer)/sizeof(mBuffer[0]);
|
|
|
|
nsCRT::zero(mData,mCapacity*sizeof(mBuffer[0]));
|
1998-04-22 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
* @update gess4/18/98
|
|
|
|
*/
|
|
|
|
nsDeque::~nsDeque() {
|
1999-07-25 17:18:41 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
char buffer[30];
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("Capacity: %i\n",mCapacity);
|
1999-07-16 17:31:00 +00:00
|
|
|
|
|
|
|
static int mCaps[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
|
|
|
switch(mCapacity) {
|
|
|
|
case 4: mCaps[0]++; break;
|
|
|
|
case 8: mCaps[1]++; break;
|
|
|
|
case 16: mCaps[2]++; break;
|
|
|
|
case 32: mCaps[3]++; break;
|
|
|
|
case 64: mCaps[4]++; break;
|
|
|
|
case 128: mCaps[5]++; break;
|
|
|
|
case 256: mCaps[6]++; break;
|
|
|
|
case 512: mCaps[7]++; break;
|
|
|
|
case 1024: mCaps[8]++; break;
|
|
|
|
case 2048: mCaps[9]++; break;
|
|
|
|
case 4096: mCaps[10]++; break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1999-07-25 17:18:41 +00:00
|
|
|
#endif
|
1999-07-16 17:31:00 +00:00
|
|
|
|
1998-06-17 23:13:28 +00:00
|
|
|
Erase();
|
1999-07-16 17:31:00 +00:00
|
|
|
if(mData && (mData!=mBuffer))
|
|
|
|
delete [] mData;
|
1998-04-22 18:28:48 +00:00
|
|
|
mData=0;
|
1999-02-26 06:33:54 +00:00
|
|
|
if(mDeallocator) {
|
|
|
|
delete mDeallocator;
|
|
|
|
}
|
|
|
|
mDeallocator=0;
|
1998-04-22 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param
|
1999-09-30 04:03:49 +00:00
|
|
|
* @return
|
1998-04-22 18:28:48 +00:00
|
|
|
*/
|
1999-02-26 07:23:56 +00:00
|
|
|
void nsDeque::SetDeallocator(nsDequeFunctor* aDeallocator){
|
|
|
|
if(mDeallocator) {
|
|
|
|
delete mDeallocator;
|
|
|
|
}
|
|
|
|
mDeallocator=aDeallocator;
|
|
|
|
}
|
|
|
|
|
1998-04-22 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* Remove all items from container without destroying them.
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
nsDeque& nsDeque::Empty() {
|
1999-02-16 06:47:00 +00:00
|
|
|
if((0<mCapacity) && (mData)) {
|
|
|
|
nsCRT::zero(mData,mCapacity*sizeof(mData));
|
|
|
|
}
|
1998-04-22 18:28:48 +00:00
|
|
|
mSize=0;
|
|
|
|
mOrigin=0;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove and delete all items from container
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-16 17:31:00 +00:00
|
|
|
nsDeque& nsDeque::Erase() {
|
|
|
|
if(mDeallocator && mSize) {
|
1999-02-26 06:33:54 +00:00
|
|
|
ForEach(*mDeallocator);
|
|
|
|
}
|
1998-04-22 18:28:48 +00:00
|
|
|
return Empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-31 08:42:06 +00:00
|
|
|
/**
|
|
|
|
* This method adds an item to the end of the deque.
|
|
|
|
* This operation has the potential to cause the
|
|
|
|
* underlying buffer to resize.
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param anItem: new item to be added to deque
|
|
|
|
* @return nada
|
|
|
|
*/
|
|
|
|
nsDeque& nsDeque::GrowCapacity(void) {
|
1999-07-16 17:31:00 +00:00
|
|
|
|
|
|
|
PRInt32 theNewSize = mCapacity<<2;
|
|
|
|
void** temp=new void*[theNewSize];
|
1999-03-31 08:42:06 +00:00
|
|
|
|
|
|
|
//Here's the interesting part: You can't just move the elements
|
|
|
|
//directy (in situ) from the old buffer to the new one.
|
|
|
|
//Since capacity has changed, the old origin doesn't make
|
|
|
|
//sense anymore. It's better to resequence the elements now.
|
1999-07-16 17:31:00 +00:00
|
|
|
|
|
|
|
if(mData) {
|
|
|
|
int tempi=0;
|
|
|
|
int i=0;
|
|
|
|
int j=0;
|
|
|
|
for(i=mOrigin;i<mCapacity;i++) temp[tempi++]=mData[i]; //copy the leading elements...
|
|
|
|
for(j=0;j<mOrigin;j++) temp[tempi++]=mData[j]; //copy the trailing elements...
|
|
|
|
if(mData!=mBuffer)
|
|
|
|
delete [] mData;
|
|
|
|
}
|
|
|
|
mCapacity=theNewSize;
|
1999-03-31 08:42:06 +00:00
|
|
|
mOrigin=0; //now realign the origin...
|
|
|
|
mData=temp;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1998-04-22 18:28:48 +00:00
|
|
|
/**
|
1999-01-09 01:09:39 +00:00
|
|
|
* This method adds an item to the end of the deque.
|
1998-04-22 18:28:48 +00:00
|
|
|
* This operation has the potential to cause the
|
|
|
|
* underlying buffer to resize.
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
1999-01-09 01:09:39 +00:00
|
|
|
* @param anItem: new item to be added to deque
|
1998-04-22 18:28:48 +00:00
|
|
|
* @return nada
|
|
|
|
*/
|
|
|
|
nsDeque& nsDeque::Push(void* anItem) {
|
|
|
|
if(mSize==mCapacity) {
|
1999-03-31 08:42:06 +00:00
|
|
|
GrowCapacity();
|
1998-04-22 18:28:48 +00:00
|
|
|
}
|
|
|
|
int offset=mOrigin+mSize;
|
|
|
|
if(offset<mCapacity)
|
|
|
|
mData[offset]=anItem;
|
|
|
|
else mData[offset-mCapacity]=anItem;
|
|
|
|
mSize++;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1999-01-09 01:09:39 +00:00
|
|
|
/**
|
|
|
|
* This method adds an item to the front of the deque.
|
|
|
|
* This operation has the potential to cause the
|
|
|
|
* underlying buffer to resize.
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param anItem: new item to be added to deque
|
|
|
|
* @return nada
|
|
|
|
*/
|
|
|
|
nsDeque& nsDeque::PushFront(void* anItem) {
|
1999-03-31 08:42:06 +00:00
|
|
|
if(mSize==mCapacity) {
|
|
|
|
GrowCapacity();
|
|
|
|
}
|
|
|
|
if(0==mOrigin){ //case1: [xxx..]
|
1999-04-07 21:05:19 +00:00
|
|
|
//mOrigin=mCapacity-1-mSize++;
|
|
|
|
mOrigin=mCapacity-1;
|
1999-01-09 01:09:39 +00:00
|
|
|
mData[mOrigin]=anItem;
|
|
|
|
}
|
1999-04-02 22:06:05 +00:00
|
|
|
else {// if(mCapacity==(mOrigin+mSize-1)){ //case2: [..xxx] and case3: [.xxx.]
|
1999-03-31 08:42:06 +00:00
|
|
|
mData[--mOrigin]=anItem;
|
1999-01-09 01:09:39 +00:00
|
|
|
}
|
1999-04-07 21:05:19 +00:00
|
|
|
mSize++;
|
1999-01-09 01:09:39 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove and return the last item in the container.
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param none
|
|
|
|
* @return ptr to last item in container
|
|
|
|
*/
|
|
|
|
void* nsDeque::Pop(void) {
|
|
|
|
void* result=0;
|
|
|
|
if(mSize>0) {
|
|
|
|
int offset=mOrigin+mSize-1;
|
|
|
|
if(offset>=mCapacity)
|
|
|
|
offset-=mCapacity;
|
|
|
|
result=mData[offset];
|
|
|
|
mData[offset]=0;
|
|
|
|
mSize--;
|
|
|
|
if(0==mSize)
|
|
|
|
mOrigin=0;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-04-22 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* This method gets called you want to remove and return
|
|
|
|
* the first member in the container.
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param nada
|
|
|
|
* @return last item in container
|
|
|
|
*/
|
1999-01-09 01:09:39 +00:00
|
|
|
void* nsDeque::PopFront() {
|
1998-04-22 18:28:48 +00:00
|
|
|
void* result=0;
|
|
|
|
if(mSize>0) {
|
1999-07-16 17:31:00 +00:00
|
|
|
NS_ASSERTION(mOrigin<mCapacity,"Error: Bad origin");
|
1998-04-22 18:28:48 +00:00
|
|
|
result=mData[mOrigin];
|
|
|
|
mData[mOrigin++]=0; //zero it out for debugging purposes.
|
|
|
|
mSize--;
|
1998-08-21 02:03:56 +00:00
|
|
|
if(mCapacity==mOrigin) //you popped off the end, so cycle back around...
|
|
|
|
mOrigin=0;
|
1998-04-22 18:28:48 +00:00
|
|
|
if(0==mSize)
|
|
|
|
mOrigin=0;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
1999-11-27 17:47:05 +00:00
|
|
|
/**
|
|
|
|
* This method gets called you want to peek at the bottom
|
|
|
|
* member without removing it.
|
|
|
|
*
|
|
|
|
* @update sford 11/25/99
|
|
|
|
* @param nada
|
|
|
|
* @return last item in container
|
|
|
|
*/
|
|
|
|
void* nsDeque::Peek() {
|
|
|
|
void* result=0;
|
|
|
|
if(mSize>0) {
|
|
|
|
int offset=mOrigin+mSize-1;
|
|
|
|
result=mData[offset];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
1998-04-22 18:28:48 +00:00
|
|
|
|
1998-08-05 01:59:34 +00:00
|
|
|
/**
|
|
|
|
* This method gets called you want to peek at the topmost
|
|
|
|
* member without removing it.
|
|
|
|
*
|
1999-11-27 17:47:05 +00:00
|
|
|
* @update sford 11/25/99
|
1998-08-05 01:59:34 +00:00
|
|
|
* @param nada
|
|
|
|
* @return last item in container
|
|
|
|
*/
|
1999-11-27 17:47:05 +00:00
|
|
|
void* nsDeque::PeekFront() {
|
1998-08-05 01:59:34 +00:00
|
|
|
void* result=0;
|
|
|
|
if(mSize>0) {
|
|
|
|
result=mData[mOrigin];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-04-22 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* Call this to retrieve the ith element from this container.
|
|
|
|
* Keep in mind that accessing the underlying elements is
|
|
|
|
* done in a relative fashion. Object 0 is not necessarily
|
|
|
|
* the first element (the first element is at mOrigin).
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param anIndex : 0 relative offset of item you want
|
|
|
|
* @return void* or null
|
|
|
|
*/
|
|
|
|
void* nsDeque::ObjectAt(PRInt32 anIndex) const {
|
|
|
|
void* result=0;
|
|
|
|
|
|
|
|
if((anIndex>=0) && (anIndex<mSize))
|
|
|
|
{
|
1998-08-12 08:53:03 +00:00
|
|
|
if(anIndex<(mCapacity-mOrigin)) {
|
1998-04-22 18:28:48 +00:00
|
|
|
result=mData[mOrigin+anIndex];
|
|
|
|
}
|
|
|
|
else {
|
1998-08-12 08:53:03 +00:00
|
|
|
result=mData[anIndex-(mCapacity-mOrigin)];
|
1998-04-22 18:28:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and return an iterator pointing to
|
|
|
|
* the beginning of the queue. Note that this
|
|
|
|
* takes the circular buffer semantics into account.
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @return new deque iterator, init'ed to 1st item
|
|
|
|
*/
|
|
|
|
nsDequeIterator nsDeque::Begin(void) const{
|
|
|
|
return nsDequeIterator(*this,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and return an iterator pointing to
|
|
|
|
* the last of the queue. Note that this
|
|
|
|
* takes the circular buffer semantics into account.
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @return new deque iterator, init'ed to last item
|
|
|
|
*/
|
|
|
|
nsDequeIterator nsDeque::End(void) const{
|
|
|
|
return nsDequeIterator(*this,mSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this method when you wanto to iterate all the
|
|
|
|
* members of the container, passing a functor along
|
|
|
|
* to call your code.
|
|
|
|
*
|
|
|
|
* @update gess4/20/98
|
|
|
|
* @param aFunctor object to call for each member
|
|
|
|
* @return *this
|
|
|
|
*/
|
1998-08-27 02:39:36 +00:00
|
|
|
void nsDeque::ForEach(nsDequeFunctor& aFunctor) const{
|
1998-08-05 01:59:34 +00:00
|
|
|
int i=0;
|
|
|
|
for(i=0;i<mSize;i++){
|
|
|
|
void* obj=ObjectAt(i);
|
|
|
|
obj=aFunctor(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this method when you wanto to iterate all the
|
|
|
|
* members of the container, passing a functor along
|
|
|
|
* to call your code. Iteration continues until your
|
|
|
|
* functor returns a non-null.
|
|
|
|
*
|
|
|
|
* @update gess4/20/98
|
|
|
|
* @param aFunctor object to call for each member
|
|
|
|
* @return *this
|
|
|
|
*/
|
|
|
|
const void* nsDeque::FirstThat(nsDequeFunctor& aFunctor) const{
|
1998-05-21 02:27:34 +00:00
|
|
|
int i=0;
|
|
|
|
for(i=0;i<mSize;i++){
|
1998-04-22 18:28:48 +00:00
|
|
|
void* obj=ObjectAt(i);
|
1998-07-02 08:14:22 +00:00
|
|
|
obj=aFunctor(obj);
|
|
|
|
if(obj)
|
|
|
|
return obj;
|
1998-04-22 18:28:48 +00:00
|
|
|
}
|
1998-07-02 08:14:22 +00:00
|
|
|
return 0;
|
1998-04-22 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
1998-08-05 01:59:34 +00:00
|
|
|
|
1998-04-22 18:28:48 +00:00
|
|
|
/******************************************************
|
|
|
|
* Here comes the nsDequeIterator class...
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DequeIterator is an object that knows how to iterate (forward and backward)
|
|
|
|
* a Deque. Normally, you don't need to do this, but there are some special
|
|
|
|
* cases where it is pretty handy, so here you go.
|
|
|
|
*
|
|
|
|
* This is a standard dequeiterator constructor
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param aQueue is the deque object to be iterated
|
|
|
|
* @param anIndex is the starting position for your iteration
|
|
|
|
*/
|
1998-07-25 02:11:02 +00:00
|
|
|
nsDequeIterator::nsDequeIterator(const nsDeque& aQueue,int anIndex): mIndex(anIndex), mDeque(aQueue) {
|
1998-04-22 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy construct a new iterator beginning with given
|
|
|
|
*
|
|
|
|
* @update gess4/20/98
|
|
|
|
* @param aCopy is another iterator to copy from
|
|
|
|
* @return
|
|
|
|
*/
|
1998-07-25 02:11:02 +00:00
|
|
|
nsDequeIterator::nsDequeIterator(const nsDequeIterator& aCopy) : mIndex(aCopy.mIndex), mDeque(aCopy.mDeque) {
|
1998-04-22 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
1998-08-21 02:03:56 +00:00
|
|
|
/**
|
|
|
|
* Moves iterator to first element in deque
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @return this
|
|
|
|
*/
|
|
|
|
nsDequeIterator& nsDequeIterator::First(void){
|
|
|
|
mIndex=0;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1998-04-22 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* Standard assignment operator for dequeiterator
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param aCopy is an iterator to be copied from
|
|
|
|
* @return *this
|
|
|
|
*/
|
1998-05-19 01:51:24 +00:00
|
|
|
nsDequeIterator& nsDequeIterator::operator=(const nsDequeIterator& aCopy) {
|
1998-04-22 18:28:48 +00:00
|
|
|
//queue's are already equal.
|
|
|
|
mIndex=aCopy.mIndex;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* preform ! operation against to iterators to test for equivalence
|
|
|
|
* (or lack thereof)!
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param anIter is the object to be compared to
|
|
|
|
* @return TRUE if NOT equal.
|
|
|
|
*/
|
|
|
|
PRBool nsDequeIterator::operator!=(nsDequeIterator& anIter) {
|
|
|
|
return PRBool(!this->operator==(anIter));
|
|
|
|
}
|
|
|
|
|
1998-04-30 05:55:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare 2 iterators for equivalence.
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param anIter is the other iterator to be compared to
|
|
|
|
* @return TRUE if EQUAL
|
|
|
|
*/
|
|
|
|
PRBool nsDequeIterator::operator<(nsDequeIterator& anIter) {
|
|
|
|
return PRBool(((mIndex<anIter.mIndex) && (&mDeque==&anIter.mDeque)));
|
|
|
|
}
|
|
|
|
|
1998-04-22 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* Compare 2 iterators for equivalence.
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param anIter is the other iterator to be compared to
|
|
|
|
* @return TRUE if EQUAL
|
|
|
|
*/
|
|
|
|
PRBool nsDequeIterator::operator==(nsDequeIterator& anIter) {
|
|
|
|
return PRBool(((mIndex==anIter.mIndex) && (&mDeque==&anIter.mDeque)));
|
|
|
|
}
|
|
|
|
|
1998-04-30 05:55:51 +00:00
|
|
|
/**
|
|
|
|
* Compare 2 iterators for equivalence.
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param anIter is the other iterator to be compared to
|
|
|
|
* @return TRUE if EQUAL
|
|
|
|
*/
|
|
|
|
PRBool nsDequeIterator::operator>=(nsDequeIterator& anIter) {
|
|
|
|
return PRBool(((mIndex>=anIter.mIndex) && (&mDeque==&anIter.mDeque)));
|
|
|
|
}
|
|
|
|
|
1998-04-22 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* Pre-increment operator
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @return object at preincremented index
|
|
|
|
*/
|
|
|
|
void* nsDequeIterator::operator++() {
|
|
|
|
return mDeque.ObjectAt(++mIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-increment operator
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param param is ignored
|
|
|
|
* @return object at post-incremented index
|
|
|
|
*/
|
|
|
|
void* nsDequeIterator::operator++(int) {
|
|
|
|
return mDeque.ObjectAt(mIndex++);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pre-decrement operator
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @return object at pre-decremented index
|
|
|
|
*/
|
|
|
|
void* nsDequeIterator::operator--() {
|
|
|
|
return mDeque.ObjectAt(--mIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-decrement operator
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param param is ignored
|
|
|
|
* @return object at post-decremented index
|
|
|
|
*/
|
|
|
|
void* nsDequeIterator::operator--(int) {
|
|
|
|
return mDeque.ObjectAt(mIndex--);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dereference operator
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @return object at ith index
|
|
|
|
*/
|
|
|
|
void* nsDequeIterator::GetCurrent(void) {
|
|
|
|
return mDeque.ObjectAt(mIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this method when you wanto to iterate all the
|
|
|
|
* members of the container, passing a functor along
|
|
|
|
* to call your code.
|
|
|
|
*
|
|
|
|
* @update gess4/20/98
|
|
|
|
* @param aFunctor object to call for each member
|
|
|
|
* @return *this
|
|
|
|
*/
|
1998-08-27 02:39:36 +00:00
|
|
|
void nsDequeIterator::ForEach(nsDequeFunctor& aFunctor) const{
|
1998-08-05 01:59:34 +00:00
|
|
|
mDeque.ForEach(aFunctor);
|
1998-04-22 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
1998-08-05 01:59:34 +00:00
|
|
|
/**
|
|
|
|
* Call this method when you wanto to iterate all the
|
|
|
|
* members of the container, passing a functor along
|
|
|
|
* to call your code.
|
|
|
|
*
|
|
|
|
* @update gess4/20/98
|
|
|
|
* @param aFunctor object to call for each member
|
|
|
|
* @return *this
|
|
|
|
*/
|
|
|
|
const void* nsDequeIterator::FirstThat(nsDequeFunctor& aFunctor) const{
|
|
|
|
return mDeque.FirstThat(aFunctor);
|
|
|
|
}
|
1998-04-22 18:28:48 +00:00
|
|
|
|
1998-08-21 02:03:56 +00:00
|
|
|
#ifdef _SELFTEST_DEQUE
|
|
|
|
/**************************************************************
|
|
|
|
Now define the token deallocator class...
|
|
|
|
**************************************************************/
|
|
|
|
class _SelfTestDeallocator: public nsDequeFunctor{
|
|
|
|
public:
|
|
|
|
_SelfTestDeallocator::_SelfTestDeallocator() {
|
|
|
|
nsDeque::SelfTest();
|
|
|
|
}
|
|
|
|
virtual void* operator()(void* anObject) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static _SelfTestDeallocator gDeallocator;
|
|
|
|
#endif
|
|
|
|
|
1998-04-22 18:28:48 +00:00
|
|
|
/**
|
|
|
|
* conduct automated self test for this class
|
|
|
|
*
|
|
|
|
* @update gess4/18/98
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
void nsDeque::SelfTest(void) {
|
|
|
|
#ifdef _SELFTEST_DEQUE
|
|
|
|
|
|
|
|
{
|
1998-08-21 02:03:56 +00:00
|
|
|
nsDeque theDeque(gDeallocator); //construct a simple one...
|
1998-04-22 18:28:48 +00:00
|
|
|
|
1998-08-21 02:03:56 +00:00
|
|
|
int ints[200];
|
1998-04-22 18:28:48 +00:00
|
|
|
int count=sizeof(ints)/sizeof(int);
|
1998-05-21 02:27:34 +00:00
|
|
|
int i=0;
|
1998-08-21 02:03:56 +00:00
|
|
|
|
|
|
|
for(i=0;i<count;i++){ //initialize'em
|
|
|
|
ints[i]=10*(1+i);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0;i<70;i++){
|
1998-04-22 18:28:48 +00:00
|
|
|
theDeque.Push(&ints[i]);
|
|
|
|
}
|
|
|
|
|
1998-08-21 02:03:56 +00:00
|
|
|
for(i=0;i<56;i++){
|
|
|
|
int* temp=(int*)theDeque.Pop();
|
|
|
|
}
|
1998-04-22 18:28:48 +00:00
|
|
|
|
1998-08-21 02:03:56 +00:00
|
|
|
for(i=0;i<55;i++){
|
|
|
|
theDeque.Push(&ints[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0;i<35;i++){
|
|
|
|
int* temp=(int*)theDeque.Pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0;i<35;i++){
|
|
|
|
theDeque.Push(&ints[i]);
|
|
|
|
}
|
1998-04-22 18:28:48 +00:00
|
|
|
|
1998-08-21 02:03:56 +00:00
|
|
|
for(i=0;i<38;i++){
|
|
|
|
int* temp=(int*)theDeque.Pop();
|
1998-04-22 18:28:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int x;
|
|
|
|
x=10;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|