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.

     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);
    36     }
    37     return NS_ERROR_FAILURE;
    38   }
    39   NS_IMETHOD SetElementAt(uint32_t aIndex, nsISupports* value) {
    40     return ReplaceElementAt(value, aIndex) ? NS_OK : NS_ERROR_FAILURE;
    41   }
    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*/;
    45   }
    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*/;
    50   }
    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;
    66   }
    68   NS_IMETHOD GetIndexOfStartingAt(nsISupports *aPossibleElement,
    69                                   uint32_t aStartIndex, int32_t *_retval) {
    70     *_retval = IndexOfStartingAt(aPossibleElement, aStartIndex);
    71     return NS_OK;
    72   }
    74   NS_IMETHOD GetLastIndexOf(nsISupports *aPossibleElement, int32_t *_retval) {
    75     *_retval = LastIndexOf(aPossibleElement);
    76     return NS_OK;
    77   }
    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);
    85   }
    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);
    91   }
    93   NS_IMETHOD DeleteElementAt(uint32_t aIndex) {
    94     return (RemoveElementAt(aIndex) ? NS_OK : NS_ERROR_FAILURE);
    95   }
    97   NS_IMETHOD_(bool) AppendElements(nsISupportsArray* aElements) {
    98     return InsertElementsAt(aElements,mCount);
    99   }
   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);
   127 };
   129 #endif // nsSupportsArray_h__

mercurial