seekableiterator.inc 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /** @file seekableiterator.inc
  3. * @ingroup SPL
  4. * @brief class SeekableIterator
  5. * @author Marcus Boerger
  6. * @date 2003 - 2009
  7. *
  8. * SPL - Standard PHP Library
  9. */
  10. /** @brief seekable iterator
  11. * @author Marcus Boerger
  12. * @version 1.0
  13. * @since PHP 5.0
  14. *
  15. * Turns a normal iterator ino a seekable iterator. When there is a way
  16. * to seek on an iterator LimitIterator can use this to efficiently rewind
  17. * to offset.
  18. */
  19. interface SeekableIterator extends Iterator
  20. {
  21. /** Seek to an absolute position
  22. *
  23. * \param $index position to seek to
  24. * \return void
  25. *
  26. * The method should throw an exception if it is not possible to seek to
  27. * the given position. Typically this exception should be of type
  28. * OutOfBoundsException.
  29. \code
  30. function seek($index);
  31. $this->rewind();
  32. $position = 0;
  33. while($position < $index && $this->valid()) {
  34. $this->next();
  35. $position++;
  36. }
  37. if (!$this->valid()) {
  38. throw new OutOfBoundsException('Invalid seek position');
  39. }
  40. }
  41. \endcode
  42. */
  43. function seek($index);
  44. }
  45. ?>