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.  * @version  $Id: fsource_utility__utilFindIterator.php.html 443 2007-06-01 16:25:38Z cax $
  15.  * @author Tobias Gauß <tobias.gauss@web.de>
  16.  *
  17.  * @package utility
  18.  * @access    public
  19.  *
  20.  */ 
  21.  class FindIterator extends Object {
  22.  
  23.      /**
  24.     * Reference to the MemModel
  25.     * @var        object MemModel 
  26.     * @access    private
  27.     */    
  28.     var $model;
  29.     
  30.  
  31.  
  32.      /**
  33.     * Current position
  34.     * FindIterator does not use the build in PHP array iterator,
  35.     * so you can use serveral iterators on a single MemModel.
  36.     * @var        integer 
  37.     * @access    private
  38.     */    
  39.     var $position;
  40.     
  41.     
  42.     /**
  43.     * Searchpattern
  44.     * 
  45.     * @var        Object Subject,Predicate,Object
  46.     * @access    private
  47.     */    
  48.  
  49.     var $subject;
  50.     var $predicate;
  51.     var $object;
  52.    
  53.     
  54.    /**
  55.     * Constructor
  56.     *
  57.     * @param    object    MemModel 
  58.     * @param    object  Subject 
  59.     * @param    object  Predicate 
  60.     * @param    object  Object 
  61.     * @access    public
  62.     */
  63.     function FindIterator(&$model,$sub,$pred,$obj{
  64.         $this->model &$model;
  65.         $this->subject=$sub;
  66.         $this->predicate=$pred;
  67.         $this->object=$obj;
  68.         $this->position=-1;
  69.     }
  70.     
  71.     
  72.      /**
  73.     * Returns TRUE if there are more matching statements.
  74.     * @return    boolean 
  75.     * @access    public
  76.     */
  77.     function hasNext({
  78.           if($this->model->findFirstMatchOff($this->subject,$this->predicate,$this->object,$this->position+1)>-1){
  79.               return TRUE;
  80.           }else{
  81.               return FALSE;
  82.           }
  83.     }
  84.  
  85.    
  86.     /**
  87.     * Returns the next matching statement.
  88.     * @return    statement or NULL if there is no next matching statement.
  89.     * @access    public
  90.     */
  91.     function next({
  92.               $res=$this->model->findFirstMatchOff($this->subject,$this->predicate,$this->object,$this->position+1);    
  93.               if($res>-1){
  94.                   $this->position=$res;
  95.                   return $this->model->triples[$res];
  96.               }else{
  97.                   return Null;
  98.               }        
  99.     }
  100.    
  101.    
  102.  
  103.  
  104.     /**
  105.     * Returns the current matching statement.
  106.     * @return    statement or NULL if there is no current matching statement.
  107.     * @access    public
  108.     */
  109.     function current({
  110.           if (($this->position >= -1)&&(isset($this->model->triples[$this->position]))) {
  111.             return $this->model->triples[$this->position];
  112.         else {
  113.             return NULL;
  114.         
  115.     }  
  116.   
  117.  
  118.  
  119. ?>

Documentation generated on Fri, 1 Jun 2007 16:49:08 +0200 by phpDocumentor 1.3.2