Qore Programming Language Reference Manual  1.7.0
Qore::ObjectReverseIterator Class Reference

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

Inheritance diagram for Qore::ObjectReverseIterator:

Public Member Methods

 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 Methods 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 Methods inherited from Qore::HashIterator
 constructor (hash< auto > 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...
 
auto getKeyValue ()
 returns the current value of the current hash key being iterated or throws an INVALID-ITERATOR exception if the iterator is invalid More...
 
auto getValue ()
 returns the current key value or throws an INVALID-ITERATOR exception if the iterator is invalid More...
 
hash< auto > 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 ObjectReverseIterator::next() to iterate through the object in reverse order; do not use the iterator if ObjectReverseIterator::next() returns False. An object can be iterated in reverse order by calling ObjectReverseIterator::prev() instead of ObjectReverseIterator::next()

Example: ObjectReverseIterator basic usage
class Class1 {
public {
int attr1;
date attr2;
}
constructor() {
attr1 = 1;
attr2 = now();
}
}
Class1 o();
ObjectReverseIterator it(o);
while (it.next()) {
printf("iter: %n\n", it.getValue());
}
iter: 2013-04-17 16:31:03 Wed +02:00 (CEST)
iter: 1
date now()
Returns the current date and time with a resolution to the second.
string printf(string fmt,...)
Outputs the string passed to standard output, using the first argument as a format string; does not e...
Note
See also
ObjectIterator

Member Function Documentation

◆ constructor() [1/2]

Qore::ObjectReverseIterator::constructor ( )

Creates an empty iterator object.

Example:
*object obj = get_object_or_nothing();
ObjectReverseIterator i(obj);

◆ constructor() [2/2]

Qore::ObjectReverseIterator::constructor ( object  o)

Creates the object iterator object.

Parameters
othe object to iterate
Example:
ObjectReverseIterator i(obj);

◆ copy()

Qore::ObjectReverseIterator::copy ( )

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

Example:
ObjectReverseIterator ni = i.copy();

◆ first()

bool Qore::ObjectReverseIterator::first ( )
virtual

returns True if on the last element of the object

Returns
True if on the last element of the object
Code Flags:
CONSTANT
Example:
while (i.next()) {
if (i.first())
printf("START:\n");
}

Reimplemented from Qore::HashIterator.

◆ last()

bool Qore::ObjectReverseIterator::last ( )
virtual

returns True if on the first element of the object

Returns
True if on the first element of the object
Code Flags:
CONSTANT
Example:
while (i.next()) {
if (i.last())
printf("END.\n");
}

Reimplemented from Qore::HashIterator.

◆ next()

bool Qore::ObjectReverseIterator::next ( )
virtual

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.

This method will return True again after it returns False once if the object 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 object (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
ObjectReverseIterator::next() is the opposite of ObjectIterator::next(); it is functionally equivalent to ObjectIterator::prev(); ObjectReverseIterator::next() iterates through the object in reverse order
Exceptions
ITERATOR-THREAD-ERRORthis exception is thrown if this method is called from any thread other than the thread that created the object

Reimplemented from Qore::HashIterator.

◆ prev()

bool Qore::ObjectReverseIterator::prev ( )
virtual

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.

This method will return True again after it returns False once if object 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 object (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
ObjectReverseIterator::prev() is the opposite of ObjectIterator::prev(); it is functionally equivalent to ObjectIterator::next(); ObjectReverseIterator::prev() iterates through the object in forward order
Exceptions
ITERATOR-THREAD-ERRORthis exception is thrown if this method is called from any thread other than the thread that created the object

Reimplemented from Qore::HashIterator.