Add AppendObjects/InsertObjectsAt to nsCOMArray. Bug 175137,

r=timeless, sr=alecf, a=dbaron
This commit is contained in:
bzbarsky%mit.edu 2002-10-25 01:40:50 +00:00
parent c66a28d655
commit e1ecd5f25d
2 changed files with 31 additions and 3 deletions

View File

@ -66,6 +66,19 @@ nsCOMArray_base::InsertObjectAt(nsISupports* aObject, PRInt32 aIndex) {
return result;
}
PRBool
nsCOMArray_base::InsertObjectsAt(const nsCOMArray_base& aObjects, PRInt32 aIndex) {
PRBool result = mArray.InsertElementsAt(aObjects.mArray, aIndex);
if (result) {
// need to addref all these
PRInt32 count = aObjects.Count();
for (PRInt32 i = 0; i < count; ++i) {
NS_IF_ADDREF(aObjects.ObjectAt(i));
}
}
return result;
}
PRBool
nsCOMArray_base::ReplaceObjectAt(nsISupports* aObject, PRInt32 aIndex)
{

View File

@ -71,9 +71,13 @@ protected:
// all over the place
void Clear();
PRBool InsertObjectAt(nsISupports* aObject, PRInt32 aIndex);
PRBool InsertObjectsAt(const nsCOMArray_base& aObjects, PRInt32 aIndex);
PRBool ReplaceObjectAt(nsISupports* aObject, PRInt32 aIndex);
PRBool AppendObject(nsISupports *aObject) {
return InsertObjectAt(aObject, Count());
return InsertObjectAt(aObject, Count());
}
PRBool AppendObjects(const nsCOMArray_base& aObjects) {
return InsertObjectsAt(aObjects, Count());
}
PRBool RemoveObject(nsISupports *aObject);
PRBool RemoveObjectAt(PRInt32 aIndex);
@ -148,12 +152,18 @@ class nsCOMArray : public nsCOMArray_base
return nsCOMArray_base::IndexOf(aObject);
}
// inserts the object at aIndex, and move all objects after aIndex
// to the right
// inserts aObject at aIndex, shifting the objects at aIndex and
// later to make space
PRBool InsertObjectAt(T* aObject, PRInt32 aIndex) {
return nsCOMArray_base::InsertObjectAt(aObject, aIndex);
}
// inserts the objects from aObject at aIndex, shifting the
// objects at aIndex and later to make space
PRBool InsertObjectsAt(const nsCOMArray<T>& aObjects, PRInt32 aIndex) {
return nsCOMArray_base::InsertObjectsAt(aObjects, aIndex);
}
// replaces an existing element. Warning: if the array grows,
// the newly created entries will all be null
PRBool ReplaceObjectAt(T* aObject, PRInt32 aIndex) {
@ -195,6 +205,11 @@ class nsCOMArray : public nsCOMArray_base
return nsCOMArray_base::AppendObject(aObject);
}
// append objects, growing the array as necessary
PRBool AppendObjects(const nsCOMArray<T>& aObjects) {
return nsCOMArray_base::AppendObjects(aObjects);
}
// remove the first instance of the given object and shrink the
// array as necessary
// Warning: if you pass null here, it will remove the first null element