Backed out changeset 4c2bc5ae8f95 (bug 945562) for device image bustage.
[gecko.git] / xpcom / ds / nsSupportsArray.h
blob6346513604b37037e163d5da06397808e9f1b585
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsSupportsArray_h__
7 #define nsSupportsArray_h__
9 //#define DEBUG_SUPPORTSARRAY 1
11 #include "nsISupportsArray.h"
12 #include "mozilla/Attributes.h"
14 static const uint32_t kAutoArraySize = 8;
16 class nsSupportsArray MOZ_FINAL : public nsISupportsArray {
17 public:
18 nsSupportsArray(void);
19 ~nsSupportsArray(void); // nonvirtual since we're not subclassed
21 static nsresult
22 Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
24 NS_DECL_THREADSAFE_ISUPPORTS
26 NS_DECL_NSISERIALIZABLE
28 // nsICollection methods:
29 NS_IMETHOD Count(uint32_t *result) { *result = mCount; return NS_OK; }
30 NS_IMETHOD GetElementAt(uint32_t aIndex, nsISupports* *result);
31 NS_IMETHOD QueryElementAt(uint32_t aIndex, const nsIID & aIID, void * *aResult) {
32 if (aIndex < mCount) {
33 nsISupports* element = mArray[aIndex];
34 if (nullptr != element)
35 return element->QueryInterface(aIID, aResult);
37 return NS_ERROR_FAILURE;
39 NS_IMETHOD SetElementAt(uint32_t aIndex, nsISupports* value) {
40 return ReplaceElementAt(value, aIndex) ? NS_OK : NS_ERROR_FAILURE;
42 NS_IMETHOD AppendElement(nsISupports *aElement) {
43 // XXX Invalid cast of bool to nsresult (bug 778110)
44 return (nsresult)InsertElementAt(aElement, mCount)/* ? NS_OK : NS_ERROR_FAILURE*/;
46 // XXX this is badly named - should be RemoveFirstElement
47 NS_IMETHOD RemoveElement(nsISupports *aElement) {
48 // XXX Invalid cast of bool to nsresult (bug 778110)
49 return (nsresult)RemoveElement(aElement, 0)/* ? NS_OK : NS_ERROR_FAILURE*/;
51 NS_IMETHOD_(bool) MoveElement(int32_t aFrom, int32_t aTo);
52 NS_IMETHOD Enumerate(nsIEnumerator* *result);
53 NS_IMETHOD Clear(void);
55 // nsISupportsArray methods:
56 NS_IMETHOD_(bool) Equals(const nsISupportsArray* aOther);
58 NS_IMETHOD_(int32_t) IndexOf(const nsISupports* aPossibleElement);
59 NS_IMETHOD_(int32_t) IndexOfStartingAt(const nsISupports* aPossibleElement,
60 uint32_t aStartIndex = 0);
61 NS_IMETHOD_(int32_t) LastIndexOf(const nsISupports* aPossibleElement);
63 NS_IMETHOD GetIndexOf(nsISupports *aPossibleElement, int32_t *_retval) {
64 *_retval = IndexOf(aPossibleElement);
65 return NS_OK;
68 NS_IMETHOD GetIndexOfStartingAt(nsISupports *aPossibleElement,
69 uint32_t aStartIndex, int32_t *_retval) {
70 *_retval = IndexOfStartingAt(aPossibleElement, aStartIndex);
71 return NS_OK;
74 NS_IMETHOD GetLastIndexOf(nsISupports *aPossibleElement, int32_t *_retval) {
75 *_retval = LastIndexOf(aPossibleElement);
76 return NS_OK;
79 NS_IMETHOD_(bool) InsertElementAt(nsISupports* aElement, uint32_t aIndex);
81 NS_IMETHOD_(bool) ReplaceElementAt(nsISupports* aElement, uint32_t aIndex);
83 NS_IMETHOD_(bool) RemoveElementAt(uint32_t aIndex) {
84 return RemoveElementsAt(aIndex,1);
86 NS_IMETHOD_(bool) RemoveElement(const nsISupports* aElement, uint32_t aStartIndex = 0);
87 NS_IMETHOD_(bool) RemoveLastElement(const nsISupports* aElement);
89 NS_IMETHOD DeleteLastElement(nsISupports *aElement) {
90 return (RemoveLastElement(aElement) ? NS_OK : NS_ERROR_FAILURE);
93 NS_IMETHOD DeleteElementAt(uint32_t aIndex) {
94 return (RemoveElementAt(aIndex) ? NS_OK : NS_ERROR_FAILURE);
97 NS_IMETHOD_(bool) AppendElements(nsISupportsArray* aElements) {
98 return InsertElementsAt(aElements,mCount);
101 NS_IMETHOD Compact(void);
103 NS_IMETHOD Clone(nsISupportsArray **_retval);
105 NS_IMETHOD_(bool) InsertElementsAt(nsISupportsArray *aOther, uint32_t aIndex);
107 NS_IMETHOD_(bool) RemoveElementsAt(uint32_t aIndex, uint32_t aCount);
109 NS_IMETHOD_(bool) SizeTo(int32_t aSize);
110 protected:
111 void DeleteArray(void);
113 NS_IMETHOD_(void) GrowArrayBy(int32_t aGrowBy);
115 nsISupports** mArray;
116 uint32_t mArraySize;
117 uint32_t mCount;
118 nsISupports* mAutoArray[kAutoArraySize];
119 #if DEBUG_SUPPORTSARRAY
120 uint32_t mMaxCount;
121 uint32_t mMaxSize;
122 #endif
124 private:
125 // Copy constructors are not allowed
126 nsSupportsArray(const nsISupportsArray& other);
129 #endif // nsSupportsArray_h__