Bug 630001, part2 - fix nsAccUtils::TextLength to not use nsIFrame::GetRenderedText...
[mozilla-central.git] / xpcom / ds / nsSupportsArray.h
blob617ed3210e1fa38ae8e424e6e2aaf9d77556c4cb
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
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 #ifndef nsSupportsArray_h__
39 #define nsSupportsArray_h__
41 //#define DEBUG_SUPPORTSARRAY 1
43 #include "nsISupportsArray.h"
45 static const PRUint32 kAutoArraySize = 8;
47 // Set IMETHOD_VISIBILITY to empty so that the class-level NS_COM declaration
48 // controls member method visibility.
49 #undef IMETHOD_VISIBILITY
50 #define IMETHOD_VISIBILITY
52 class NS_COM nsSupportsArray : public nsISupportsArray {
53 public:
54 nsSupportsArray(void);
55 ~nsSupportsArray(void); // nonvirtual since we're not subclassed
57 static nsresult
58 Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
60 NS_DECL_ISUPPORTS
62 NS_DECL_NSISERIALIZABLE
64 // nsICollection methods:
65 NS_IMETHOD Count(PRUint32 *result) { *result = mCount; return NS_OK; }
66 NS_IMETHOD GetElementAt(PRUint32 aIndex, nsISupports* *result) {
67 *result = ElementAt(aIndex);
68 return NS_OK;
70 NS_IMETHOD QueryElementAt(PRUint32 aIndex, const nsIID & aIID, void * *aResult) {
71 if (aIndex < mCount) {
72 nsISupports* element = mArray[aIndex];
73 if (nsnull != element)
74 return element->QueryInterface(aIID, aResult);
76 return NS_ERROR_FAILURE;
78 NS_IMETHOD SetElementAt(PRUint32 aIndex, nsISupports* value) {
79 return ReplaceElementAt(value, aIndex) ? NS_OK : NS_ERROR_FAILURE;
81 NS_IMETHOD AppendElement(nsISupports *aElement) {
82 return InsertElementAt(aElement, mCount)/* ? NS_OK : NS_ERROR_FAILURE*/;
84 // XXX this is badly named - should be RemoveFirstElement
85 NS_IMETHOD RemoveElement(nsISupports *aElement) {
86 return RemoveElement(aElement, 0)/* ? NS_OK : NS_ERROR_FAILURE*/;
88 NS_IMETHOD_(PRBool) MoveElement(PRInt32 aFrom, PRInt32 aTo);
89 NS_IMETHOD Enumerate(nsIEnumerator* *result);
90 NS_IMETHOD Clear(void);
92 // nsISupportsArray methods:
93 NS_IMETHOD_(PRBool) Equals(const nsISupportsArray* aOther);
95 NS_IMETHOD_(nsISupports*) ElementAt(PRUint32 aIndex);
97 NS_IMETHOD_(PRInt32) IndexOf(const nsISupports* aPossibleElement);
98 NS_IMETHOD_(PRInt32) IndexOfStartingAt(const nsISupports* aPossibleElement,
99 PRUint32 aStartIndex = 0);
100 NS_IMETHOD_(PRInt32) LastIndexOf(const nsISupports* aPossibleElement);
102 NS_IMETHOD GetIndexOf(nsISupports *aPossibleElement, PRInt32 *_retval) {
103 *_retval = IndexOf(aPossibleElement);
104 return NS_OK;
107 NS_IMETHOD GetIndexOfStartingAt(nsISupports *aPossibleElement,
108 PRUint32 aStartIndex, PRInt32 *_retval) {
109 *_retval = IndexOfStartingAt(aPossibleElement, aStartIndex);
110 return NS_OK;
113 NS_IMETHOD GetLastIndexOf(nsISupports *aPossibleElement, PRInt32 *_retval) {
114 *_retval = LastIndexOf(aPossibleElement);
115 return NS_OK;
118 NS_IMETHOD_(PRBool) InsertElementAt(nsISupports* aElement, PRUint32 aIndex);
120 NS_IMETHOD_(PRBool) ReplaceElementAt(nsISupports* aElement, PRUint32 aIndex);
122 NS_IMETHOD_(PRBool) RemoveElementAt(PRUint32 aIndex) {
123 return RemoveElementsAt(aIndex,1);
125 NS_IMETHOD_(PRBool) RemoveElement(const nsISupports* aElement, PRUint32 aStartIndex = 0);
126 NS_IMETHOD_(PRBool) RemoveLastElement(const nsISupports* aElement);
128 NS_IMETHOD DeleteLastElement(nsISupports *aElement) {
129 return (RemoveLastElement(aElement) ? NS_OK : NS_ERROR_FAILURE);
132 NS_IMETHOD DeleteElementAt(PRUint32 aIndex) {
133 return (RemoveElementAt(aIndex) ? NS_OK : NS_ERROR_FAILURE);
136 NS_IMETHOD_(PRBool) AppendElements(nsISupportsArray* aElements) {
137 return InsertElementsAt(aElements,mCount);
140 NS_IMETHOD Compact(void);
142 NS_IMETHOD_(PRBool) EnumerateForwards(nsISupportsArrayEnumFunc aFunc, void* aData);
143 NS_IMETHOD_(PRBool) EnumerateBackwards(nsISupportsArrayEnumFunc aFunc, void* aData);
145 NS_IMETHOD Clone(nsISupportsArray **_retval);
147 NS_IMETHOD_(PRBool) InsertElementsAt(nsISupportsArray *aOther, PRUint32 aIndex);
149 NS_IMETHOD_(PRBool) RemoveElementsAt(PRUint32 aIndex, PRUint32 aCount);
151 NS_IMETHOD_(PRBool) SizeTo(PRInt32 aSize);
152 protected:
153 void DeleteArray(void);
155 NS_IMETHOD_(PRBool) GrowArrayBy(PRInt32 aGrowBy);
157 nsISupports** mArray;
158 PRUint32 mArraySize;
159 PRUint32 mCount;
160 nsISupports* mAutoArray[kAutoArraySize];
161 #if DEBUG_SUPPORTSARRAY
162 PRUint32 mMaxCount;
163 PRUint32 mMaxSize;
164 #endif
166 private:
167 // Copy constructors are not allowed
168 nsSupportsArray(const nsISupportsArray& other);
171 #endif // nsSupportsArray_h__