All Classes Namespaces Functions Variables Groups Pages
Qore::HashKeyReverseIterator Class Reference

This class an iterator class for hashes. More...

Inheritance diagram for Qore::HashKeyReverseIterator:
[legend]

## Public Member Functions

| constructor (hash h)
| Creates the hash iterator object.
| constructor ()
| Creates an empty iterator object.
| copy ()
| Creates a copy of the HashKeyReverseIterator object, iterating the same object as the original and in the same position.
string | getValue ()
| returns the current key value or throws an `INVALID-ITERATOR` exception if the iterator is invalid
Public Member Functions inherited from Qore::HashReverseIterator
| constructor (hash h)
| Creates the hash iterator object.
| constructor ()
| Creates an empty iterator object.
| copy ()
| Creates a copy of the HashReverseIterator object, iterating the same object as the original and in the same position.
bool | first ()
| returns True if on the last element of the hash
bool | last ()
| returns True if on the first element of the hash
bool | next ()
| Moves the current position to the previous element in the hash; 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 hash if the hash is not empty.
bool | prev ()
| Moves the current position to the next element in the hash; 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 hash if the hash is not empty.
Public Member Functions inherited from Qore::HashIterator
| constructor (hash h)
| Creates the hash iterator object.
| constructor ()
| Creates an empty hash iterator object.
| copy ()
| Creates a copy of the HashIterator object, iterating the same object as the original and in the same position.
bool | empty ()
| returns True if the hash is empty; False if not
string | getKey ()
| returns the current key value or throws an `INVALID-ITERATOR` exception if the iterator is invalid
any | getKeyValue ()
| returns the current value of the current has key being iterated or throws an `INVALID-ITERATOR` exception if the iterator is invalid
hash | getValuePair ()
| returns a hash with the current key and value (a hash with 2 keys: `"key"` and `"value"`) or throws an `INVALID-ITERATOR` exception if the iterator is invalid
| reset ()
| Reset the iterator instance to its initial state.
bool | valid ()
| returns True if the iterator is currently pointing at a valid element, False if not

## Detailed Description

This class an iterator class for hashes.

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

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

See Also
  HashKeyIterator

## Member Function Documentation

Qore::HashKeyReverseIterator::constructor | ( | hash | h | ) |

Creates the hash iterator object.

Parameters

  h | the hash to iterate

Example:
  my HashKeyReverseIterator $hi($h);

Qore::HashKeyReverseIterator::constructor | ( |  | ) |

Creates an empty iterator object.

Example:
  my *hash $h = get_hash_or_nothing();
  my HashKeyReverseIterator $hi($h);

Qore::HashKeyReverseIterator::copy | ( |  | ) |

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

Example:
  my HashKeyReverseIterator $ni = $i.copy();

string Qore::HashKeyReverseIterator::getValue | ( |  | ) |

virtual

returns the current key value or throws an `INVALID-ITERATOR` exception if the iterator is invalid

Returns
  the current key value or throws an `INVALID-ITERATOR` exception if the iterator is invalid

Code Flags:
  RET_VALUE_ONLY

Example:
  my HashKeyReverseIterator $hi($hash);
  while ($hi.next())
  printf("key: %s\n", $hi.getValue());

Exceptions

  INVALID-ITERATOR | the iterator is not pointing at a valid element
  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::HashIterator.