2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsSupportsArray_h__
|
|
|
|
#define nsSupportsArray_h__
|
|
|
|
|
|
|
|
//#define DEBUG_SUPPORTSARRAY 1
|
|
|
|
|
|
|
|
#include "nsISupportsArray.h"
|
2012-06-05 16:51:58 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static const uint32_t kAutoArraySize = 8;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-05 16:51:58 -07:00
|
|
|
class nsSupportsArray MOZ_FINAL : public nsISupportsArray {
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
nsSupportsArray(void);
|
|
|
|
~nsSupportsArray(void); // nonvirtual since we're not subclassed
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
static nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_DECL_NSISERIALIZABLE
|
|
|
|
|
|
|
|
// nsICollection methods:
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD Count(uint32_t *result) { *result = mCount; return NS_OK; }
|
|
|
|
NS_IMETHOD GetElementAt(uint32_t aIndex, nsISupports* *result) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*result = ElementAt(aIndex);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD QueryElementAt(uint32_t aIndex, const nsIID & aIID, void * *aResult) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aIndex < mCount) {
|
|
|
|
nsISupports* element = mArray[aIndex];
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != element)
|
2007-03-22 10:30:00 -07:00
|
|
|
return element->QueryInterface(aIID, aResult);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD SetElementAt(uint32_t aIndex, nsISupports* value) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return ReplaceElementAt(value, aIndex) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
NS_IMETHOD AppendElement(nsISupports *aElement) {
|
2012-07-27 07:03:25 -07:00
|
|
|
// XXX Invalid cast of bool to nsresult (bug 778110)
|
|
|
|
return (nsresult)InsertElementAt(aElement, mCount)/* ? NS_OK : NS_ERROR_FAILURE*/;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// XXX this is badly named - should be RemoveFirstElement
|
|
|
|
NS_IMETHOD RemoveElement(nsISupports *aElement) {
|
2012-07-27 07:03:25 -07:00
|
|
|
// XXX Invalid cast of bool to nsresult (bug 778110)
|
|
|
|
return (nsresult)RemoveElement(aElement, 0)/* ? NS_OK : NS_ERROR_FAILURE*/;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD_(bool) MoveElement(int32_t aFrom, int32_t aTo);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD Enumerate(nsIEnumerator* *result);
|
|
|
|
NS_IMETHOD Clear(void);
|
|
|
|
|
|
|
|
// nsISupportsArray methods:
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD_(bool) Equals(const nsISupportsArray* aOther);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD_(nsISupports*) ElementAt(uint32_t aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD_(int32_t) IndexOf(const nsISupports* aPossibleElement);
|
|
|
|
NS_IMETHOD_(int32_t) IndexOfStartingAt(const nsISupports* aPossibleElement,
|
|
|
|
uint32_t aStartIndex = 0);
|
|
|
|
NS_IMETHOD_(int32_t) LastIndexOf(const nsISupports* aPossibleElement);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD GetIndexOf(nsISupports *aPossibleElement, int32_t *_retval) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*_retval = IndexOf(aPossibleElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetIndexOfStartingAt(nsISupports *aPossibleElement,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aStartIndex, int32_t *_retval) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*_retval = IndexOfStartingAt(aPossibleElement, aStartIndex);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD GetLastIndexOf(nsISupports *aPossibleElement, int32_t *_retval) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*_retval = LastIndexOf(aPossibleElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD_(bool) InsertElementAt(nsISupports* aElement, uint32_t aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD_(bool) ReplaceElementAt(nsISupports* aElement, uint32_t aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD_(bool) RemoveElementAt(uint32_t aIndex) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return RemoveElementsAt(aIndex,1);
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD_(bool) RemoveElement(const nsISupports* aElement, uint32_t aStartIndex = 0);
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD_(bool) RemoveLastElement(const nsISupports* aElement);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD DeleteLastElement(nsISupports *aElement) {
|
|
|
|
return (RemoveLastElement(aElement) ? NS_OK : NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD DeleteElementAt(uint32_t aIndex) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return (RemoveElementAt(aIndex) ? NS_OK : NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD_(bool) AppendElements(nsISupportsArray* aElements) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return InsertElementsAt(aElements,mCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Compact(void);
|
|
|
|
|
|
|
|
NS_IMETHOD Clone(nsISupportsArray **_retval);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD_(bool) InsertElementsAt(nsISupportsArray *aOther, uint32_t aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD_(bool) RemoveElementsAt(uint32_t aIndex, uint32_t aCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD_(bool) SizeTo(int32_t aSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
void DeleteArray(void);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD_(void) GrowArrayBy(int32_t aGrowBy);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsISupports** mArray;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mArraySize;
|
|
|
|
uint32_t mCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsISupports* mAutoArray[kAutoArraySize];
|
|
|
|
#if DEBUG_SUPPORTSARRAY
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mMaxCount;
|
|
|
|
uint32_t mMaxSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Copy constructors are not allowed
|
|
|
|
nsSupportsArray(const nsISupportsArray& other);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsSupportsArray_h__
|