Qore::ListReverseIterator Class Reference

This class an iterator class for lists. More...

Inheritance diagram for Qore::ListReverseIterator:
[legend]

## Public Member Functions

| constructor (softlist l)
| Creates the list iterator object. More...
| copy ()
| Creates a copy of the ListReverseIterator object, iterating the same object as the original and in the same position. More...
bool | first ()
| returns True if on the first element iterated with this iterator (ie the last element in the list) More...
bool | last ()
| returns True if on the last element iterated with this iterator (ie the first element in the list) More...
bool | next ()
| 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. More...
bool | prev ()
| 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. More...
Public Member Functions inherited from Qore::ListIterator
| constructor (softlist l)
| Creates the list iterator object. More...
| copy ()
| Creates a copy of the ListIterator object, iterating the same object as the original and in the same position. More...
bool | empty ()
| returns True if the list is empty; False if not More...
auto | getValue ()
| returns the current value or throws an `INVALID-ITERATOR` exception if the iterator is invalid More...
int | index ()
| returns the current iterator position in the list or -1 if not pointing at a valid element More...
int | max ()
| returns the number of elements in the list More...
| reset ()
| Reset the iterator instance to its initial state. More...
bool | set (int pos)
| sets the new position in the list; if the position is invalid then the method returns False, meaning the iterator is not valid, otherwise it returns True More...
bool | valid ()
| returns True if the iterator is currently pointing at a valid element, False if not More...

## Detailed Description

This class an iterator class for lists.

Call ListReverseIterator::next() to iterate through the list in reverse order; do not use the iterator if ListReverseIterator::next() returns False. A list can be iterated in reverse order by calling ListReverseIterator::prev() instead of ListReverseIterator::next()

Example: ListIterator basic usage
  list data = (1, "foo", 2);
  ListReverseIterator it(data);
  while (it.next()) {
  printf("iter: %n\n", it.getValue());
  }
  iter: 2
  iter: "foo"
  iter: 1

Note
  - In general, the ListReverseIterator 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.
  - ListReverseIterator is functionally equivalent to ListIterator, but the effect of ListReverseIterator::next() and ListReverseIterator::prev() are the opposite of ListIterator::next() and ListIterator::prev(); that is ListReverseIterator::next() will iterate through the list in reverse order, while ListReverseIterator::prev() iterates in forward order. Additionally the meanings of the return values for ListReverseIterator::first() and ListReverseIterator::last() are swapped in respect to ListIterator::first() and ListIterator::last().

See also
  ListIterator

## Member Function Documentation

## constructor()

Qore::ListReverseIterator::constructor | ( | softlist | l | ) |

Creates the list iterator object.

Parameters

  l | the list to iterate

Example:
  ListReverseIterator li(l);

Note
  the constructor's argument is softlist so that it can also accept NOTHING

## copy()

Qore::ListReverseIterator::copy | ( |  | ) |

Creates a copy of the ListReverseIterator object, iterating the same object as the original and in the same position.

Example:
  ListReverseIterator ni = i.copy();

## first()

bool Qore::ListReverseIterator::first | ( |  | ) |

virtual

returns True if on the first element iterated with this iterator (ie the last element in the list)

Returns
  True if on the first element iterated with this iterator (ie the last element in the list)

Code Flags:
  CONSTANT

Example:
  while (i.next()) {
  if (i.first())
  printf("START:\n");
  }

Reimplemented from Qore::ListIterator.

## last()

bool Qore::ListReverseIterator::last | ( |  | ) |

virtual

returns True if on the last element iterated with this iterator (ie the first element in the list)

Returns
  True if on the last element iterated with this iterator (ie the first element in the list)

Code Flags:
  CONSTANT

Example:
  while (i.next()) {
  if (i.last())
  printf("END.\n");
  }

Reimplemented from Qore::ListIterator.

## next()

bool Qore::ListReverseIterator::next | ( |  | ) |

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());
  }

Note
  ListReverseIterator::next() is the opposite of ListIterator::next(); it is functionally equivalent to ListIterator::prev(); ListReverseIterator::next() iterates through the list in reverse order

Exceptions

  ITERATOR-THREAD-ERROR | this exception is thrown if this method is called from any thread other than the thread that created the object

Reimplemented from Qore::ListIterator.

## prev()

bool Qore::ListReverseIterator::prev | ( |  | ) |

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());
  }

Note
  ListReverseIterator::prev() is the opposite of ListIterator::prev(); it is functionally equivalent to ListIterator::next(); ListReverseIterator::prev() iterates through the list in forward order

Exceptions

  ITERATOR-THREAD-ERROR | this exception is thrown if this method is called from any thread other than the thread that created the object

Reimplemented from Qore::ListIterator.