1999-02-23 11:04:28 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
1999-02-23 11:04:28 +03:00
|
|
|
|
|
|
|
#ifndef nsSupportsArray_h__
|
|
|
|
#define nsSupportsArray_h__
|
|
|
|
|
2001-08-07 10:23:40 +04:00
|
|
|
//#define DEBUG_SUPPORTSARRAY 1
|
|
|
|
|
1999-02-23 11:04:28 +03:00
|
|
|
#include "nsISupportsArray.h"
|
2012-06-06 03:51:58 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
1999-02-23 11:04:28 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static const uint32_t kAutoArraySize = 8;
|
1999-02-23 11:04:28 +03:00
|
|
|
|
2014-07-01 02:11:53 +04:00
|
|
|
class nsSupportsArray MOZ_FINAL : public nsISupportsArray
|
|
|
|
{
|
2014-07-01 02:50:19 +04:00
|
|
|
~nsSupportsArray(void); // nonvirtual since we're not subclassed
|
|
|
|
|
2014-07-01 02:11:53 +04:00
|
|
|
public:
|
|
|
|
nsSupportsArray(void);
|
2014-07-09 19:15:21 +04:00
|
|
|
static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
1999-05-26 05:38:36 +04:00
|
|
|
|
2013-07-19 06:31:26 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
1999-02-23 11:04:28 +03:00
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
NS_DECL_NSISERIALIZABLE
|
|
|
|
|
1999-02-23 11:04:28 +03:00
|
|
|
// nsICollection methods:
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD Count(uint32_t* aResult) MOZ_OVERRIDE
|
2014-07-09 19:15:21 +04:00
|
|
|
{
|
|
|
|
*aResult = mCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD GetElementAt(uint32_t aIndex, nsISupports** aResult) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD QueryElementAt(uint32_t aIndex, const nsIID& aIID, void** aResult) MOZ_OVERRIDE
|
2014-07-09 19:15:21 +04:00
|
|
|
{
|
1999-09-17 01:29:22 +04:00
|
|
|
if (aIndex < mCount) {
|
|
|
|
nsISupports* element = mArray[aIndex];
|
2014-07-09 19:15:21 +04:00
|
|
|
if (element) {
|
1999-09-17 01:29:22 +04:00
|
|
|
return element->QueryInterface(aIID, aResult);
|
2014-07-09 19:15:21 +04:00
|
|
|
}
|
1999-09-17 01:29:22 +04:00
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD SetElementAt(uint32_t aIndex, nsISupports* aValue) MOZ_OVERRIDE
|
2014-07-09 19:15:21 +04:00
|
|
|
{
|
|
|
|
return ReplaceElementAt(aValue, aIndex) ? NS_OK : NS_ERROR_FAILURE;
|
1999-05-13 08:56:04 +04:00
|
|
|
}
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD AppendElement(nsISupports* aElement) MOZ_OVERRIDE
|
2014-07-09 19:15:21 +04:00
|
|
|
{
|
2012-07-27 18:03:25 +04:00
|
|
|
// XXX Invalid cast of bool to nsresult (bug 778110)
|
|
|
|
return (nsresult)InsertElementAt(aElement, mCount)/* ? NS_OK : NS_ERROR_FAILURE*/;
|
1999-02-23 11:04:28 +03:00
|
|
|
}
|
2002-05-30 11:13:40 +04:00
|
|
|
// XXX this is badly named - should be RemoveFirstElement
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD RemoveElement(nsISupports* aElement) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD_(bool) MoveElement(int32_t aFrom, int32_t aTo) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD Enumerate(nsIEnumerator** aResult) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD Clear(void) MOZ_OVERRIDE;
|
1999-02-23 11:04:28 +03:00
|
|
|
|
|
|
|
// nsISupportsArray methods:
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD_(bool) Equals(const nsISupportsArray* aOther) MOZ_OVERRIDE;
|
1999-02-23 11:04:28 +03:00
|
|
|
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD_(int32_t) IndexOf(const nsISupports* aPossibleElement) MOZ_OVERRIDE;
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHOD_(int32_t) IndexOfStartingAt(const nsISupports* aPossibleElement,
|
2015-01-02 09:09:28 +03:00
|
|
|
uint32_t aStartIndex = 0) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD_(int32_t) LastIndexOf(const nsISupports* aPossibleElement) MOZ_OVERRIDE;
|
1999-02-23 11:04:28 +03:00
|
|
|
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD GetIndexOf(nsISupports* aPossibleElement, int32_t* aResult) MOZ_OVERRIDE
|
2014-07-09 19:15:21 +04:00
|
|
|
{
|
|
|
|
*aResult = IndexOf(aPossibleElement);
|
1999-06-02 06:06:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-07-09 19:15:21 +04:00
|
|
|
|
|
|
|
NS_IMETHOD GetIndexOfStartingAt(nsISupports* aPossibleElement,
|
2015-01-02 09:09:28 +03:00
|
|
|
uint32_t aStartIndex, int32_t* aResult) MOZ_OVERRIDE
|
2014-07-09 19:15:21 +04:00
|
|
|
{
|
|
|
|
*aResult = IndexOfStartingAt(aPossibleElement, aStartIndex);
|
1999-06-02 06:06:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-07-09 19:15:21 +04:00
|
|
|
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD GetLastIndexOf(nsISupports* aPossibleElement, int32_t* aResult) MOZ_OVERRIDE
|
2014-07-09 19:15:21 +04:00
|
|
|
{
|
|
|
|
*aResult = LastIndexOf(aPossibleElement);
|
1999-06-02 06:06:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-07-09 19:15:21 +04:00
|
|
|
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD_(bool) InsertElementAt(nsISupports* aElement, uint32_t aIndex) MOZ_OVERRIDE;
|
1999-02-23 11:04:28 +03:00
|
|
|
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD_(bool) ReplaceElementAt(nsISupports* aElement, uint32_t aIndex) MOZ_OVERRIDE;
|
1999-02-23 11:04:28 +03:00
|
|
|
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD_(bool) RemoveElementAt(uint32_t aIndex) MOZ_OVERRIDE
|
2014-07-09 19:15:21 +04:00
|
|
|
{
|
|
|
|
return RemoveElementsAt(aIndex, 1);
|
2001-08-07 10:23:40 +04:00
|
|
|
}
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD_(bool) RemoveLastElement(const nsISupports* aElement) MOZ_OVERRIDE;
|
1999-02-23 11:04:28 +03:00
|
|
|
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD DeleteLastElement(nsISupports* aElement) MOZ_OVERRIDE
|
2014-07-09 19:15:21 +04:00
|
|
|
{
|
1999-06-02 06:06:32 +04:00
|
|
|
return (RemoveLastElement(aElement) ? NS_OK : NS_ERROR_FAILURE);
|
|
|
|
}
|
2014-07-09 19:15:21 +04:00
|
|
|
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD DeleteElementAt(uint32_t aIndex) MOZ_OVERRIDE
|
2014-07-09 19:15:21 +04:00
|
|
|
{
|
1999-06-02 06:06:32 +04:00
|
|
|
return (RemoveElementAt(aIndex) ? NS_OK : NS_ERROR_FAILURE);
|
|
|
|
}
|
2014-07-09 19:15:21 +04:00
|
|
|
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD_(bool) AppendElements(nsISupportsArray* aElements) MOZ_OVERRIDE
|
2014-07-09 19:15:21 +04:00
|
|
|
{
|
|
|
|
return InsertElementsAt(aElements, mCount);
|
2001-08-07 10:23:40 +04:00
|
|
|
}
|
2014-07-09 19:15:21 +04:00
|
|
|
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD Compact(void) MOZ_OVERRIDE;
|
1999-02-23 11:04:28 +03:00
|
|
|
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD Clone(nsISupportsArray** aResult) MOZ_OVERRIDE;
|
2000-06-09 11:51:13 +04:00
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
NS_IMETHOD_(bool) InsertElementsAt(nsISupportsArray* aOther,
|
2015-01-02 09:09:28 +03:00
|
|
|
uint32_t aIndex) MOZ_OVERRIDE;
|
2001-08-07 10:23:40 +04:00
|
|
|
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD_(bool) RemoveElementsAt(uint32_t aIndex, uint32_t aCount) MOZ_OVERRIDE;
|
2001-08-07 10:23:40 +04:00
|
|
|
|
2015-01-02 09:09:28 +03:00
|
|
|
NS_IMETHOD_(bool) SizeTo(int32_t aSize) MOZ_OVERRIDE;
|
1999-02-23 11:04:28 +03:00
|
|
|
protected:
|
|
|
|
void DeleteArray(void);
|
|
|
|
|
2015-01-02 09:09:28 +03:00
|
|
|
void GrowArrayBy(int32_t aGrowBy);
|
2001-08-07 10:23:40 +04:00
|
|
|
|
1999-02-23 11:04:28 +03:00
|
|
|
nsISupports** mArray;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mArraySize;
|
|
|
|
uint32_t mCount;
|
1999-02-23 11:04:28 +03:00
|
|
|
nsISupports* mAutoArray[kAutoArraySize];
|
2001-08-07 10:23:40 +04:00
|
|
|
#if DEBUG_SUPPORTSARRAY
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mMaxCount;
|
|
|
|
uint32_t mMaxSize;
|
2001-08-07 10:23:40 +04:00
|
|
|
#endif
|
1999-02-23 11:04:28 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Copy constructors are not allowed
|
2014-07-28 21:19:06 +04:00
|
|
|
explicit nsSupportsArray(const nsISupportsArray& aOther);
|
1999-02-23 11:04:28 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsSupportsArray_h__
|