Source for file FindIterator.php

Documentation is available at FindIterator.php

  1. <?php
  2.  
  3. // ----------------------------------------------------------------------------------
  4. // Class: FindIterator
  5. // ----------------------------------------------------------------------------------
  6.  
  7.  
  8.  
  9. /**
  10. * Iterator for traversing statements matching a searchpattern.
  11. * FindIterators are returned by model->findAsIterator()
  12. * Using a find iterator is significantly faster than using model->find() which returns
  13. * a new result model.
  14. *
  15. *
  16. * <BR><BR>History:<UL>
  17. * <LI>08-05-2004 : First version of this class.</LI>
  18. * </UL>
  19. *
  20. * @version V0.9.1
  21. * @author Tobias Gauß <tobias.gauss@web.de>
  22. *
  23. * @package utility
  24. * @access public
  25. *
  26. */
  27. class FindIterator extends Object {
  28.  
  29. /**
  30. * Reference to the MemModel
  31. * @var object MemModel
  32. * @access private
  33. */
  34. var $model;
  35.  
  36.  
  37. /**
  38. * Current position
  39. * FindIterator does not use the build in PHP array iterator,
  40. * so you can use serveral iterators on a single MemModel.
  41. * @var integer
  42. * @access private
  43. */
  44. var $position;
  45. /**
  46. * Searchpattern
  47. *
  48. * @var Object Subject,Predicate,Object
  49. * @access private
  50. */
  51.  
  52. var $subject;
  53. var $predicate;
  54. var $object;
  55. /**
  56. * Constructor
  57. *
  58. * @param object MemModel
  59. * @param object Subject
  60. * @param object Predicate
  61. * @param object Object
  62. * @access public
  63. */
  64. function FindIterator(&$model,$sub,$pred,$obj) {
  65. $this->model = &$model;
  66. $this->subject=$sub;
  67. $this->predicate=$pred;
  68. $this->object=$obj;
  69. $this->position=-1;
  70. }
  71. /**
  72. * Returns TRUE if there are more matching statements.
  73. * @return boolean
  74. * @access public
  75. */
  76. function hasNext() {
  77. if($this->model->findFirstMatchOff($this->subject,$this->predicate,$this->object,$this->position+1)>-1){
  78. return TRUE;
  79. }else{
  80. return FALSE;
  81. }
  82. }
  83.  
  84. /**
  85. * Returns the next matching statement.
  86. * @return statement or NULL if there is no next matching statement.
  87. * @access public
  88. */
  89. function next() {
  90. $res=$this->model->findFirstMatchOff($this->subject,$this->predicate,$this->object,$this->position+1);
  91. if($res>-1){
  92. $this->position=$res;
  93. return $this->model->triples[$res];
  94. }else{
  95. return Null;
  96. }
  97. }
  98.  
  99. /**
  100. * Returns the current matching statement.
  101. * @return statement or NULL if there is no current matching statement.
  102. * @access public
  103. */
  104. function current() {
  105. if (($this->position >= -1)&&(isset($this->model->triples[$this->position]))) {
  106. return $this->model->triples[$this->position];
  107. } else {
  108. return NULL;
  109. }
  110. }
  111. }
  112.  
  113. ?>

Documentation generated on Fri, 17 Dec 2004 16:14:49 +0100 by phpDocumentor 1.3.0RC3