Bumping manifests a=b2g-bump
[gecko.git] / xpcom / ds / nsSupportsArray.h
blob51d4e7a3e59a205906ed3b79d2d0a5ce48e71ab2
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
18 ~nsSupportsArray(void); // nonvirtual since we're not subclassed
20 public:
21 nsSupportsArray(void);
22 static nsresult 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* aResult)
31 *aResult = mCount;
32 return NS_OK;
34 NS_IMETHOD GetElementAt(uint32_t aIndex, nsISupports** aResult);
35 NS_IMETHOD QueryElementAt(uint32_t aIndex, const nsIID& aIID, void** aResult)
37 if (aIndex < mCount) {
38 nsISupports* element = mArray[aIndex];
39 if (element) {
40 return element->QueryInterface(aIID, aResult);
43 return NS_ERROR_FAILURE;
45 NS_IMETHOD SetElementAt(uint32_t aIndex, nsISupports* aValue)
47 return ReplaceElementAt(aValue, aIndex) ? NS_OK : NS_ERROR_FAILURE;
49 NS_IMETHOD AppendElement(nsISupports* aElement)
51 // XXX Invalid cast of bool to nsresult (bug 778110)
52 return (nsresult)InsertElementAt(aElement, mCount)/* ? NS_OK : NS_ERROR_FAILURE*/;
54 // XXX this is badly named - should be RemoveFirstElement
55 NS_IMETHOD RemoveElement(nsISupports* aElement)
57 // XXX Invalid cast of bool to nsresult (bug 778110)
58 return (nsresult)RemoveElement(aElement, 0)/* ? NS_OK : NS_ERROR_FAILURE*/;
60 NS_IMETHOD_(bool) MoveElement(int32_t aFrom, int32_t aTo);
61 NS_IMETHOD Enumerate(nsIEnumerator** aResult);
62 NS_IMETHOD Clear(void);
64 // nsISupportsArray methods:
65 NS_IMETHOD_(bool) Equals(const nsISupportsArray* aOther);
67 NS_IMETHOD_(int32_t) IndexOf(const nsISupports* aPossibleElement);
68 NS_IMETHOD_(int32_t) IndexOfStartingAt(const nsISupports* aPossibleElement,
69 uint32_t aStartIndex = 0);
70 NS_IMETHOD_(int32_t) LastIndexOf(const nsISupports* aPossibleElement);
72 NS_IMETHOD GetIndexOf(nsISupports* aPossibleElement, int32_t* aResult)
74 *aResult = IndexOf(aPossibleElement);
75 return NS_OK;
78 NS_IMETHOD GetIndexOfStartingAt(nsISupports* aPossibleElement,
79 uint32_t aStartIndex, int32_t* aResult)
81 *aResult = IndexOfStartingAt(aPossibleElement, aStartIndex);
82 return NS_OK;
85 NS_IMETHOD GetLastIndexOf(nsISupports* aPossibleElement, int32_t* aResult)
87 *aResult = LastIndexOf(aPossibleElement);
88 return NS_OK;
91 NS_IMETHOD_(bool) InsertElementAt(nsISupports* aElement, uint32_t aIndex);
93 NS_IMETHOD_(bool) ReplaceElementAt(nsISupports* aElement, uint32_t aIndex);
95 NS_IMETHOD_(bool) RemoveElementAt(uint32_t aIndex)
97 return RemoveElementsAt(aIndex, 1);
99 NS_IMETHOD_(bool) RemoveElement(const nsISupports* aElement,
100 uint32_t aStartIndex = 0);
101 NS_IMETHOD_(bool) RemoveLastElement(const nsISupports* aElement);
103 NS_IMETHOD DeleteLastElement(nsISupports* aElement)
105 return (RemoveLastElement(aElement) ? NS_OK : NS_ERROR_FAILURE);
108 NS_IMETHOD DeleteElementAt(uint32_t aIndex)
110 return (RemoveElementAt(aIndex) ? NS_OK : NS_ERROR_FAILURE);
113 NS_IMETHOD_(bool) AppendElements(nsISupportsArray* aElements)
115 return InsertElementsAt(aElements, mCount);
118 NS_IMETHOD Compact(void);
120 NS_IMETHOD Clone(nsISupportsArray** aResult);
122 NS_IMETHOD_(bool) InsertElementsAt(nsISupportsArray* aOther,
123 uint32_t aIndex);
125 NS_IMETHOD_(bool) RemoveElementsAt(uint32_t aIndex, uint32_t aCount);
127 NS_IMETHOD_(bool) SizeTo(int32_t aSize);
128 protected:
129 void DeleteArray(void);
131 NS_IMETHOD_(void) GrowArrayBy(int32_t aGrowBy);
133 nsISupports** mArray;
134 uint32_t mArraySize;
135 uint32_t mCount;
136 nsISupports* mAutoArray[kAutoArraySize];
137 #if DEBUG_SUPPORTSARRAY
138 uint32_t mMaxCount;
139 uint32_t mMaxSize;
140 #endif
142 private:
143 // Copy constructors are not allowed
144 explicit nsSupportsArray(const nsISupportsArray& aOther);
147 #endif // nsSupportsArray_h__