IteratorIterator Class Reference
[Internal classes]

Basic Iterator wrapper. More...

Inheritance diagram for IteratorIterator:

Inheritance graph
{InfiniteIterator\n||+ next()\l}{NoRewindIterator\n||+ rewind()\l}{OuterIterator\n||+ getInnerIterator()\l}{Iterator\n||+ current()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l}{Traversable\n||}
[legend]
Collaboration diagram for IteratorIterator:

Collaboration graph
{OuterIterator\n||+ getInnerIterator()\l}{Iterator\n||+ current()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l}{Traversable\n||}
[legend]
List of all members.

Public Member Functions

 __call ($func, $params)
 __construct (Traversable $iterator, $classname=null)
 current ()
 getInnerIterator ()
 key ()
 next ()
 rewind ()
 valid ()

Private Attributes

 $iterator

Detailed Description

Basic Iterator wrapper.

Since:
PHP 5.1
This iterator wrapper allows to convert anything that is traversable into an Iterator. It is very important to understand that most classes that do not implement Iterator have their reasone to. Most likely they do not allow the full Iterator feature set. If so you need to provide techniques to prevent missuse. If you do not you must expect exceptions or fatal erros.

It is also possible to derive the class and implement IteratorAggregate by downcasting the instances returned in getIterator. See the following example (assuming BaseClass implements Traversable):

 class SomeClass extends BaseClass implements IteratorAggregate
 {
   function getIterator()
   {
     return new IteratorIterator($this, 'BaseClass');
   }
 }

As you can see in the example this approach requires that the class to downcast to is actually a base class of the specified iterator to wrap. Omitting the downcast in the above example would result in an endless loop since IteratorIterator::__construct() would call SomeClass::getIterator().

Definition at line 40 of file iteratoriterator.inc.


Constructor & Destructor Documentation

IteratorIterator::__construct ( Traversable iterator,
classname = null 
)

Construct an IteratorIterator from an Iterator or an IteratorAggregate.

Parameters:
iterator inner iterator
classname optional class the iterator has to be downcasted to

Definition at line 47 of file iteratoriterator.inc.

References $iterator.

00048     {
00049         if ($iterator instanceof IteratorAggregate)
00050         {
00051             $iterator = $iterator->getIterator();
00052         }
00053         if ($iterator instanceof Iterator)
00054         {
00055             $this->iterator = $iterator;
00056         }
00057         else
00058         {
00059             throw new Exception("Classes that only implement Traversable can be wrapped only after converting class IteratorIterator into c code");
00060         }
00061     }


Member Function Documentation

IteratorIterator::__call ( func,
params 
)

Aggregate the inner iterator.

Parameters:
func Name of method to invoke
params Array of parameters to pass to method

Definition at line 110 of file iteratoriterator.inc.

00111     {
00112         return call_user_func_array(array($this->iterator, $func), $params);
00113     }

IteratorIterator::current (  ) 

Returns:
current value

Implements Iterator.

Definition at line 86 of file iteratoriterator.inc.

00087     {
00088         return $this->iterator->current();
00089     }

IteratorIterator::getInnerIterator (  ) 

Returns:
the inner iterator as passed to the constructor

Implements OuterIterator.

Definition at line 65 of file iteratoriterator.inc.

Referenced by InfiniteIterator::next().

00066     {
00067         return $this->iterator;
00068     }

IteratorIterator::key (  ) 

Returns:
current key

Implements Iterator.

Definition at line 79 of file iteratoriterator.inc.

00080     {
00081         return $this->iterator->key();
00082     }

IteratorIterator::next (  ) 

forward to next element

Implements Iterator.

Reimplemented in InfiniteIterator.

Definition at line 93 of file iteratoriterator.inc.

00094     {
00095         return $this->iterator->next();
00096     }

IteratorIterator::rewind (  ) 

rewind to the first element

Implements Iterator.

Reimplemented in NoRewindIterator.

Definition at line 100 of file iteratoriterator.inc.

00101     {
00102         return $this->iterator->rewind();
00103     }

IteratorIterator::valid (  ) 

Returns:
whether the iterator is valid

Implements Iterator.

Definition at line 72 of file iteratoriterator.inc.

Referenced by InfiniteIterator::next().

00073     {
00074         return $this->iterator->valid();
00075     }


Member Data Documentation

IteratorIterator::$iterator [private]

The inner iterator must be private because when this class will be converted to c code it won't no longer be available.

Definition at line 118 of file iteratoriterator.inc.

Referenced by __construct().


The documentation for this class was generated from the following file:
Generated on Thu Apr 26 01:06:15 2007 for SPL-StandardPHPLibrary by  doxygen 1.5.2