Source for file FindIterator.php

Documentation is available at FindIterator.php

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

Documentation generated on Fri, 13 Jan 2006 07:48:12 +0100 by phpDocumentor 1.3.0RC4