Qore Programming Language Reference Manual 0.8.8

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Functions Variables Groups Pages
Public Member Functions | List of all members
Qore::ObjectKeyReverseIterator Class Reference

This class an iterator class for objects. More...

Inheritance diagram for Qore::ObjectKeyReverseIterator:
[legend]

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

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

Example: ObjectKeyReverseIterator basic usage
  class Class1 {
  public {
  int $.attr1;
  date $.attr2;
  }
  constructor() {
  $.attr1 = 1;
  $.attr2 = now();
  }
  }
  my Class1 $o();
  my ObjectKeyReverseIterator $it($o);
  while ($it.next()) {
  printf("iter: %n\n", $it.getValue());
  }
  iter: "attr2"
  iter: "attr1"

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

See Also
  ObjectKeyIterator

## Member Function Documentation

Qore::ObjectKeyReverseIterator::constructor | ( | object | o | ) |

Creates the object iterator object.

Parameters

  o | the object to iterate

Example:
  my ObjectKeyReverseIterator $i($obj);

Qore::ObjectKeyReverseIterator::constructor | ( |  | ) |

Creates an empty iterator object.

Example:
  my *object $obj = get_object();
  my ObjectKeyReverseIterator $i($obj);

Qore::ObjectKeyReverseIterator::copy | ( |  | ) |

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

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

string Qore::ObjectKeyReverseIterator::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 ObjectKeyReverseIterator $i($obj);
  while ($i.next())
  printf("key: %s\n", $i.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.