1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsSupportsArrayEnumerator.h"
7 #include "nsISupportsArray.h"
9 nsSupportsArrayEnumerator::nsSupportsArrayEnumerator(nsISupportsArray
* array
)
13 NS_ASSERTION(array
, "null array");
17 nsSupportsArrayEnumerator::~nsSupportsArrayEnumerator()
22 NS_IMPL_ISUPPORTS(nsSupportsArrayEnumerator
, nsIBidirectionalEnumerator
,
26 nsSupportsArrayEnumerator::First()
30 nsresult rv
= mArray
->Count(&cnt
);
34 int32_t end
= (int32_t)cnt
;
38 return NS_ERROR_FAILURE
;
43 nsSupportsArrayEnumerator::Next()
46 nsresult rv
= mArray
->Count(&cnt
);
50 int32_t end
= (int32_t)cnt
;
51 if (mCursor
< end
) { // don't count upward forever
57 return NS_ERROR_FAILURE
;
62 nsSupportsArrayEnumerator::CurrentItem(nsISupports
** aItem
)
64 NS_ASSERTION(aItem
, "null out parameter");
66 nsresult rv
= mArray
->Count(&cnt
);
70 if (mCursor
>= 0 && mCursor
< (int32_t)cnt
) {
71 return mArray
->GetElementAt(mCursor
, aItem
);
73 return NS_ERROR_FAILURE
;
77 nsSupportsArrayEnumerator::IsDone()
80 nsresult rv
= mArray
->Count(&cnt
);
84 // XXX This is completely incompatible with the meaning of nsresult.
85 // NS_ENUMERATOR_FALSE is defined to be 1. (bug 778111)
86 return (mCursor
>= 0 && mCursor
< (int32_t)cnt
)
87 ? (nsresult
)NS_ENUMERATOR_FALSE
: NS_OK
;
90 ////////////////////////////////////////////////////////////////////////////////
93 nsSupportsArrayEnumerator::Last()
96 nsresult rv
= mArray
->Count(&cnt
);
105 nsSupportsArrayEnumerator::Prev()
113 return NS_ERROR_FAILURE
;