Back to index

lightning-sunbird  0.9+nobinonly
nsDeque.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00056 #ifndef _NSDEQUE
00057 #define _NSDEQUE
00058 
00059 #include "nscore.h"
00060 
00068 class nsDequeFunctor{
00069 public:
00070   virtual void* operator()(void* anObject)=0;
00071 };
00072 
00073 /******************************************************
00074  * Here comes the nsDeque class itself...
00075  ******************************************************/
00076 
00087 class nsDequeIterator;
00088 
00089 class NS_COM nsDeque {
00090   friend class nsDequeIterator;
00091   public:
00092    nsDeque(nsDequeFunctor* aDeallocator);
00093   ~nsDeque();
00094 
00101   inline PRInt32 GetSize() const {return mSize;}
00102 
00109   nsDeque& Push(void* aItem);
00110 
00117   nsDeque& PushFront(void* aItem);
00118 
00124   void* Pop();
00125 
00131   void* PopFront();
00132 
00139   void* Peek();
00145   void* PeekFront();
00146 
00153   void* ObjectAt(int aIndex) const;
00154 
00160   nsDeque& Empty();
00161 
00169   nsDeque& Erase();
00170 
00177   nsDequeIterator Begin() const;
00178 
00185   nsDequeIterator End() const;
00186 
00187   void* Last() const;
00196   void ForEach(nsDequeFunctor& aFunctor) const;
00197 
00207   const void* FirstThat(nsDequeFunctor& aFunctor) const;
00208 
00209   void SetDeallocator(nsDequeFunctor* aDeallocator);
00210 
00211 protected:
00212   PRInt32         mSize;
00213   PRInt32         mCapacity;
00214   PRInt32         mOrigin;
00215   nsDequeFunctor* mDeallocator;
00216   void*           mBuffer[8];
00217   void**          mData;
00218 
00219 private:
00220 
00224   nsDeque();
00225 
00231   nsDeque(const nsDeque& other);
00232 
00239   nsDeque& operator=(const nsDeque& anOther);
00240 
00241   PRInt32 GrowCapacity();
00242 };
00243 
00244 /******************************************************
00245  * Here comes the nsDequeIterator class...
00246  ******************************************************/
00247 
00248 class NS_COM nsDequeIterator {
00249 public:
00267   nsDequeIterator(const nsDeque& aQueue, int aIndex=0);
00268 
00274   nsDequeIterator(const nsDequeIterator& aCopy);
00275 
00280   nsDequeIterator& First();
00281 
00287   nsDequeIterator& operator=(const nsDequeIterator& aCopy);
00288 
00296   PRBool operator!=(nsDequeIterator& aIter);
00297 
00307   PRBool operator<(nsDequeIterator& aIter);
00308 
00315   PRBool operator==(nsDequeIterator& aIter);
00316 
00326   PRBool operator>=(nsDequeIterator& aIter);
00327 
00334   void* operator++();
00335 
00343   void* operator++(int);
00344 
00351   void* operator--();
00352 
00360   void* operator--(int);
00361 
00377   void* GetCurrent();
00378 
00387   void ForEach(nsDequeFunctor& aFunctor) const;
00388 
00398   const void* FirstThat(nsDequeFunctor& aFunctor) const;
00399 
00400   protected:
00401 
00402   PRInt32         mIndex;
00403   const nsDeque&  mDeque;
00404 };
00405 #endif