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

Public Member Functions

 __construct (Iterator $lhs, Iterator $rhs, $flags=0x13)
 
 areEqual ()
 
 areIdentical ()
 
 current ()
 
 getFlags ()
 
 getLHS ()
 
 getRHS ()
 
 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

 $flags
 
 $lhs
 
 $rhs
 

Detailed Description

Synchronous iteration over two iterators.

Author
Marcus Boerger
Version
1.3

Definition at line 17 of file dualiterator.inc.

Constructor & Destructor Documentation

DualIterator::__construct ( Iterator  $lhs,
Iterator  $rhs,
  $flags = 0x13 
)

construct iterator from two iterators

Parameters
lhsLeft Hand Side Iterator
rhsRight Hand Side Iterator
flagsiteration flags

Definition at line 40 of file dualiterator.inc.

References $flags, $lhs, and $rhs.

42  {
43  $this->lhs = $lhs;
44  $this->rhs = $rhs;
45  $this->flags = $flags;
46  }

Member Function Documentation

DualIterator::areEqual ( )
Returns
whether both inner iterators are valid and have equal current and key values or both are non valid.

Definition at line 147 of file dualiterator.inc.

References valid().

148  {
149  return $this->valid()
150  ? $this->lhs->current() == $this->rhs->current()
151  && $this->lhs->key() == $this->rhs->key()
152  : $this->lhs->valid() == $this->rhs->valid();
153  }

Here is the call graph for this function:

DualIterator::areIdentical ( )
Returns
whether both inner iterators are valid and have identical current and key values or both are non valid.

Definition at line 136 of file dualiterator.inc.

References valid().

137  {
138  return $this->valid()
139  ? $this->lhs->current() === $this->rhs->current()
140  && $this->lhs->key() === $this->rhs->key()
141  : $this->lhs->valid() == $this->rhs->valid();
142  }

Here is the call graph for this function:

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

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 ( )
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  }
DualIterator::getFlags ( )
Returns
current flags

Definition at line 71 of file dualiterator.inc.

References $flags.

Referenced by RecursiveDualIterator\getChildren().

72  {
73  return $this->flags;
74  }
DualIterator::getLHS ( )
DualIterator::getRHS ( )
DualIterator::key ( )
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 ( )

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 ( )

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)
Parameters
flagsnew flags

Definition at line 64 of file dualiterator.inc.

References $flags.

65  {
66  $this->flags = $flags;
67  }
DualIterator::valid ( )
Returns
whether both inner iterators are valid

Implements Iterator.

Definition at line 86 of file dualiterator.inc.

Referenced by areEqual(), and areIdentical().

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

Member Data Documentation

DualIterator::$flags
private
DualIterator::$lhs
private

Definition at line 30 of file dualiterator.inc.

Referenced by __construct(), and getLHS().

DualIterator::$rhs
private

Definition at line 31 of file dualiterator.inc.

Referenced by __construct(), and getRHS().

const DualIterator::CURRENT_0 = 0x00

Definition at line 22 of file dualiterator.inc.

const DualIterator::CURRENT_ARRAY = 0x03

Definition at line 21 of file dualiterator.inc.

const DualIterator::CURRENT_LHS = 0x01

Definition at line 19 of file dualiterator.inc.

const DualIterator::CURRENT_RHS = 0x02

Definition at line 20 of file dualiterator.inc.

const DualIterator::DEFAULT_FLAGS = 0x13

Definition at line 28 of file dualiterator.inc.

const DualIterator::KEY_0 = 0x00

Definition at line 26 of file dualiterator.inc.

const DualIterator::KEY_LHS = 0x10

Definition at line 24 of file dualiterator.inc.

const DualIterator::KEY_RHS = 0x20

Definition at line 25 of file dualiterator.inc.


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