File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / spl / internal / infiniteiterator.inc
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:48:01 2012 UTC (12 years, 8 months ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, v5_3_10, HEAD
php

<?php

/** @file infiniteiterator.inc
 * @ingroup SPL
 * @brief class InfiniteIterator
 * @author  Marcus Boerger
 * @date    2003 - 2009
 *
 * SPL - Standard PHP Library
 */

/** @ingroup SPL
 * @brief   An infinite Iterator
 * @author  Marcus Boerger
 * @version 1.1
 * @since PHP 5.1
 *
 * This Iterator takes another Iterator and infinitvely iterates it by
 * rewinding it when its end is reached.
 *
 * \note Even an InfiniteIterator stops if its inner Iterator is empty.
 *
 \verbatim
 $it       = new ArrayIterator(array(1,2,3));
 $infinite = new InfiniteIterator($it);
 $limit    = new LimitIterator($infinite, 0, 5);
 foreach($limit as $val=>$key)
 {
 	echo "$val=>$key\n";
 }
 \endverbatim
 */
class InfiniteIterator extends IteratorIterator
{
	/** Move the inner Iterator forward to its next element or rewind it.
	 * @return void
	 */
	function next()
	{
		$this->getInnerIterator()->next();
		if (!$this->getInnerIterator()->valid())
		{
			$this->getInnerIterator()->rewind();
		}
	}
}

?>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>