not part of build, more for bug 162115:

- fix some spelling, add documentation
- add NS_NewArray(), including one that takes an existing nsCOMArray<T>
- implement copy constructor for nsCOMArray_base, so that NS_NewArray can work
not part of build
This commit is contained in:
alecf@netscape.com
2002-09-30 23:02:31 +00:00
parent 7a0f25c401
commit 4939acab42
5 changed files with 125 additions and 17 deletions

View File

@@ -38,8 +38,27 @@
#include "nsCOMArray.h"
static PRBool AddRefObjects(void* aElement, void*);
static PRBool ReleaseObjects(void* aElement, void*);
// implementations of non-trivial methods in nsCOMArray_base
// copy constructor - we can't just memcpy here, because
// we have to make sure we own our own array buffer, and that each
// object gets another AddRef()
nsCOMArray_base::nsCOMArray_base(const nsCOMArray_base& aOther)
{
PRInt32 count = aOther.Count();
// make sure we do only one allocation
mArray.SizeTo(count);
PRInt32 i;
for (i=0; i<count; i++) {
ReplaceObjectAt(aOther[i], i);
}
}
PRBool
nsCOMArray_base::InsertObjectAt(nsISupports* aObject, PRInt32 aIndex) {
PRBool result = mArray.InsertElementAt(aObject, aIndex);
@@ -98,8 +117,19 @@ nsCOMArray_base::RemoveObjectAt(PRInt32 aIndex)
return PR_FALSE;
}
static PRBool
ClearObjectsCallback(void* aElement, void*)
// useful for copy constructors
PRBool
AddRefObjects(void* aElement, void*)
{
nsISupports* element = NS_STATIC_CAST(nsISupports*,aElement);
NS_IF_ADDREF(element);
return PR_TRUE;
}
// useful for destructors
PRBool
ReleaseObjects(void* aElement, void*)
{
nsISupports* element = NS_STATIC_CAST(nsISupports*, aElement);
NS_IF_RELEASE(element);
@@ -109,6 +139,7 @@ ClearObjectsCallback(void* aElement, void*)
void
nsCOMArray_base::Clear()
{
mArray.EnumerateForwards(ClearObjectsCallback, nsnull);
mArray.EnumerateForwards(ReleaseObjects, nsnull);
mArray.Clear();
}