Back to index

php5  5.3.10
Public Member Functions
SeekableIterator Interface Reference

seekable iterator More...

Inheritance diagram for SeekableIterator:
Inheritance graph
[legend]
Collaboration diagram for SeekableIterator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 seek ($index)
 Seek to an absolute position.
 rewind ()
 Rewind the Iterator to the first element.
 current ()
 Return the current element.
 key ()
 Return the key of the current element.
 next ()
 Move forward to next element.
 valid ()
 Check if there is a current element after calls to rewind() or next().

Detailed Description

seekable iterator

Author:
Marcus Boerger
Version:
1.0
Since:
PHP 5.0

Turns a normal iterator ino a seekable iterator. When there is a way to seek on an iterator LimitIterator can use this to efficiently rewind to offset.

Definition at line 21 of file seekableiterator.inc.


Member Function Documentation

Iterator::current ( ) [inherited]
Iterator::key ( ) [inherited]
Iterator::next ( ) [inherited]
Iterator::rewind ( ) [inherited]
SeekableIterator::seek ( index)

Seek to an absolute position.

Parameters:
$indexposition to seek to
Returns:
void

The method should throw an exception if it is not possible to seek to the given position. Typically this exception should be of type OutOfBoundsException.

       function seek($index);
              $this->rewind();
              $position = 0;
              while($position < $index && $this->valid()) {
                     $this->next();
                     $position++;
              }
              if (!$this->valid()) {
                     throw new OutOfBoundsException('Invalid seek position');
              }
       }

Implemented in ArrayIterator, and SplFileObject.

Iterator::valid ( ) [inherited]

The documentation for this interface was generated from the following file: