xpcom/ds/nsSupportsArray.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial