This class an iterator class for lists.
Call ListIterator::next() to iterate through the list; do not use the iterator if ListIterator::next() returns False. A list can be iterated in reverse order by calling ListIterator::prev() instead of ListIterator::next()
- Example: ListIterator basic usage
list data = (1, "foo", 2);
ListIterator it(data);
while (it.next()) {
printf(
"iter: %n\n", it.getValue());
}
iter: 1
iter: "foo"
iter: 2
string printf(string fmt,...)
Outputs the string passed to standard output, using the first argument as a format string; does not e...
- Note
- In general, the ListIterator class is not designed to be accessed from multiple threads; it was created without locking for fast and efficient use when used from a single thread. For methods that would be unsafe to use in another thread, any use of such methods in threads other than the thread where the constructor was called will cause an
ITERATOR-THREAD-ERROR
to be thrown.
- See also
- ListReverseIterator
bool Qore::ListIterator::next |
( |
| ) |
|
|
virtual |
Moves the current position to the next element in the list; returns False if there are no more elements; if the iterator is not pointing at a valid element before this call, the iterator will be positioned on the first element in the list if the list is not empty.
This method will return True again after it returns False once if list is not empty, otherwise it will always return False. The iterator object should not be used after this method returns False
- Returns
- False if there are no more elements in the list (in which case the iterator object is invalid and should not be used); True if successful (meaning that the iterator object is valid)
- Example:
while (i.next()) {
printf(
" + %y\n", i.getValue());
}
- Exceptions
-
ITERATOR-THREAD-ERROR | this exception is thrown if this method is called from any thread other than the thread that created the object |
Implements Qore::AbstractIterator.
Reimplemented in Qore::ListReverseIterator.
bool Qore::ListIterator::prev |
( |
| ) |
|
|
virtual |
Moves the current position to the previous element in the list; returns False if there are no more elements; if the iterator is not pointing at a valid element before this call, the iterator will be positioned on the last element in the list if the list is not empty.
This method will return True again after it returns False once if the list is not empty, otherwise it will always return False. The iterator object should not be used after this method returns False
- Returns
- False if there are no more elements in the list (in which case the iterator object is invalid and should not be used); True if successful (meaning that the iterator object is valid)
- Example:
while (i.prev()) {
printf(
" + %y\n", i.getValue());
}
- Exceptions
-
ITERATOR-THREAD-ERROR | this exception is thrown if this method is called from any thread other than the thread that created the object |
Implements Qore::AbstractBidirectionalIterator.
Reimplemented in Qore::ListReverseIterator.