Qore::AbstractLineIterator Class Referenceabstract

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

Inheritance diagram for Qore::AbstractLineIterator:
[legend]

## Public Member Functions

abstract string | getLine ()
| Returns the current line in the data or throws an `INVALID-ITERATOR` exception if the iterator is invalid. More...
abstract string | getValue ()
| Returns the current line in the data or throws an `INVALID-ITERATOR` exception if the iterator is invalid. More...
abstract int | index ()
| Returns the current iterator line number (the first line is line 1) or 0 if not pointing at a valid element. More...
abstract bool | next ()
| Moves the current position to the next line; returns False if there are no more lines to read. 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 line iterators.

Classes inheriting this class can be used to iterate lines from various sources.

Since
  Qore 0.8.13

## Member Function Documentation

## getLine()

abstract string Qore::AbstractLineIterator::getLine | ( |  | ) |

pure virtual

Returns the current line in the data or throws an `INVALID-ITERATOR` exception if the iterator is invalid.

Returns
  the current line in the data

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

Exceptions

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

Implemented in Qore::FileLineIterator, Qore::DataLineIterator, and Qore::InputStreamLineIterator.

## getValue()

abstract string Qore::AbstractLineIterator::getValue | ( |  | ) |

pure virtual

Returns the current line in the data or throws an `INVALID-ITERATOR` exception if the iterator is invalid.

This method calls AbstractLineIterator::getLine() internally.

Returns
  the current line in the data

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

Exceptions

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

See also
  AbstractLineIterator::getLine()

Implements Qore::AbstractIterator.

Implemented in Qore::FileLineIterator, Qore::InputStreamLineIterator, and Qore::DataLineIterator.

## index()

abstract int Qore::AbstractLineIterator::index | ( |  | ) |

pure virtual

Returns the current iterator line number (the first line is line 1) or 0 if not pointing at a valid element.

Returns
  the current iterator line number (the first line is line 1) or 0 if not pointing at a valid element

Example:
  while (i.next()) {
  printf("+ %d: %y\n", i.index(), i.getLine());
  }

Implemented in Qore::FileLineIterator, Qore::InputStreamLineIterator, and Qore::DataLineIterator.

## next()

abstract bool Qore::AbstractLineIterator::next | ( |  | ) |

pure virtual

Moves the current position to the next line; returns False if there are no more lines to read.

This method will return True again after it returns False once if data 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 lines in the source (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("line: %y\n", i.getLine());
  }

Implements Qore::AbstractIterator.

Implemented in Qore::FileLineIterator, Qore::InputStreamLineIterator, and Qore::DataLineIterator.

## valid()

abstract bool Qore::AbstractLineIterator::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());

Implements Qore::AbstractIterator.

Implemented in Qore::FileLineIterator, Qore::DataLineIterator, and Qore::InputStreamLineIterator.