SPL-StandardPHPLibrary
Public Member Functions | Static Public Member Functions | Public Attributes | Private Attributes | List of all members
RecursiveDualIterator Class Reference
Inheritance diagram for RecursiveDualIterator:
Inheritance graph
Collaboration diagram for RecursiveDualIterator:
Collaboration graph

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.

29  {
30  parent::__construct($lhs, $rhs, $flags);
31  }

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.

Definition at line 65 of file recursivedualiterator.inc.

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

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

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.

Definition at line 56 of file recursivedualiterator.inc.

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

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

Here is the call graph for this function:

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

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.

167  {
168  if ($lhs instanceof RecursiveIterator)
169  {
170  if ($rhs instanceof RecursiveIterator)
171  {
172  $it = new RecursiveDualIterator($lhs, $rhs,
173  self::CURRENT_0 | self::KEY_0);
175  }
176  else
177  {
178  return false;
179  }
180  }
181  else
182  {
183  $it = new DualIterator($lhs, $rhs, self::CURRENT_0 | self::KEY_0);
184  }
185 
186  if ($identical)
187  {
188  foreach($it as $n)
189  {
190  if (!$it->areIdentical())
191  {
192  return false;
193  }
194  }
195  }
196  else
197  {
198  foreach($it as $n)
199  {
200  if (!$it->areEqual())
201  {
202  return false;
203  }
204  }
205  }
206  return $identical ? $it->areIdentical() : $it->areEqual();
207  }
Recursive comparison iterator for a RecursiveDualIterator.
$it
Definition: class_tree.php:105
Interface for recursive iteration with RecursiveIteratorIterator.
Synchronous iteration over two recursive iterators.
Synchronous iteration over two iterators.
DualIterator::current ( )
inherited
Returns
current value depending on CURRENT_* flags

Implements Iterator.

Definition at line 93 of file dualiterator.inc.

94  {
95  switch($this->flags & 0x0F)
96  {
97  default:
98  case self::CURRENT_ARRAY:
99  return array($this->lhs->current(), $this->rhs->current());
100  case self::CURRENT_LHS:
101  return $this->lhs->current();
102  case self::CURRENT_RHS:
103  return $this->rhs->current();
104  case self::CURRENT_0:
105  return NULL;
106  }
107  }
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().

44  {
45  if (empty($this->ref))
46  {
47  $this->ref = new ReflectionClass($this);
48  }
49  return $this->ref->newInstance(
50  $this->getLHS()->getChildren(), $this->getRHS()->getChildren(), $this->getFlags());
51  }

Here is the call graph for this function:

DualIterator::getFlags ( )
inherited
Returns
current flags

Definition at line 71 of file dualiterator.inc.

References DualIterator\$flags.

Referenced by getChildren().

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

Definition at line 50 of file dualiterator.inc.

References DualIterator\$lhs.

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

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

Definition at line 57 of file dualiterator.inc.

References DualIterator\$rhs.

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

58  {
59  return $this->rhs;
60  }
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().

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

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.

112  {
113  switch($this->flags & 0xF0)
114  {
115  default:
116  case self::KEY_LHS:
117  return $this->lhs->key();
118  case self::KEY_RHS:
119  return $this->rhs->key();
120  case self::KEY_0:
121  return NULL;
122  }
123  }
DualIterator::next ( )
inherited

move both inner iterators forward

Implements Iterator.

Definition at line 127 of file dualiterator.inc.

128  {
129  $this->lhs->next();
130  $this->rhs->next();
131  }
DualIterator::rewind ( )
inherited

rewind both inner iterators

Implements Iterator.

Definition at line 78 of file dualiterator.inc.

79  {
80  $this->lhs->rewind();
81  $this->rhs->rewind();
82  }
DualIterator::setFlags (   $flags)
inherited
Parameters
flagsnew flags

Definition at line 64 of file dualiterator.inc.

References DualIterator\$flags.

65  {
66  $this->flags = $flags;
67  }
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().

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

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: