< FilterIterator > Protocol Reference

Abstract filter for iterators. More...

Inheritance diagram for < FilterIterator >:

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

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

Protected Member Functions

 __clone ()
 fetch ()

Private Attributes

 $it

Detailed Description

Abstract filter for iterators.

Author:
Marcus Boerger
Version:
1.1
Since:
PHP 5.0
Instances of this class act as a filter around iterators. In other words you can put an iterator into the constructor and the instance will only return selected (accepted) elements.

The only thing that needs to be done to make this work is implementing method accept(). Typically this invloves reading the current element or key of the inner Iterator and checking whether it is acceptable.

Definition at line 26 of file filteriterator.inc.


Constructor & Destructor Documentation

FilterIterator-p::__construct ( Iterator it  ) 

Constructs a filter around another iterator.

Parameters:
it Iterator to filter

Definition at line 35 of file filteriterator.inc.

References $it.

00035                                        {
00036         $this->it = $it;
00037     }


Member Function Documentation

FilterIterator-p::__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 121 of file filteriterator.inc.

00122     {
00123         return call_user_func_array(array($this->it, $func), $params);
00124     }

FilterIterator-p::__clone (  )  [protected]

hidden __clone

Definition at line 104 of file filteriterator.inc.

00104                                  {
00105         // disallow clone 
00106     }

FilterIterator-p::accept (  )  [abstract]

Accept function to decide whether an element of the inner iterator should be accessible through the Filteriterator.

Returns:
whether or not to expose the current element of the inner iterator.

FilterIterator-p::current (  ) 

Returns:
The current value

Implements Iterator.

Definition at line 97 of file filteriterator.inc.

00097                        {
00098         return $this->it->current();
00099     }

FilterIterator-p::fetch (  )  [protected]

Fetch next element and store it.

Returns:
void

Definition at line 61 of file filteriterator.inc.

00061                                {
00062         while ($this->it->valid()) {
00063             if ($this->accept()) {
00064                 return;
00065             }
00066             $this->it->next();
00067         };
00068     }

FilterIterator-p::getInnerIterator (  ) 

Returns:
The inner iterator

Implements OuterIterator.

Definition at line 111 of file filteriterator.inc.

00112     {
00113         return $this->it;
00114     }

FilterIterator-p::key (  ) 

Returns:
The current key

Implements Iterator.

Definition at line 90 of file filteriterator.inc.

00090                    {
00091         return $this->it->key();
00092     }

FilterIterator-p::next (  ) 

Move to next element.

Returns:
void

Implements Iterator.

Definition at line 75 of file filteriterator.inc.

00075                     {
00076         $this->it->next();
00077         $this->fetch();
00078     }

FilterIterator-p::rewind (  ) 

Rewind the inner iterator.

Implements Iterator.

Definition at line 42 of file filteriterator.inc.

00042                       { 
00043         $this->it->rewind();
00044         $this->fetch();
00045     }

FilterIterator-p::valid (  ) 

Returns:
Whether more elements are available

Implements Iterator.

Definition at line 83 of file filteriterator.inc.

00083                      {
00084         return $this->it->valid();
00085     }


Member Data Documentation

FilterIterator-p::$it [private]

Definition at line 28 of file filteriterator.inc.


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