1<?php
2
3/** @file recursivecomparedualiterator.inc
4 * @ingroup Examples
5 * @brief class DualIterator
6 * @author  Marcus Boerger
7 * @date    2003 - 2006
8 *
9 * SPL - Standard PHP Library
10 */
11
12/** @ingroup Examples
13 * @brief   Recursive comparison iterator for a RecursiveDualIterator
14 * @author  Marcus Boerger
15 * @version 1.0
16 */
17class RecursiveCompareDualIterator extends RecursiveIteratorIterator
18{
19	/** Used to keep end of recursion equality. That is en leaving a nesting
20	 * level we need to check whether both child iterators are at their end.
21	 */
22	protected $equal = false;
23
24	/** Construct from RecursiveDualIterator
25	 *
26	 * @param $it      RecursiveDualIterator
27	 * @param $mode    should be LEAVES_ONLY
28	 * @param $flags   should be 0
29	 */
30	function __construct(RecursiveDualIterator $it, $mode = self::LEAVES_ONLY, $flags = 0)
31	{
32		parent::__construct($it);
33	}
34
35	/** Rewind iteration andcomparison process. Starting with $equal = true.
36	 */
37	function rewind()
38	{
39		$this->equal = true;
40		parent::rewind();
41	}
42
43	/** Calculate $equal
44	 * @see $equal
45	 */
46	function endChildren()
47	{
48		$this->equal &= !$this->getInnerIterator()->getLHS()->valid()
49		             && !$this->getInnerIterator()->getRHS()->valid();
50	}
51
52	/** @return whether both inner iterators are valid and have identical
53	 * current and key values or both are non valid.
54	 */
55	function areIdentical()
56	{
57		return $this->equal && $this->getInnerIterator()->areIdentical();
58	}
59
60	/** @return whether both inner iterators are valid and have equal current
61	 * and key values or both are non valid.
62	 */
63	function areEqual()
64	{
65		return $this->equal && $this->getInnerIterator()->areEqual();
66	}
67}
68
69?>
70