VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/ds/nsSupportsArray.h@ 6542

Last change on this file since 6542 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1/* -*- Mode: C++; tab-width: 4; 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#ifndef nsSupportsArray_h__
39#define nsSupportsArray_h__
40
41//#define DEBUG_SUPPORTSARRAY 1
42
43#include "nsISupportsArray.h"
44
45static const PRUint32 kAutoArraySize = 8;
46
47#undef IMETHOD_VISIBILITY
48#define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT
49
50class NS_COM nsSupportsArray : public nsISupportsArray {
51public:
52 nsSupportsArray(void);
53 ~nsSupportsArray(void); // nonvirtual since we're not subclassed
54
55 static NS_METHOD
56 Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
57
58 NS_DECL_ISUPPORTS
59
60 NS_DECL_NSISERIALIZABLE
61
62 // nsICollection methods:
63 NS_IMETHOD Count(PRUint32 *result) { *result = mCount; return NS_OK; }
64 NS_IMETHOD GetElementAt(PRUint32 aIndex, nsISupports* *result) {
65 *result = ElementAt(aIndex);
66 return NS_OK;
67 }
68 NS_IMETHOD QueryElementAt(PRUint32 aIndex, const nsIID & aIID, void * *aResult) {
69 if (aIndex < mCount) {
70 nsISupports* element = mArray[aIndex];
71 if (nsnull != element)
72 return element->QueryInterface(aIID, aResult);
73 }
74 return NS_ERROR_FAILURE;
75 }
76 NS_IMETHOD SetElementAt(PRUint32 aIndex, nsISupports* value) {
77 return ReplaceElementAt(value, aIndex) ? NS_OK : NS_ERROR_FAILURE;
78 }
79 NS_IMETHOD AppendElement(nsISupports *aElement) {
80 return InsertElementAt(aElement, mCount)/* ? NS_OK : NS_ERROR_FAILURE*/;
81 }
82 // XXX this is badly named - should be RemoveFirstElement
83 NS_IMETHOD RemoveElement(nsISupports *aElement) {
84 return RemoveElement(aElement, 0)/* ? NS_OK : NS_ERROR_FAILURE*/;
85 }
86 NS_IMETHOD_(PRBool) MoveElement(PRInt32 aFrom, PRInt32 aTo);
87 NS_IMETHOD Enumerate(nsIEnumerator* *result);
88 NS_IMETHOD Clear(void);
89
90 // nsISupportsArray methods:
91 NS_IMETHOD_(PRBool) Equals(const nsISupportsArray* aOther);
92
93 NS_IMETHOD_(nsISupports*) ElementAt(PRUint32 aIndex);
94
95 NS_IMETHOD_(PRInt32) IndexOf(const nsISupports* aPossibleElement);
96 NS_IMETHOD_(PRInt32) IndexOfStartingAt(const nsISupports* aPossibleElement,
97 PRUint32 aStartIndex = 0);
98 NS_IMETHOD_(PRInt32) LastIndexOf(const nsISupports* aPossibleElement);
99
100 NS_IMETHOD GetIndexOf(nsISupports *aPossibleElement, PRInt32 *_retval) {
101 *_retval = IndexOf(aPossibleElement);
102 return NS_OK;
103 }
104
105 NS_IMETHOD GetIndexOfStartingAt(nsISupports *aPossibleElement,
106 PRUint32 aStartIndex, PRInt32 *_retval) {
107 *_retval = IndexOfStartingAt(aPossibleElement, aStartIndex);
108 return NS_OK;
109 }
110
111 NS_IMETHOD GetLastIndexOf(nsISupports *aPossibleElement, PRInt32 *_retval) {
112 *_retval = LastIndexOf(aPossibleElement);
113 return NS_OK;
114 }
115
116 NS_IMETHOD_(PRBool) InsertElementAt(nsISupports* aElement, PRUint32 aIndex);
117
118 NS_IMETHOD_(PRBool) ReplaceElementAt(nsISupports* aElement, PRUint32 aIndex);
119
120 NS_IMETHOD_(PRBool) RemoveElementAt(PRUint32 aIndex) {
121 return RemoveElementsAt(aIndex,1);
122 }
123 NS_IMETHOD_(PRBool) RemoveElement(const nsISupports* aElement, PRUint32 aStartIndex = 0);
124 NS_IMETHOD_(PRBool) RemoveLastElement(const nsISupports* aElement);
125
126 NS_IMETHOD DeleteLastElement(nsISupports *aElement) {
127 return (RemoveLastElement(aElement) ? NS_OK : NS_ERROR_FAILURE);
128 }
129
130 NS_IMETHOD DeleteElementAt(PRUint32 aIndex) {
131 return (RemoveElementAt(aIndex) ? NS_OK : NS_ERROR_FAILURE);
132 }
133
134 NS_IMETHOD_(PRBool) AppendElements(nsISupportsArray* aElements) {
135 return InsertElementsAt(aElements,mCount);
136 }
137
138 NS_IMETHOD Compact(void);
139
140 NS_IMETHOD_(PRBool) EnumerateForwards(nsISupportsArrayEnumFunc aFunc, void* aData);
141 NS_IMETHOD_(PRBool) EnumerateBackwards(nsISupportsArrayEnumFunc aFunc, void* aData);
142
143 NS_IMETHOD Clone(nsISupportsArray **_retval);
144
145 NS_IMETHOD_(PRBool) InsertElementsAt(nsISupportsArray *aOther, PRUint32 aIndex);
146
147 NS_IMETHOD_(PRBool) RemoveElementsAt(PRUint32 aIndex, PRUint32 aCount);
148
149 NS_IMETHOD_(PRBool) SizeTo(PRInt32 aSize);
150protected:
151 void DeleteArray(void);
152
153 NS_IMETHOD_(PRBool) GrowArrayBy(PRInt32 aGrowBy);
154
155 nsISupports** mArray;
156 PRUint32 mArraySize;
157 PRUint32 mCount;
158 nsISupports* mAutoArray[kAutoArraySize];
159#if DEBUG_SUPPORTSARRAY
160 PRUint32 mMaxCount;
161 PRUint32 mMaxSize;
162#endif
163
164private:
165 // Copy constructors are not allowed
166 nsSupportsArray(const nsISupportsArray& other);
167};
168
169#undef IMETHOD_VISIBILITY
170#define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
171
172#endif // nsSupportsArray_h__
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