1
1
<?php
2
2
3
+ /** @file cachingiterator.inc
4
+ * @ingroup Internal
5
+ * @brief class CachingIterator
6
+ * @author Marcus Boerger
7
+ * @date 2003 - 2004
8
+ *
9
+ * SPL - Standard PHP Library
10
+ */
11
+
3
12
define ('CIT_CALL_TOSTRING ' , 1 );
4
13
define ('CIT_CATCH_GET_CHILD ' , 2 );
5
14
15
+ /**
16
+ * @brief Cached Iteration over another Iterator
17
+ * @author Marcus Boerger
18
+ * @version 1.1
19
+ *
20
+ */
6
21
class CachingIterator implements OuterIterator
7
22
{
8
23
protected $ it ;
@@ -11,19 +26,29 @@ class CachingIterator implements OuterIterator
11
26
protected $ valid ;
12
27
protected $ strValue ;
13
28
29
+ /** Construct from another iterator
30
+ *
31
+ * @param it Iterator to cache
32
+ * @param flags Bitmask:
33
+ * - CIT_CALL_TOSTRING (whether to call __toString() for every element)
34
+ */
14
35
function __construct (Iterator $ it , $ flags = CIT_CALL_TOSTRING )
15
36
{
16
37
$ this ->it = $ it ;
17
38
$ this ->flags = $ flags & (CIT_CALL_TOSTRING |CIT_CATCH_GET_CHILD );
18
39
$ this ->next ();
19
40
}
20
41
42
+ /** Rewind the Iterator
43
+ */
21
44
function rewind ()
22
45
{
23
46
$ this ->it ->rewind ();
24
47
$ this ->next ();
25
48
}
26
49
50
+ /** Forward to the next element
51
+ */
27
52
function next ()
28
53
{
29
54
if ($ this ->valid = $ this ->it ->valid ()) {
@@ -44,31 +69,45 @@ class CachingIterator implements OuterIterator
44
69
$ this ->it ->next ();
45
70
}
46
71
72
+ /** @return whether teh iterator is valid
73
+ */
47
74
function valid ()
48
75
{
49
76
return $ this ->valid ;
50
77
}
51
78
79
+ /** @return whether there is one more element
80
+ */
52
81
function hasNext ()
53
82
{
54
83
return $ this ->it ->valid ();
55
84
}
56
85
86
+ /** @return the current element
87
+ */
57
88
function current ()
58
89
{
59
90
return $ this ->current ;
60
91
}
61
92
93
+ /** @return the current key
94
+ */
62
95
function key ()
63
96
{
64
97
return $ this ->key ;
65
98
}
66
99
100
+ /** Aggregate the inner iterator
101
+ */
67
102
function __call ($ func , $ params )
68
103
{
69
104
return call_user_func_array (array ($ this ->it , $ func ), $ params );
70
105
}
71
106
107
+ /** @return the string represenatation that was generated for the current
108
+ * element
109
+ * @throw exception when CIT_CALL_TOSTRING was not specified in constructor
110
+ */
72
111
function __toString ()
73
112
{
74
113
if (!$ this ->flags & CIT_CALL_TOSTRING ) {
@@ -77,6 +116,9 @@ class CachingIterator implements OuterIterator
77
116
return $ this ->strValue ;
78
117
}
79
118
119
+ /**
120
+ * @return The inner iterator
121
+ */
80
122
function getInnerIterator ()
81
123
{
82
124
return $ this ->it ;
0 commit comments