Bug 545892 - Always pass WM_NCPAINT events to the default event procedure. r=bent...
[mozilla-central.git] / xpcom / glue / nsDeque.h
blob4ca6bb5342e38cfbf6f0a8ceeb4e44f33ddbda69
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 /**
39 * MODULE NOTES:
41 * The Deque is a very small, very efficient container object
42 * than can hold elements of type void*, offering the following features:
43 * Its interface supports pushing and popping of elements.
44 * It can iterate (via an interator class) its elements.
45 * When full, it can efficiently resize dynamically.
48 * NOTE: The only bit of trickery here is that this deque is
49 * built upon a ring-buffer. Like all ring buffers, the first
50 * element may not be at index[0]. The mOrigin member determines
51 * where the first child is. This point is quietly hidden from
52 * customers of this class.
56 #ifndef _NSDEQUE
57 #define _NSDEQUE
59 #include "nscore.h"
61 /**
62 * The nsDequeFunctor class is used when you want to create
63 * callbacks between the deque and your generic code.
64 * Use these objects in a call to ForEach();
68 class nsDequeFunctor{
69 public:
70 virtual void* operator()(void* anObject)=0;
73 /******************************************************
74 * Here comes the nsDeque class itself...
75 ******************************************************/
77 /**
78 * The deque (double-ended queue) class is a common container type,
79 * whose behavior mimics a line in your favorite checkout stand.
80 * Classic CS describes the common behavior of a queue as FIFO.
81 * A deque allows insertion and removal at both ends of
82 * the container.
84 * The deque stores pointers to items.
87 class nsDequeIterator;
89 class NS_COM_GLUE nsDeque {
90 friend class nsDequeIterator;
91 public:
92 nsDeque(nsDequeFunctor* aDeallocator = nsnull);
93 ~nsDeque();
95 /**
96 * Returns the number of elements currently stored in
97 * this deque.
99 * @return number of elements currently in the deque
101 inline PRInt32 GetSize() const {return mSize;}
104 * Appends new member at the end of the deque.
106 * @param item to store in deque
107 * @return *this
109 nsDeque& Push(void* aItem);
112 * Inserts new member at the front of the deque.
114 * @param item to store in deque
115 * @return *this
117 nsDeque& PushFront(void* aItem);
120 * Remove and return the last item in the container.
122 * @return the item that was the last item in container
124 void* Pop();
127 * Remove and return the first item in the container.
129 * @return the item that was first item in container
131 void* PopFront();
134 * Retrieve the bottom item without removing it.
136 * @return the first item in container
139 void* Peek();
141 * Return topmost item without removing it.
143 * @return the first item in container
145 void* PeekFront();
148 * Retrieve the i'th member from the deque without removing it.
150 * @param index of desired item
151 * @return i'th element in list
153 void* ObjectAt(int aIndex) const;
156 * Remove all items from container without destroying them.
158 * @return *this
160 nsDeque& Empty();
163 * Remove and delete all items from container.
164 * Deletes are handled by the deallocator nsDequeFunctor
165 * which is specified at deque construction.
167 * @return *this
169 nsDeque& Erase();
172 * Creates a new iterator, pointing to the first
173 * item in the deque.
175 * @return new dequeIterator
177 nsDequeIterator Begin() const;
180 * Creates a new iterator, pointing to the last
181 * item in the deque.
183 * @return new dequeIterator
185 nsDequeIterator End() const;
187 void* Last() const;
189 * Call this method when you want to iterate all the
190 * members of the container, passing a functor along
191 * to call your code.
193 * @param aFunctor object to call for each member
194 * @return *this
196 void ForEach(nsDequeFunctor& aFunctor) const;
199 * Call this method when you want to iterate all the
200 * members of the container, calling the functor you
201 * passed with each member. This process will interrupt
202 * if your function returns non 0 to this method.
204 * @param aFunctor object to call for each member
205 * @return first nonzero result of aFunctor or 0.
207 const void* FirstThat(nsDequeFunctor& aFunctor) const;
209 void SetDeallocator(nsDequeFunctor* aDeallocator);
211 protected:
212 PRInt32 mSize;
213 PRInt32 mCapacity;
214 PRInt32 mOrigin;
215 nsDequeFunctor* mDeallocator;
216 void* mBuffer[8];
217 void** mData;
219 private:
222 * Copy constructor (PRIVATE)
224 * @param another deque
226 nsDeque(const nsDeque& other);
229 * Deque assignment operator (PRIVATE)
231 * @param another deque
232 * @return *this
234 nsDeque& operator=(const nsDeque& anOther);
236 PRBool GrowCapacity();
239 /******************************************************
240 * Here comes the nsDequeIterator class...
241 ******************************************************/
243 class NS_COM_GLUE nsDequeIterator {
244 public:
246 * DequeIterator is an object that knows how to iterate
247 * (forward and backward) through a Deque. Normally,
248 * you don't need to do this, but there are some special
249 * cases where it is pretty handy.
251 * One warning: the iterator is not bound to an item,
252 * it is bound to an index, so if you insert or remove
253 * from the beginning while using an iterator
254 * (which is not recommended) then the iterator will
255 * point to a different item. @see GetCurrent()
257 * Here you go.
259 * @param aQueue is the deque object to be iterated
260 * @param aIndex is the starting position for your iteration
262 nsDequeIterator(const nsDeque& aQueue, int aIndex=0);
265 * Create a copy of a DequeIterator
267 * @param aCopy is another iterator to copy from
269 nsDequeIterator(const nsDequeIterator& aCopy);
272 * Moves iterator to first element in the deque
273 * @return *this
275 nsDequeIterator& First();
278 * Standard assignment operator for dequeiterator
279 * @param aCopy is another iterator to copy from
280 * @return *this
282 nsDequeIterator& operator=(const nsDequeIterator& aCopy);
285 * preform ! operation against two iterators to test for equivalence
286 * (or lack thereof)!
288 * @param aIter is the object to be compared to
289 * @return TRUE if NOT equal.
291 PRBool operator!=(nsDequeIterator& aIter);
294 * Compare two iterators for increasing order.
296 * @param aIter is the other iterator to be compared to
297 * @return TRUE if this object points to an element before
298 * the element pointed to by aIter.
299 * FALSE if this and aIter are not iterating over
300 * the same deque.
302 PRBool operator<(nsDequeIterator& aIter);
305 * Compare two iterators for equivalence.
307 * @param aIter is the other iterator to be compared to
308 * @return TRUE if EQUAL
310 PRBool operator==(nsDequeIterator& aIter);
313 * Compare two iterators for non strict decreasing order.
315 * @param aIter is the other iterator to be compared to
316 * @return TRUE if this object points to the same element, or
317 * an element after the element pointed to by aIter.
318 * FALSE if this and aIter are not iterating over
319 * the same deque.
321 PRBool operator>=(nsDequeIterator& aIter);
324 * Pre-increment operator
325 * Iterator will advance one index towards the end.
327 * @return object_at(++index)
329 void* operator++();
332 * Post-increment operator
333 * Iterator will advance one index towards the end.
335 * @param param is ignored
336 * @return object_at(mIndex++)
338 void* operator++(int);
341 * Pre-decrement operator
342 * Iterator will advance one index towards the beginning.
344 * @return object_at(--index)
346 void* operator--();
349 * Post-decrement operator
350 * Iterator will advance one index towards the beginning.
352 * @param param is ignored
353 * @return object_at(index--)
355 void* operator--(int);
358 * Retrieve the the iterator's notion of current node.
360 * Note that the iterator floats, so you don't need to do:
361 * <code>++iter; aDeque.PopFront();</code>
362 * Unless you actually want your iterator to jump 2 positions
363 * relative to its origin.
365 * Picture: [1 2i 3 4]
366 * PopFront()
367 * Picture: [2 3i 4]
368 * Note that I still happily points to object at the second index.
370 * @return object at i'th index
372 void* GetCurrent();
375 * Call this method when you want to iterate all the
376 * members of the container, passing a functor along
377 * to call your code.
379 * @param aFunctor object to call for each member
380 * @return *this
382 void ForEach(nsDequeFunctor& aFunctor) const;
385 * Call this method when you want to iterate all the
386 * members of the container, calling the functor you
387 * passed with each member. This process will interrupt
388 * if your function returns non 0 to this method.
390 * @param aFunctor object to call for each member
391 * @return first nonzero result of aFunctor or 0.
393 const void* FirstThat(nsDequeFunctor& aFunctor) const;
395 protected:
397 PRInt32 mIndex;
398 const nsDeque& mDeque;
400 #endif