xpcom/ds/nsSupportsArray.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/ds/nsSupportsArray.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsSupportsArray_h__
    1.10 +#define nsSupportsArray_h__
    1.11 +
    1.12 +//#define DEBUG_SUPPORTSARRAY 1
    1.13 +
    1.14 +#include "nsISupportsArray.h"
    1.15 +#include "mozilla/Attributes.h"
    1.16 +
    1.17 +static const uint32_t kAutoArraySize = 8;
    1.18 +
    1.19 +class nsSupportsArray MOZ_FINAL : public nsISupportsArray {
    1.20 +public:
    1.21 +  nsSupportsArray(void);
    1.22 +  ~nsSupportsArray(void); // nonvirtual since we're not subclassed
    1.23 +
    1.24 +  static nsresult
    1.25 +  Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
    1.26 +
    1.27 +  NS_DECL_THREADSAFE_ISUPPORTS
    1.28 +
    1.29 +  NS_DECL_NSISERIALIZABLE
    1.30 +
    1.31 +  // nsICollection methods:
    1.32 +  NS_IMETHOD Count(uint32_t *result) { *result = mCount; return NS_OK; }
    1.33 +  NS_IMETHOD GetElementAt(uint32_t aIndex, nsISupports* *result);
    1.34 +  NS_IMETHOD QueryElementAt(uint32_t aIndex, const nsIID & aIID, void * *aResult) {
    1.35 +    if (aIndex < mCount) {
    1.36 +      nsISupports* element = mArray[aIndex];
    1.37 +      if (nullptr != element)
    1.38 +        return element->QueryInterface(aIID, aResult);
    1.39 +    }
    1.40 +    return NS_ERROR_FAILURE;
    1.41 +  }
    1.42 +  NS_IMETHOD SetElementAt(uint32_t aIndex, nsISupports* value) {
    1.43 +    return ReplaceElementAt(value, aIndex) ? NS_OK : NS_ERROR_FAILURE;
    1.44 +  }
    1.45 +  NS_IMETHOD AppendElement(nsISupports *aElement) {
    1.46 +    // XXX Invalid cast of bool to nsresult (bug 778110)
    1.47 +    return (nsresult)InsertElementAt(aElement, mCount)/* ? NS_OK : NS_ERROR_FAILURE*/;
    1.48 +  }
    1.49 +  // XXX this is badly named - should be RemoveFirstElement
    1.50 +  NS_IMETHOD RemoveElement(nsISupports *aElement) {
    1.51 +    // XXX Invalid cast of bool to nsresult (bug 778110)
    1.52 +    return (nsresult)RemoveElement(aElement, 0)/* ? NS_OK : NS_ERROR_FAILURE*/;
    1.53 +  }
    1.54 +  NS_IMETHOD_(bool) MoveElement(int32_t aFrom, int32_t aTo);
    1.55 +  NS_IMETHOD Enumerate(nsIEnumerator* *result);
    1.56 +  NS_IMETHOD Clear(void);
    1.57 +
    1.58 +  // nsISupportsArray methods:
    1.59 +  NS_IMETHOD_(bool) Equals(const nsISupportsArray* aOther);
    1.60 +
    1.61 +  NS_IMETHOD_(int32_t) IndexOf(const nsISupports* aPossibleElement);
    1.62 +  NS_IMETHOD_(int32_t) IndexOfStartingAt(const nsISupports* aPossibleElement,
    1.63 +                                         uint32_t aStartIndex = 0);
    1.64 +  NS_IMETHOD_(int32_t) LastIndexOf(const nsISupports* aPossibleElement);
    1.65 +
    1.66 +  NS_IMETHOD GetIndexOf(nsISupports *aPossibleElement, int32_t *_retval) {
    1.67 +    *_retval = IndexOf(aPossibleElement);
    1.68 +    return NS_OK;
    1.69 +  }
    1.70 +  
    1.71 +  NS_IMETHOD GetIndexOfStartingAt(nsISupports *aPossibleElement,
    1.72 +                                  uint32_t aStartIndex, int32_t *_retval) {
    1.73 +    *_retval = IndexOfStartingAt(aPossibleElement, aStartIndex);
    1.74 +    return NS_OK;
    1.75 +  }
    1.76 +  
    1.77 +  NS_IMETHOD GetLastIndexOf(nsISupports *aPossibleElement, int32_t *_retval) {
    1.78 +    *_retval = LastIndexOf(aPossibleElement);
    1.79 +    return NS_OK;
    1.80 +  }
    1.81 +  
    1.82 +  NS_IMETHOD_(bool) InsertElementAt(nsISupports* aElement, uint32_t aIndex);
    1.83 +
    1.84 +  NS_IMETHOD_(bool) ReplaceElementAt(nsISupports* aElement, uint32_t aIndex);
    1.85 +
    1.86 +  NS_IMETHOD_(bool) RemoveElementAt(uint32_t aIndex) {
    1.87 +    return RemoveElementsAt(aIndex,1);
    1.88 +  }
    1.89 +  NS_IMETHOD_(bool) RemoveElement(const nsISupports* aElement, uint32_t aStartIndex = 0);
    1.90 +  NS_IMETHOD_(bool) RemoveLastElement(const nsISupports* aElement);
    1.91 +
    1.92 +  NS_IMETHOD DeleteLastElement(nsISupports *aElement) {
    1.93 +    return (RemoveLastElement(aElement) ? NS_OK : NS_ERROR_FAILURE);
    1.94 +  }
    1.95 +  
    1.96 +  NS_IMETHOD DeleteElementAt(uint32_t aIndex) {
    1.97 +    return (RemoveElementAt(aIndex) ? NS_OK : NS_ERROR_FAILURE);
    1.98 +  }
    1.99 +  
   1.100 +  NS_IMETHOD_(bool) AppendElements(nsISupportsArray* aElements) {
   1.101 +    return InsertElementsAt(aElements,mCount);
   1.102 +  }
   1.103 +  
   1.104 +  NS_IMETHOD Compact(void);
   1.105 +
   1.106 +  NS_IMETHOD Clone(nsISupportsArray **_retval);
   1.107 +
   1.108 +  NS_IMETHOD_(bool) InsertElementsAt(nsISupportsArray *aOther, uint32_t aIndex);
   1.109 +
   1.110 +  NS_IMETHOD_(bool) RemoveElementsAt(uint32_t aIndex, uint32_t aCount);
   1.111 +
   1.112 +  NS_IMETHOD_(bool) SizeTo(int32_t aSize);
   1.113 +protected:
   1.114 +  void DeleteArray(void);
   1.115 +
   1.116 +  NS_IMETHOD_(void) GrowArrayBy(int32_t aGrowBy);
   1.117 +
   1.118 +  nsISupports** mArray;
   1.119 +  uint32_t mArraySize;
   1.120 +  uint32_t mCount;
   1.121 +  nsISupports*  mAutoArray[kAutoArraySize];
   1.122 +#if DEBUG_SUPPORTSARRAY
   1.123 +  uint32_t mMaxCount;
   1.124 +  uint32_t mMaxSize;
   1.125 +#endif
   1.126 +
   1.127 +private:
   1.128 +  // Copy constructors are not allowed
   1.129 +  nsSupportsArray(const nsISupportsArray& other);
   1.130 +};
   1.131 +
   1.132 +#endif // nsSupportsArray_h__

mercurial