From c4dd7a1a684490673e25aaf4fabec5df138854c4 Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Thu, 14 Mar 2013 05:42:27 +0000 Subject: Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2. --- ext/spl/internal/limititerator.inc | 134 +++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 ext/spl/internal/limititerator.inc (limited to 'ext/spl/internal/limititerator.inc') diff --git a/ext/spl/internal/limititerator.inc b/ext/spl/internal/limititerator.inc new file mode 100644 index 0000000..c5bddea --- /dev/null +++ b/ext/spl/internal/limititerator.inc @@ -0,0 +1,134 @@ + 0'); + } + if ($count < 0 && $count != -1) { + throw new exception('Parameter count must either be -1 or a value greater than or equal to 0'); + } + $this->it = $it; + $this->offset = $offset; + $this->count = $count; + $this->pos = 0; + } + + /** Seek to specified position + * @param position offset to seek to (relative to beginning not offset + * specified in constructor). + * @throw exception when position is invalid + */ + function seek($position) { + if ($position < $this->offset) { + throw new exception('Cannot seek to '.$position.' which is below offset '.$this->offset); + } + if ($position > $this->offset + $this->count && $this->count != -1) { + throw new exception('Cannot seek to '.$position.' which is behind offset '.$this->offset.' plus count '.$this->count); + } + if ($this->it instanceof SeekableIterator) { + $this->it->seek($position); + $this->pos = $position; + } else { + while($this->pos < $position && $this->it->valid()) { + $this->next(); + } + } + } + + /** Rewind to offset specified in constructor + */ + function rewind() + { + $this->it->rewind(); + $this->pos = 0; + $this->seek($this->offset); + } + + /** @return whether iterator is valid + */ + function valid() { + return ($this->count == -1 || $this->pos < $this->offset + $this->count) + && $this->it->valid(); + } + + /** @return current key + */ + function key() { + return $this->it->key(); + } + + /** @return current element + */ + function current() { + return $this->it->current(); + } + + /** Forward to nect element + */ + function next() { + $this->it->next(); + $this->pos++; + } + + /** @return current position relative to zero (not to offset specified in + * constructor). + */ + function getPosition() { + return $this->pos; + } + + /** + * @return The inner iterator + */ + function getInnerIterator() + { + return $this->it; + } + + /** Aggregate the inner iterator + * + * @param func Name of method to invoke + * @param params Array of parameters to pass to method + */ + function __call($func, $params) + { + return call_user_func_array(array($this->it, $func), $params); + } +} + +?> \ No newline at end of file -- cgit v1.2.1