Visit Mozilla.org

nsIArray

From MDC

The nsIArray interface implements an array object.

Contents

nsIArray is defined in xpcom/ds/nsIArray.idl. It is scriptable and is currently under review.

Inherits from: nsISupports

[edit] Method overview

void queryElementAt(in unsigned long index, in nsIIDRef uuid, [iid_is(uuid), retval] out nsQIResult result);
unsigned long indexOf(in unsigned long startIndex, in nsISupports element);
nsISimpleEnumerator enumerate();

[edit] Methods

[edit] queryElementAt()

Retrieve a specific element of the array, and QueryInterface() it to the specified interface. null is a valid result for this method, but exceptions are thrown in other circumstances

 void queryElementAt(
   in unsigned long index,
   in nsIIDRef uuid,
   [iid_is(uuid), retval] out nsQIResult result
 );
[edit] Parameters
index
Position of element.
uuid
The IID of the requested interface.
result
The object, QI'd to the requested interface.
[edit] Exceptions thrown
NS_ERROR_NO_INTERFACE
When an entry exists at the specified index, but the requested interface is not available.
NS_ERROR_ILLEGAL_VALUE
When index > length-1.

[edit] indexOf()

Get the position of a specific element. Note that since null is a valid input, exceptions are used to indicate that an element is not found.

 unsigned long indexOf(
   in unsigned long startIndex,
   in nsISupports element
 );
[edit] Parameters
startIndex
The initial element to search in the array to start at the beginning, use 0 as the startIndex.
element
The element you are looking for.
[edit] Return value

A number >= startIndex which is the position of the element in the array.

element
The element you are looking for.
[edit] Exceptions thrown
NS_ERROR_NOT_FOUND
If the element was not in the array.

[edit] enumerate()

Enumerate the array.

 nsISimpleEnumerator enumerate(
 );
[edit] Parameters

None.

[edit] Return value

A new enumerator positioned at the start of the array.

[edit] Exceptions thrown
NS_ERROR_FAILURE
If the array is empty (to make it easy to detect errors).

[edit] See Also