recursivecomparedualiterator.inc 1.8 KB

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