bug #50721: sr=brendan, r=dbaron. Add |do_QueryElementAt|.

This commit is contained in:
scc%mozilla.org 2001-07-04 05:42:46 +00:00
Родитель 221a000a29
Коммит 88720ed1d1
2 изменённых файлов: 51 добавлений и 2 удалений

Просмотреть файл

@ -17,7 +17,8 @@
* Copyright (C) 1998 Netscape Communications Corporation. All * Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved. * Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Scott Collins <scc@mozilla.org>: |do_QueryElementAt|
*/ */
#include "nsISupports.idl" #include "nsISupports.idl"
@ -40,3 +41,37 @@ interface nsICollection : nsISupports
void Clear(); void Clear();
}; };
%{C++
#ifndef nsCOMPtr_h__
#include "nsCOMPtr.h"
#endif
class NS_EXPORT nsQueryElementAt : public nsCOMPtr_helper
{
public:
nsQueryElementAt( nsICollection* aCollection, PRUint32 aIndex, nsresult* aErrorPtr )
: mCollection(aCollection),
mIndex(aIndex),
mErrorPtr(aErrorPtr)
{
// nothing else to do here
}
virtual nsresult operator()( const nsIID& aIID, void** ) const;
private:
nsICollection* mCollection;
PRUint32 mIndex;
nsresult* mErrorPtr;
};
inline
const nsQueryElementAt
do_QueryElementAt( nsICollection* aCollection, PRUint32 aIndex, nsresult* aErrorPtr = 0 )
{
return nsQueryElementAt(aCollection, aIndex, aErrorPtr);
}
%}

Просмотреть файл

@ -17,7 +17,8 @@
* Copyright (C) 1998 Netscape Communications Corporation. All * Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved. * Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Scott Collins <scc@mozilla.org>: |do_QueryElementAt|
* Pierre Phaneuf <pp@ludusdesign.com> * Pierre Phaneuf <pp@ludusdesign.com>
*/ */
@ -25,6 +26,19 @@
#include "nsSupportsArrayEnumerator.h" #include "nsSupportsArrayEnumerator.h"
#include <string.h> #include <string.h>
nsresult
nsQueryElementAt::operator()( const nsIID& aIID, void** aResult ) const
{
nsresult status = mCollection
? mCollection->QueryElementAt(mIndex, aIID, aResult)
: NS_ERROR_NULL_POINTER;
if ( mErrorPtr )
*mErrorPtr = status;
return status;
}
static const PRUint32 kGrowArrayBy = 8; static const PRUint32 kGrowArrayBy = 8;
nsSupportsArray::nsSupportsArray() nsSupportsArray::nsSupportsArray()