source: Dev/branches/rest-dojo-ui/Demo/rdfapi/dataset/IteratorAllGraphsMem.php @ 312

Last change on this file since 312 was 312, checked in by jkraaijeveld, 13 years ago
File size: 2.1 KB
Line 
1<?php
2// ----------------------------------------------------------------------------------
3// Class: IteratorAllGraphsMem
4// ----------------------------------------------------------------------------------
5
6
7/**
8* Implementation of a Graph iterator.
9*
10* This Iterator should be used in a for-loop like:
11* for($iterator = $dataset->listGraphs(); $iterator->valid(); $iterator->next())
12* {
13*       $currentResource=$it->current();
14* };
15*
16* @version  $Id$
17* @author Daniel Westphal <mail at d-westphal dot de>
18*
19*
20* @package      dataset
21* @access       public
22**/
23class IteratorAllGraphsMem
24{
25        /**
26        * Holds a reference to the associated RDF dataset
27        *
28        * @var          object dataset
29        * @access       private
30        */
31        var $associatedGraphSet;
32       
33        /**
34        * The current position
35        *
36        * @var          integer
37        * @access       private
38        */
39        var $key;
40       
41        /**
42        * If the current resource is valid
43        *
44        * @var          boolean
45        * @access       private
46        */
47        var $valid;
48       
49        /**
50        * The current NamedGraph
51        *
52        * @var obejct NamedGraph
53        * @access       private
54        */
55        var $current;
56       
57       
58        /**
59    * Constructor.
60    *
61    * @param dataset
62        * @access       public
63    */
64        function IteratorAllGraphsMem(&$namedGraphSet)
65        {
66                $this->associatedGraphSet=&$namedGraphSet;
67                $this->rewind();
68        }
69       
70        /**
71    * Resets iterator list to start
72    *
73        * @access public
74    */
75        function rewind()
76        {
77                $this->key = -1;
78                $this->next();
79        }
80       
81        /**
82    * Says if there are additional items left in the list.
83    *
84    * @return   boolean
85        * @access       public
86    */
87        function valid()
88        {
89                return $this->valid;
90        }
91       
92        /**
93    * Moves Iterator to the next item in the list.
94    *
95        * @access       public
96    */
97        function next()
98        {
99                $this->current = &$this->associatedGraphSet->getGraphWithOffset(++$this->key);
100                $this->valid=($this->current!=NULL);
101        }
102       
103        /**
104    * Returns the current item.
105    *
106    * @return   mixed
107        * @access       public
108    */
109        function &current()
110        {
111                return $this->current;
112        }
113       
114        /**
115    * Returns the key of the current item.
116    *
117    * @return   integer
118        * @access       public
119    */
120        function key()
121        {
122                return $this->key;
123        }
124}
125?>
Note: See TracBrowser for help on using the repository browser.