VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/ds/nsDeque.h

Last change on this file was 101927, checked in by vboxsync, 13 months ago

libs/xpcom: Remove unused code in nsDeque.{cpp,h}, bugref:10545

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
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
4 *
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/
9 *
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.
14 *
15 * The Original Code is mozilla.org code.
16 *
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.
21 *
22 * Contributor(s):
23 *
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.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/**
39 * MODULE NOTES:
40 *
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.
46 *
47 *
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.
53 *
54 */
55
56#ifndef _NSDEQUE
57#define _NSDEQUE
58
59#include "nscore.h"
60
61/******************************************************
62 * Here comes the nsDeque class itself...
63 ******************************************************/
64
65/**
66 * The deque (double-ended queue) class is a common container type,
67 * whose behavior mimics a line in your favorite checkout stand.
68 * Classic CS describes the common behavior of a queue as FIFO.
69 * A deque allows insertion and removal at both ends of
70 * the container.
71 *
72 * The deque stores pointers to items.
73 */
74class NS_COM nsDeque {
75 public:
76 nsDeque();
77 ~nsDeque();
78
79 /**
80 * Returns the number of elements currently stored in
81 * this deque.
82 *
83 * @return number of elements currently in the deque
84 */
85 inline PRInt32 GetSize() const {return mSize;}
86
87 /**
88 * Appends new member at the end of the deque.
89 *
90 * @param item to store in deque
91 * @return *this
92 */
93 nsDeque& Push(void* aItem);
94
95 /**
96 * Inserts new member at the front of the deque.
97 *
98 * @param item to store in deque
99 * @return *this
100 */
101 nsDeque& PushFront(void* aItem);
102
103 /**
104 * Remove and return the last item in the container.
105 *
106 * @return the item that was the last item in container
107 */
108 void* Pop();
109
110 /**
111 * Remove and return the first item in the container.
112 *
113 * @return the item that was first item in container
114 */
115 void* PopFront();
116
117 /**
118 * Retrieve the bottom item without removing it.
119 *
120 * @return the first item in container
121 */
122
123 void* Peek();
124 /**
125 * Return topmost item without removing it.
126 *
127 * @return the first item in container
128 */
129 void* PeekFront();
130
131 /**
132 * Retrieve the i'th member from the deque without removing it.
133 *
134 * @param index of desired item
135 * @return i'th element in list
136 */
137 void* ObjectAt(int aIndex) const;
138
139 /**
140 * Remove all items from container without destroying them.
141 *
142 * @return *this
143 */
144 nsDeque& Empty();
145
146 /**
147 * Remove and delete all items from container.
148 * Deletes are handled by the deallocator nsDequeFunctor
149 * which is specified at deque construction.
150 *
151 * @return *this
152 */
153 nsDeque& Erase();
154
155protected:
156 PRInt32 mSize;
157 PRInt32 mCapacity;
158 PRInt32 mOrigin;
159 void* mBuffer[8];
160 void** mData;
161
162private:
163
164 /**
165 * Copy constructor (PRIVATE)
166 *
167 * @param another deque
168 */
169 nsDeque(const nsDeque& other);
170
171 /**
172 * Deque assignment operator (PRIVATE)
173 *
174 * @param another deque
175 * @return *this
176 */
177 nsDeque& operator=(const nsDeque& anOther);
178
179 PRInt32 GrowCapacity();
180};
181
182#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette