AppendIterator Class Reference
[Internal classes]

Iterator that iterates over several iterators one after the other. More...

Inheritance diagram for AppendIterator:

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

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 ()
 append (Iterator $it)
 current ()
 getInnerIterator ()
 key ()
 next ()
 rewind ()
 valid ()

Private Attributes

 $iterators

Detailed Description

Iterator that iterates over several iterators one after the other.

Author:
Marcus Boerger
Version:
1.0
Since:
PHP 5.1

Definition at line 18 of file appenditerator.inc.


Constructor & Destructor Documentation

AppendIterator::__construct (  ) 

Construct an empty AppendIterator.

Definition at line 25 of file appenditerator.inc.

00026     {
00027         $this->iterators = new ArrayIterator();
00028     }


Member Function Documentation

AppendIterator::__call ( func,
params 
)

Aggregates the inner iterator.

Definition at line 116 of file appenditerator.inc.

References getInnerIterator().

00117     {
00118         return call_user_func_array(array($this->getInnerIterator(), $func), $params);
00119     }

Here is the call graph for this function:

AppendIterator::getInnerIterator

AppendIterator::append ( Iterator it  ) 

Append an Iterator.

Parameters:
$it Iterator to append
If the current state is invalid but the appended iterator is valid the the AppendIterator itself becomes valid. However there will be no call to $it->rewind(). Also if the current state is invalid the inner ArrayIterator will be rewound und forwarded to the appended element.

Definition at line 38 of file appenditerator.inc.

References $it.

00039     {
00040         $this->iterators->append($it);
00041     }

AppendIterator::current (  ) 

Returns:
the current value if it is valid or NULL

Implements Iterator.

Definition at line 71 of file appenditerator.inc.

References getInnerIterator().

00072     {
00073         /* Using $this->valid() would be exactly the same; it would omit
00074          * the access to a non valid element in the inner iterator. Since
00075          * the user didn't respect the valid() return value false this
00076          * must be intended hence we go on. */
00077         return $this->iterators->valid() ? $this->getInnerIterator()->current() : NULL;
00078     }

Here is the call graph for this function:

AppendIterator::getInnerIterator

AppendIterator::getInnerIterator (  ) 

Returns:
the current inner Iterator

Implements OuterIterator.

Definition at line 45 of file appenditerator.inc.

Referenced by __call(), current(), key(), next(), rewind(), and valid().

00046     {
00047         return $this->iterators->current();
00048     }

AppendIterator::key (  ) 

Returns:
the current key if it is valid or NULL

Implements Iterator.

Definition at line 82 of file appenditerator.inc.

References getInnerIterator().

00083     {
00084         return $this->iterators->valid() ? $this->getInnerIterator()->key() : NULL;
00085     }

Here is the call graph for this function:

AppendIterator::getInnerIterator

AppendIterator::next (  ) 

Move to the next element.

If this means to another Iterator that rewind that Iterator.

Returns:
void

Implements Iterator.

Definition at line 91 of file appenditerator.inc.

References getInnerIterator(), and valid().

00092     {
00093         if (!$this->iterators->valid())
00094         {
00095             return; /* done all */
00096         }
00097         $this->getInnerIterator()->next();
00098         if ($this->getInnerIterator()->valid())
00099         {
00100             return; /* found valid element in current inner iterator */
00101         }
00102         $this->iterators->next();
00103         while ($this->iterators->valid())
00104         {
00105             $this->getInnerIterator()->rewind();
00106             if ($this->getInnerIterator()->valid())
00107             {
00108                 return; /* found element as first elemet in another iterator */
00109             }
00110             $this->iterators->next();
00111         }
00112     }

Here is the call graph for this function:

AppendIterator::getInnerIteratorAppendIterator::valid

AppendIterator::rewind (  ) 

Rewind to the first element of the first inner Iterator.

Returns:
void

Implements Iterator.

Definition at line 53 of file appenditerator.inc.

References getInnerIterator().

00054     {
00055         $this->iterators->rewind();
00056         if ($this->iterators->valid())
00057         {
00058             $this->getInnerIterator()->rewind();
00059         }
00060     }

Here is the call graph for this function:

AppendIterator::getInnerIterator

AppendIterator::valid (  ) 

Returns:
whether the current element is valid

Implements Iterator.

Definition at line 64 of file appenditerator.inc.

References getInnerIterator().

Referenced by next().

00065     {
00066         return $this->iterators->valid() && $this->getInnerIterator()->valid();
00067     }

Here is the call graph for this function:

AppendIterator::getInnerIterator


Member Data Documentation

AppendIterator::$iterators [private]

For internal use only.

array of inner iterators

Definition at line 21 of file appenditerator.inc.


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