SPL-StandardPHPLibrary
Public Member Functions
SeekableIterator Interface Reference
Inheritance diagram for SeekableIterator:
Inheritance graph
[legend]
Collaboration diagram for SeekableIterator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 current ()
 key ()
 next ()
 rewind ()
 seek ($index)
 valid ()

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: