SPL-StandardPHPLibrary
Public Member Functions | Static Public Member Functions | Public Attributes | Private Attributes
RecursiveDualIterator Class Reference
Inheritance diagram for RecursiveDualIterator:
Inheritance graph
[legend]
Collaboration diagram for RecursiveDualIterator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 __construct (RecursiveIterator $lhs, RecursiveIterator $rhs, $flags=0x33)
 areEqual ()
 areIdentical ()
 current ()
 getChildren ()
 getFlags ()
 getLHS ()
 getRHS ()
 hasChildren ()
 key ()
 next ()
 rewind ()
 setFlags ($flags)
 valid ()

Static Public Member Functions

static compareIterators (Iterator $lhs, Iterator $rhs, $identical=false)

Public Attributes

const CURRENT_0 = 0x00
const CURRENT_ARRAY = 0x03
const CURRENT_LHS = 0x01
const CURRENT_RHS = 0x02
const DEFAULT_FLAGS = 0x13
const KEY_0 = 0x00
const KEY_LHS = 0x10
const KEY_RHS = 0x20

Private Attributes

 $ref

Detailed Description

Synchronous iteration over two recursive iterators.

Author:
Marcus Boerger
Version:
1.0

Definition at line 17 of file recursivedualiterator.inc.


Constructor & Destructor Documentation

RecursiveDualIterator::__construct ( RecursiveIterator lhs,
RecursiveIterator rhs,
flags = 0x33 
)

construct iterator from two RecursiveIterator instances

Parameters:
lhsLeft Hand Side Iterator
rhsRight Hand Side Iterator
flagsiteration flags

Definition at line 27 of file recursivedualiterator.inc.

References DualIterator\$flags.


Member Function Documentation

RecursiveDualIterator::areEqual ( )
Returns:
whether both inner iterators are valid, have same hasChildren() state and equal current and key values or both are invalid.

Reimplemented from DualIterator.

Definition at line 65 of file recursivedualiterator.inc.

References DualIterator\getLHS(), and DualIterator\getRHS().

    {
        return $this->getLHS()->hasChildren() === $this->getRHS()->hasChildren()
            && parent::areEqual();
    }

Here is the call graph for this function:

RecursiveDualIterator::areIdentical ( )
Returns:
whether both inner iterators are valid, have same hasChildren() state and identical current and key values or both are non valid.

Reimplemented from DualIterator.

Definition at line 56 of file recursivedualiterator.inc.

References DualIterator\getLHS(), and DualIterator\getRHS().

    {
        return $this->getLHS()->hasChildren() === $this->getRHS()->hasChildren()
            && parent::areIdentical();
    }

Here is the call graph for this function:

static DualIterator::compareIterators ( Iterator lhs,
Iterator rhs,
identical = false 
) [static, inherited]

Compare two iterators.

Parameters:
lhsLeft Hand Side Iterator
rhsRight Hand Side Iterator
identicalwhether to use areEqual() or areIdentical()
Returns:
whether both iterators are equal/identical
Note:
If one implements RecursiveIterator the other must do as well. And if both do then a recursive comparison is being used.

Definition at line 165 of file dualiterator.inc.

References $it.

    {
        if ($lhs instanceof RecursiveIterator)
        {
            if ($rhs instanceof RecursiveIterator)
            {
                $it = new RecursiveDualIterator($lhs, $rhs, 
                                self::CURRENT_0 | self::KEY_0);
                $it = new RecursiveCompareDualIterator($it);
            }
            else
            {
                return false;
            }
        }
        else
        {
            $it = new DualIterator($lhs, $rhs, self::CURRENT_0 | self::KEY_0);
        }

        if ($identical)
        {
            foreach($it as $n)
            {
                if (!$it->areIdentical())
                {
                    return false;
                }
            }
        }
        else
        {
            foreach($it as $n)
            {
                if (!$it->areEqual())
                {
                    return false;
                }
            }
        }
        return $identical ? $it->areIdentical() : $it->areEqual();
    }
DualIterator::current ( ) [inherited]
Returns:
current value depending on CURRENT_* flags

Implements Iterator.

Definition at line 93 of file dualiterator.inc.

    {
        switch($this->flags & 0x0F)
        {
        default:
        case self::CURRENT_ARRAY:
            return array($this->lhs->current(), $this->rhs->current());
        case self::CURRENT_LHS:
            return $this->lhs->current();
        case self::CURRENT_RHS:
            return $this->rhs->current();
        case self::CURRENT_0:
            return NULL;
        }
    }
