helly           Sun Sep 26 17:21:46 2004 EDT

  Added files:                 
    /php-src/ext/spl/examples   iteratoriterator.inc outeriterator.inc 
  Log:
  Add new examples
  

http://cvs.php.net/co.php/php-src/ext/spl/examples/iteratoriterator.inc?r=1.1&p=1
Index: php-src/ext/spl/examples/iteratoriterator.inc
+++ php-src/ext/spl/examples/iteratoriterator.inc
<?php

/** \ingroup SPL
 * \brief Basic Iterator wrapper
 */
class IteratorIterator implements OuterIterator
{
        /** Construct an IteratorIterator from an Iterator or an IteratorAggregate.
         *
         * Classes that only implement Traversable can be wrapped only after 
         * converting class IteratorItaerator into c code.
         */
        function __construct(Traversable $iterator)
        {
                if ($iterator instanceof IteratorAggregate)
                {
                    $iterator = $iterator->getIterator();
                }
                if ($iterator instanceof Iterator)
                {
                        $this->iterator = $iterator;
                }
                else
                {
                        throw new Exception("Classes that only implement Traversable 
can be wrapped only after converting class IteratorItaerator into c code");
                }
        }

        /** \return the inner iterator as passed to the constructor
         */
        function getInnerIterator()
        {
                return $this->iterator;
        }

        /** \return whetehr the iterator is valid
         */
        function valid()
        {
                return $this->iterator->valid();
        }

        /** \return current key
         */
        function key()
        {
                return $this->iterator->key();
        }

        /** \return current value
         */
        function current()
        {
                return $this->iterator->current();
        }

        /** forward to next element
         */
        function next()
        {
                return $this->iterator->next();
        }

        /** rewind to the first element
         */
        function rewind()
        {
                return $this->iterator->rewind();
        }

        /** The inner iterator must be public becaus ewhen this class will be
         * converted to c code it won't no longer be available.
         */
        private $iterator;
}

?>
http://cvs.php.net/co.php/php-src/ext/spl/examples/outeriterator.inc?r=1.1&p=1
Index: php-src/ext/spl/examples/outeriterator.inc
+++ php-src/ext/spl/examples/outeriterator.inc
<?php

/** \ingroup SPL
 * \brief Interface to access inner iterator of iterator wrappers
 */
interface OuterIterator extends Iterator
{
        /** \return inner iterator
         */
    abstract function getInnerIterator();
}

?>

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to