michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsIArray.idl" michael@0: michael@0: /** michael@0: * nsIMutableArray michael@0: * A separate set of methods that will act on the array. Consumers of michael@0: * nsIArray should not QueryInterface to nsIMutableArray unless they michael@0: * own the array. michael@0: * michael@0: * As above, it is legal to add null elements to the array. Note also michael@0: * that null elements can be created as a side effect of michael@0: * insertElementAt(). Conversely, if insertElementAt() is never used, michael@0: * and null elements are never explicitly added to the array, then it michael@0: * is guaranteed that queryElementAt() will never return a null value. michael@0: * michael@0: * Any of these methods may throw NS_ERROR_OUT_OF_MEMORY when the michael@0: * array must grow to complete the call, but the allocation fails. michael@0: */ michael@0: [scriptable, uuid(af059da0-c85b-40ec-af07-ae4bfdc192cc)] michael@0: interface nsIMutableArray : nsIArray michael@0: { michael@0: /** michael@0: * appendElement() michael@0: * michael@0: * Append an element at the end of the array. michael@0: * michael@0: * @param element The element to append. michael@0: * @param weak Whether or not to store the element using a weak michael@0: * reference. michael@0: * @throws NS_ERROR_FAILURE when a weak reference is requested, michael@0: * but the element does not support michael@0: * nsIWeakReference. michael@0: */ michael@0: void appendElement(in nsISupports element, in boolean weak); michael@0: michael@0: /** michael@0: * removeElementAt() michael@0: * michael@0: * Remove an element at a specific position, moving all elements michael@0: * stored at a higher position down one. michael@0: * To remove a specific element, use indexOf() to find the index michael@0: * first, then call removeElementAt(). michael@0: * michael@0: * @param index the position of the item michael@0: * michael@0: */ michael@0: void removeElementAt(in unsigned long index); michael@0: michael@0: /** michael@0: * insertElementAt() michael@0: * michael@0: * Insert an element at the given position, moving the element michael@0: * currently located in that position, and all elements in higher michael@0: * position, up by one. michael@0: * michael@0: * @param element The element to insert michael@0: * @param index The position in the array: michael@0: * If the position is lower than the current length michael@0: * of the array, the elements at that position and michael@0: * onwards are bumped one position up. michael@0: * If the position is equal to the current length michael@0: * of the array, the new element is appended. michael@0: * An index lower than 0 or higher than the current michael@0: * length of the array is invalid and will be ignored. michael@0: * michael@0: * @throws NS_ERROR_FAILURE when a weak reference is requested, michael@0: * but the element does not support michael@0: * nsIWeakReference. michael@0: */ michael@0: void insertElementAt(in nsISupports element, in unsigned long index, michael@0: in boolean weak); michael@0: michael@0: /** michael@0: * replaceElementAt() michael@0: * michael@0: * Replace the element at the given position. michael@0: * michael@0: * @param element The new element to insert michael@0: * @param index The position in the array michael@0: * If the position is lower than the current length michael@0: * of the array, an existing element will be replaced. michael@0: * If the position is equal to the current length michael@0: * of the array, the new element is appended. michael@0: * If the position is higher than the current length michael@0: * of the array, empty elements are appended followed michael@0: * by the new element at the specified position. michael@0: * An index lower than 0 is invalid and will be ignored. michael@0: * michael@0: * @param weak Whether or not to store the new element using a weak michael@0: * reference. michael@0: * michael@0: * @throws NS_ERROR_FAILURE when a weak reference is requested, michael@0: * but the element does not support michael@0: * nsIWeakReference. michael@0: */ michael@0: void replaceElementAt(in nsISupports element, in unsigned long index, michael@0: in boolean weak); michael@0: michael@0: michael@0: /** michael@0: * clear() michael@0: * michael@0: * clear the entire array, releasing all stored objects michael@0: */ michael@0: void clear(); michael@0: };