RecursiveDualIterator::getChildren ( )
Returns:
new RecursiveDualIterator (late binding) for the two inner iterators current children.

Implements RecursiveIterator.

Definition at line 43 of file recursivedualiterator.inc.

References DualIterator\getFlags(), DualIterator\getLHS(), and DualIterator\getRHS().

    {
        if (empty($this->ref))
        {
            $this->ref = new ReflectionClass($this);
        }
        return $this->ref->newInstance(
                    $this->getLHS()->getChildren(), $this->getRHS()->getChildren(), $this->getFlags());
    }

Here is the call graph for this function:

DualIterator::getFlags ( ) [inherited]
Returns:
current flags

Definition at line 71 of file dualiterator.inc.

Referenced by getChildren().

    {
        return $this->flags;
    }
DualIterator::getLHS ( ) [inherited]
Returns:
Left Hand Side Iterator

Definition at line 50 of file dualiterator.inc.

Referenced by areEqual(), areIdentical(), getChildren(), and hasChildren().

    {
        return $this->lhs;
    }
DualIterator::getRHS ( ) [inherited]
Returns:
Right Hand Side Iterator

Definition at line 57 of file dualiterator.inc.

Referenced by areEqual(), areIdentical(), getChildren(), and hasChildren().

    {
        return $this->rhs;
    }
RecursiveDualIterator::hasChildren ( )
Returns:
whether both LHS and RHS have children

Implements RecursiveIterator.

Definition at line 35 of file recursivedualiterator.inc.

References DualIterator\getLHS(), and DualIterator\getRHS().

    {
        return $this->getLHS()->hasChildren() && $this->getRHS()->hasChildren();    
    }

Here is the call graph for this function:

DualIterator::key ( ) [inherited]
Returns:
key value depending on KEY_* flags

Implements Iterator.

Definition at line 111 of file dualiterator.inc.

    {
        switch($this->flags & 0xF0)
        {
        default:
        case self::KEY_LHS:
            return $this->lhs->key();
        case self::KEY_RHS:
            return $this->rhs->key();
        case self::KEY_0:
            return NULL;
        }
    }
DualIterator::next ( ) [inherited]

move both inner iterators forward

Implements Iterator.

Definition at line 127 of file dualiterator.inc.

    {
        $this->lhs->next();
        $this->rhs->next();
    }
DualIterator::rewind ( ) [inherited]

rewind both inner iterators

Implements Iterator.

Definition at line 78 of file dualiterator.inc.

    {
        $this->lhs->rewind();
        $this->rhs->rewind();   
    }
DualIterator::setFlags ( flags) [inherited]
Parameters:
flagsnew flags

Definition at line 64 of file dualiterator.inc.

References DualIterator\$flags.

    {
        $this->flags = $flags;
    }
DualIterator::valid ( ) [inherited]
Returns:
whether both inner iterators are valid

Implements Iterator.

Definition at line 86 of file dualiterator.inc.

Referenced by DualIterator\areEqual(), and DualIterator\areIdentical().

    {
        return $this->lhs->valid() && $this->rhs->valid();  
    }

Member Data Documentation

RecursiveDualIterator::$ref [private]

Definition at line 19 of file recursivedualiterator.inc.

const DualIterator::CURRENT_0 = 0x00 [inherited]

Definition at line 22 of file dualiterator.inc.

const DualIterator::CURRENT_ARRAY = 0x03 [inherited]

Definition at line 21 of file dualiterator.inc.

const DualIterator::CURRENT_LHS = 0x01 [inherited]

Definition at line 19 of file dualiterator.inc.

const DualIterator::CURRENT_RHS = 0x02 [inherited]

Definition at line 20 of file dualiterator.inc.

const DualIterator::DEFAULT_FLAGS = 0x13 [inherited]

Definition at line 28 of file dualiterator.inc.

const DualIterator::KEY_0 = 0x00 [inherited]

Definition at line 26 of file dualiterator.inc.

const DualIterator::KEY_LHS = 0x10 [inherited]

Definition at line 24 of file dualiterator.inc.

const DualIterator::KEY_RHS = 0x20 [inherited]

Definition at line 25 of file dualiterator.inc.


The documentation for this class was generated from the following file: