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::SingleValueIterator Class Reference

This class defines a simple iterator to be used to iterate single values (or complex objects where no iterator has been implemented yet) More...

Inheritance diagram for Qore::SingleValueIterator:
[legend]

## Public Member Functions
| constructor (any v)
| creates the single value iterator with the value passed as an argument More...
| copy ()
| Creates a copy of the SingleValueIterator object, iterating the same object as the original and in the same position. More...
any | getValue ()
| returns the current value or throws an `INVALID-ITERATOR` exception if the iterator is invalid More...
bool | next ()
| This method returns True and False alternately unless it has no value to iterate, in which case it returns only False. 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 defines a simple iterator to be used to iterate single values (or complex objects where no iterator has been implemented yet)

Since
  Qore 0.8.6

Example: SingleValueIterator basic usage
  my any $val = 1;
  my SingleValueIterator $it($val);
  while ($it.next()) {
  printf("iter: %n\n", $it.getValue());
  }
  iter: 1

Remember that input value is taken as a single token so result of the code above for a list as an input argument will be like this:

my any $val = (1, 2, 3);
iter: list: (1, 2, 3)

## Member Function Documentation

Qore::SingleValueIterator::constructor | ( | any | v | ) |

creates the single value iterator with the value passed as an argument

Parameters

  v | the value to iterate

Example:
  my SingleValueIterator i($v);

Qore::SingleValueIterator::copy | ( |  | ) |

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

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

any Qore::SingleValueIterator::getValue | ( |  | ) |
| virtual

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

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

Code Flags:
  RET_VALUE_ONLY

Example:
  while ($i.next()) {
  printf("+ %y\n", $i.getValue());
  }

Exceptions

  INVALID-ITERATOR | the iterator is not pointing at a valid element

Implements Qore::AbstractIterator.

bool Qore::SingleValueIterator::next | ( |  | ) |
| virtual

This method returns True and False alternately unless it has no value to iterate, in which case it returns only False.

The iterator object should not be used after this method returns False

Returns
  True and False alternately unless it has no value to iterate, in which case it returns only False

Example:
  while ($i.next()) {
  printf("value: %y\n", $i.getValue());
  }

Exceptions

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

Implements Qore::AbstractIterator.

Qore::SingleValueIterator::reset | ( |  | ) |

Reset the iterator instance to its initial state.

Reset the iterator instance to its initial state

Example
  $i.reset();

Exceptions

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

bool Qore::SingleValueIterator::valid | ( |  | ) |
| 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

Code Flags:
  CONSTANT

Example:
  if ($i.valid())
  printf("current value: %y\n", $i.getValue());

Implements Qore::AbstractIterator.