1999-02-23 11:04:28 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:21:17 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-02-23 11:04:28 +03:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-02-23 11:04:28 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:21:17 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:21:17 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:21:17 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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"
|
|
|
|
|
2001-08-07 10:23:40 +04:00
|
|
|
static const PRUint32 kAutoArraySize = 8;
|
1999-02-23 11:04:28 +03:00
|
|
|
|
2006-04-19 20:29:31 +04:00
|
|
|
// Set IMETHOD_VISIBILITY to empty so that the class-level NS_COM declaration
|
|
|
|
// controls member method visibility.
|
2004-02-03 11:32:33 +03:00
|
|
|
#undef IMETHOD_VISIBILITY
|
2006-04-19 20:29:31 +04:00
|
|
|
#define IMETHOD_VISIBILITY
|
2004-02-03 11:32:33 +03:00
|
|
|
|
1999-11-10 04:49:30 +03:00
|
|
|
class NS_COM nsSupportsArray : public nsISupportsArray {
|
1999-02-23 11:04:28 +03:00
|
|
|
public:
|
|
|
|
nsSupportsArray(void);
|
2004-01-22 04:01:19 +03:00
|
|
|
~nsSupportsArray(void); // nonvirtual since we're not subclassed
|
1999-02-23 11:04:28 +03:00
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
static nsresult
|
1999-05-26 05:38:36 +04:00
|
|
|
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
|
|
|
|
1999-02-23 11:04:28 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
NS_DECL_NSISERIALIZABLE
|
|
|
|
|
1999-02-23 11:04:28 +03:00
|
|
|
// nsICollection methods:
|
1999-05-13 08:56:04 +04:00
|
|
|
NS_IMETHOD Count(PRUint32 *result) { *result = mCount; return NS_OK; }
|
1999-06-02 06:06:32 +04:00
|
|
|
NS_IMETHOD GetElementAt(PRUint32 aIndex, nsISupports* *result) {
|
|
|
|
*result = ElementAt(aIndex);
|
1999-05-13 08:56:04 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-17 01:29:22 +04:00
|
|
|
NS_IMETHOD QueryElementAt(PRUint32 aIndex, const nsIID & aIID, void * *aResult) {
|
|
|
|
if (aIndex < mCount) {
|
|
|
|
nsISupports* element = mArray[aIndex];
|
|
|
|
if (nsnull != element)
|
|
|
|
return element->QueryInterface(aIID, aResult);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-06-02 06:06:32 +04:00
|
|
|
NS_IMETHOD SetElementAt(PRUint32 aIndex, nsISupports* value) {
|
2001-12-21 04:10:07 +03:00
|
|
|
return ReplaceElementAt(value, aIndex) ? NS_OK : NS_ERROR_FAILURE;
|
1999-05-13 08:56:04 +04:00
|
|
|
}
|
2002-05-30 11:13:40 +04:00
|
|
|
NS_IMETHOD AppendElement(nsISupports *aElement) {
|
|
|
|
return 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
|
|
|
|
NS_IMETHOD RemoveElement(nsISupports *aElement) {
|
|
|
|
return RemoveElement(aElement, 0)/* ? NS_OK : NS_ERROR_FAILURE*/;
|
1999-02-23 11:04:28 +03:00
|
|
|
}
|
2001-08-07 10:23:40 +04:00
|
|
|
NS_IMETHOD_(PRBool) MoveElement(PRInt32 aFrom, PRInt32 aTo);
|
1999-02-23 11:04:28 +03:00
|
|
|
NS_IMETHOD Enumerate(nsIEnumerator* *result);
|
|
|
|
NS_IMETHOD Clear(void);
|
|
|
|
|
|
|
|
// nsISupportsArray methods:
|
1999-06-02 06:06:32 +04:00
|
|
|
NS_IMETHOD_(PRBool) Equals(const nsISupportsArray* aOther);
|
1999-02-23 11:04:28 +03:00
|
|
|
|
1999-06-02 06:06:32 +04:00
|
|
|
NS_IMETHOD_(nsISupports*) ElementAt(PRUint32 aIndex);
|
1999-02-23 11:04:28 +03:00
|
|
|
|
1999-06-02 06:06:32 +04:00
|
|
|
NS_IMETHOD_(PRInt32) IndexOf(const nsISupports* aPossibleElement);
|
|
|
|
NS_IMETHOD_(PRInt32) IndexOfStartingAt(const nsISupports* aPossibleElement,
|
|
|
|
PRUint32 aStartIndex = 0);
|
|
|
|
NS_IMETHOD_(PRInt32) LastIndexOf(const nsISupports* aPossibleElement);
|
1999-02-23 11:04:28 +03:00
|
|
|
|
1999-06-02 06:06:32 +04:00
|
|
|
NS_IMETHOD GetIndexOf(nsISupports *aPossibleElement, PRInt32 *_retval) {
|
|
|
|
*_retval = IndexOf(aPossibleElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetIndexOfStartingAt(nsISupports *aPossibleElement,
|
|
|
|
PRUint32 aStartIndex, PRInt32 *_retval) {
|
|
|
|
*_retval = IndexOfStartingAt(aPossibleElement, aStartIndex);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetLastIndexOf(nsISupports *aPossibleElement, PRInt32 *_retval) {
|
|
|
|
*_retval = LastIndexOf(aPossibleElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-23 11:04:28 +03:00
|
|
|
NS_IMETHOD_(PRBool) InsertElementAt(nsISupports* aElement, PRUint32 aIndex);
|
|
|
|
|
|
|
|
NS_IMETHOD_(PRBool) ReplaceElementAt(nsISupports* aElement, PRUint32 aIndex);
|
|
|
|
|
2001-08-07 10:23:40 +04:00
|
|
|
NS_IMETHOD_(PRBool) RemoveElementAt(PRUint32 aIndex) {
|
|
|
|
return RemoveElementsAt(aIndex,1);
|
|
|
|
}
|
1999-02-23 11:04:28 +03:00
|
|
|
NS_IMETHOD_(PRBool) RemoveElement(const nsISupports* aElement, PRUint32 aStartIndex = 0);
|
|
|
|
NS_IMETHOD_(PRBool) RemoveLastElement(const nsISupports* aElement);
|
|
|
|
|
1999-06-02 06:06:32 +04:00
|
|
|
NS_IMETHOD DeleteLastElement(nsISupports *aElement) {
|
|
|
|
return (RemoveLastElement(aElement) ? NS_OK : NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD DeleteElementAt(PRUint32 aIndex) {
|
|
|
|
return (RemoveElementAt(aIndex) ? NS_OK : NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
|
2001-08-07 10:23:40 +04:00
|
|
|
NS_IMETHOD_(PRBool) AppendElements(nsISupportsArray* aElements) {
|
|
|
|
return InsertElementsAt(aElements,mCount);
|
|
|
|
}
|
1999-02-23 11:04:28 +03:00
|
|
|
|
1999-06-02 06:06:32 +04:00
|
|
|
NS_IMETHOD Compact(void);
|
1999-02-23 11:04:28 +03:00
|
|
|
|
1999-06-02 06:06:32 +04:00
|
|
|
NS_IMETHOD_(PRBool) EnumerateForwards(nsISupportsArrayEnumFunc aFunc, void* aData);
|
|
|
|
NS_IMETHOD_(PRBool) EnumerateBackwards(nsISupportsArrayEnumFunc aFunc, void* aData);
|
1999-02-23 11:04:28 +03:00
|
|
|
|
2000-06-09 11:51:13 +04:00
|
|
|
NS_IMETHOD Clone(nsISupportsArray **_retval);
|
|
|
|
|
2001-08-07 10:23:40 +04:00
|
|
|
NS_IMETHOD_(PRBool) InsertElementsAt(nsISupportsArray *aOther, PRUint32 aIndex);
|
|
|
|
|
|
|
|
NS_IMETHOD_(PRBool) RemoveElementsAt(PRUint32 aIndex, PRUint32 aCount);
|
|
|
|
|
|
|
|
NS_IMETHOD_(PRBool) SizeTo(PRInt32 aSize);
|
1999-02-23 11:04:28 +03:00
|
|
|
protected:
|
|
|
|
void DeleteArray(void);
|
|
|
|
|
2001-08-07 10:23:40 +04:00
|
|
|
NS_IMETHOD_(PRBool) GrowArrayBy(PRInt32 aGrowBy);
|
|
|
|
|
1999-02-23 11:04:28 +03:00
|
|
|
nsISupports** mArray;
|
|
|
|
PRUint32 mArraySize;
|
|
|
|
PRUint32 mCount;
|
|
|
|
nsISupports* mAutoArray[kAutoArraySize];
|
2001-08-07 10:23:40 +04:00
|
|
|
#if DEBUG_SUPPORTSARRAY
|
|
|
|
PRUint32 mMaxCount;
|
|
|
|
PRUint32 mMaxSize;
|
|
|
|
#endif
|
1999-02-23 11:04:28 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Copy constructors are not allowed
|
|
|
|
nsSupportsArray(const nsISupportsArray& other);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsSupportsArray_h__
|