Qore Programming Language Reference Manual  1.7.0
Qore::AbstractIterator Class Referenceabstract

This class defines an abstract interface for iterators. More...

Inheritance diagram for Qore::AbstractIterator:

Public Member Methods

abstract auto getValue ()
 returns the current value More...
 
abstract bool next ()
 Moves the current position to the next element; returns False if there are no more elements. More...
 
abstract bool valid ()
 returns True if the iterator is currently pointing at a valid element, False if not More...
 

Detailed Description

This class defines an abstract interface for iterators.

Classes inheriting this class can be used to iterate abstract or complex objects with while Statements (using AbstractIterator::next()) or directly in the following language constructs:

Member Function Documentation

◆ getValue()

abstract auto Qore::AbstractIterator::getValue ( )
pure virtual

returns the current value

Returns
the current value
Example:
while (i.next()) {
printf("+ %y\n", i.getValue());
}
string printf(string fmt,...)
Outputs the string passed to standard output, using the first argument as a format string; does not e...
Exceptions
INVALID-ITERATORthe iterator is not pointing at a valid element
See also
AbstractIterator::valid()

Implemented in Qore::SQL::SQLStatement, Qore::SingleValueIterator, Qore::RangeIterator, Qore::ObjectPairReverseIterator, Qore::ObjectPairIterator, Qore::ObjectKeyReverseIterator, Qore::ObjectKeyIterator, Qore::ListIterator, Qore::ListHashIterator, Qore::InputStreamLineIterator, Qore::HashPairReverseIterator, Qore::HashPairIterator, Qore::HashListIterator, Qore::HashKeyReverseIterator, Qore::HashKeyIterator, Qore::HashIterator, Qore::FileLineIterator, Qore::DataLineIterator, Qore::SQL::AbstractSQLStatement, and Qore::AbstractLineIterator.

◆ next()

abstract bool Qore::AbstractIterator::next ( )
pure virtual

Moves the current position to the next element; returns False if there are no more elements.

This method will return True again after it returns False once if the object being iterated 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 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());
}

Implemented in Qore::SQL::SQLStatement, Qore::SingleValueIterator, Qore::RangeIterator, Qore::ObjectReverseIterator, Qore::ListReverseIterator, Qore::ListIterator, Qore::ListHashReverseIterator, Qore::ListHashIterator, Qore::InputStreamLineIterator, Qore::HashReverseIterator, Qore::HashListReverseIterator, Qore::HashListIterator, Qore::HashIterator, Qore::FileLineIterator, Qore::DataLineIterator, Qore::SQL::AbstractSQLStatement, and Qore::AbstractLineIterator.

◆ valid()

abstract bool Qore::AbstractIterator::valid ( )
pure virtual

returns True if the iterator is currently pointing at a valid element, False if not

Returns
True if the iterator is currently pointing at a valid element, False if not
Example:
if (i.valid())
printf("current value: %y\n", i.getValue());

Implemented in Qore::SQL::SQLStatement, Qore::SingleValueIterator, Qore::RangeIterator, Qore::ListIterator, Qore::ListHashIterator, Qore::InputStreamLineIterator, Qore::HashListIterator, Qore::HashIterator, Qore::FileLineIterator, Qore::DataLineIterator, Qore::SQL::AbstractSQLStatement, and Qore::AbstractLineIterator.