]> granicus.if.org Git - php/commitdiff
Use OuterIterator to simplify conversion to C code
authorMarcus Boerger <helly@php.net>
Fri, 8 Oct 2004 21:12:15 +0000 (21:12 +0000)
committerMarcus Boerger <helly@php.net>
Fri, 8 Oct 2004 21:12:15 +0000 (21:12 +0000)
ext/spl/examples/appenditerator.inc
ext/spl/examples/directoryfilterdots.inc
ext/spl/examples/infiniteiterator.inc
ext/spl/examples/norewinditerator.inc

index d2d5c8dd0b7b937bc43ae73214417d13d73ba709..d9edebc123e12bd1c15b90419d7ddd4d4ad155a3 100755 (executable)
@@ -14,7 +14,7 @@
  * @author  Marcus Boerger
  * @version 1.0
  */
-class AppendIterator implements Iterator
+class AppendIterator implements OuterIterator
 {
        /** @internal array of inner iterators */
        private $iterators;
index 899ae6a5d6c455a3383c72324e6013eee2ffd6ee..abad2832343a2dc9f6e5182882b2481df246e9b2 100755 (executable)
@@ -31,28 +31,28 @@ class DirectoryFilterDots extends FilterIterator implements RecursiveIterator
         */     
        function accept()
        {
-               return !$this->it->isDot();
+               return !$this->getInnerIterator()->isDot();
        }
        
        /** @return whether the current entry is a directory
         */
        function hasChildren()
        {
-               return $this->it->hasChildren();
+               return $this->getInnerIterator()->hasChildren();
        }
 
        /** @return the current subdirectory as a new DirectoryFilterDots instance.
         */
        function getChildren()
        {
-               return new DirectoryFilterDots($this->it->getPathname());
+               return new DirectoryFilterDots($this->getInnerIterator()->getPathname());
        }
        
        /** @return the current entries path name
         */
        function key()
        {
-               return $this->it->getPathname();
+               return $this->getInnerIterator()->getPathname();
        }
 }
 
index 5f27633eb35cf599fdf4e210e1c7245119ed800b..7ff9d4472b77837b9e343d6d8a30387f3d123e45 100755 (executable)
@@ -29,7 +29,7 @@
  }
  \endverbatim
  */
-class InfiniteIterator implements Iterator
+class InfiniteIterator implements OuterIterator
 {
        /** @internal 
         * The inner Iterator. */
@@ -55,28 +55,28 @@ class InfiniteIterator implements Iterator
         */
        function rewind()
        {
-               $this->it->rewind();
+               $this->getInnerIterator()->rewind();
        }
 
        /** @return whether the current element is valid
         */
        function valid()
        {
-               return $this->it->valid();
+               return $this->getInnerIterator()->valid();
        }
 
        /** @return the current value
         */
        function current()
        {
-               return $this->it->current();
+               return $this->getInnerIterator()->current();
        }
 
        /** @return the current key
         */
        function key()
        {
-               return $this->it->key();
+               return $this->getInnerIterator()->key();
        }
 
        /** Move the inner Iterator forward to its next element or rewind it.
@@ -84,10 +84,10 @@ class InfiniteIterator implements Iterator
         */
        function next()
        {
-               $this->it->next();
-               if (!$this->it->valid())
+               $this->getInnerIterator()->next();
+               if (!$this->getInnerIterator()->valid())
                {
-                       $this->it->rewind();
+                       $this->getInnerIterator()->rewind();
                }
        }
 
@@ -95,7 +95,7 @@ class InfiniteIterator implements Iterator
         */     
        function __call($func, $params)
        {
-               return call_user_func_array(array($this->it, $func), $params);
+               return call_user_func_array(array($this->getInnerIterator(), $func), $params);
        }
 }
 
index 6564e1d53ef14e1887ec30f1403be8761f193c1c..cdd030c990bba1231ac17d18906940d81856e076 100755 (executable)
@@ -15,7 +15,7 @@
  * @version 1.0
  *
  */
-class NoRewindIterator implements Iterator
+class NoRewindIterator implements OuterIterator
 {
        protected $it;
        
@@ -31,22 +31,27 @@ class NoRewindIterator implements Iterator
 
        function valid()
        {
-               return $this->it->valid();
+               return $this->getInnerIterator()->valid();
        }
 
        function current()
        {
-               return $this->it->current();
+               return $this->getInnerIterator()->current();
        }
 
        function key()
        {
-               return $this->it->key();
+               return $this->getInnerIterator()->key();
        }
 
        function next()
        {
-               $this->it->next();
+               $this->getInnerIterator()->next();
+       }
+       
+       function getInnerIterator()
+       {
+               return $this->it;
        }
 }