1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 7 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2017 The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Marcus Boerger <helly@php.net> |
16 +----------------------------------------------------------------------+
17 */
18
19 /* $Id$ */
20
21 #ifndef SPL_ITERATORS_H
22 #define SPL_ITERATORS_H
23
24 #include "php.h"
25 #include "php_spl.h"
26 #if HAVE_PCRE || HAVE_BUNDLED_PCRE
27 #include "ext/pcre/php_pcre.h"
28 #endif
29
30 #define spl_ce_Traversable zend_ce_traversable
31 #define spl_ce_Iterator zend_ce_iterator
32 #define spl_ce_Aggregate zend_ce_aggregate
33 #define spl_ce_ArrayAccess zend_ce_arrayaccess
34 #define spl_ce_Serializable zend_ce_serializable
35
36 extern PHPAPI zend_class_entry *spl_ce_RecursiveIterator;
37 extern PHPAPI zend_class_entry *spl_ce_RecursiveIteratorIterator;
38 extern PHPAPI zend_class_entry *spl_ce_RecursiveTreeIterator;
39 extern PHPAPI zend_class_entry *spl_ce_FilterIterator;
40 extern PHPAPI zend_class_entry *spl_ce_RecursiveFilterIterator;
41 extern PHPAPI zend_class_entry *spl_ce_ParentIterator;
42 extern PHPAPI zend_class_entry *spl_ce_SeekableIterator;
43 extern PHPAPI zend_class_entry *spl_ce_LimitIterator;
44 extern PHPAPI zend_class_entry *spl_ce_CachingIterator;
45 extern PHPAPI zend_class_entry *spl_ce_RecursiveCachingIterator;
46 extern PHPAPI zend_class_entry *spl_ce_OuterIterator;
47 extern PHPAPI zend_class_entry *spl_ce_IteratorIterator;
48 extern PHPAPI zend_class_entry *spl_ce_NoRewindIterator;
49 extern PHPAPI zend_class_entry *spl_ce_InfiniteIterator;
50 extern PHPAPI zend_class_entry *spl_ce_EmptyIterator;
51 extern PHPAPI zend_class_entry *spl_ce_AppendIterator;
52 extern PHPAPI zend_class_entry *spl_ce_RegexIterator;
53 extern PHPAPI zend_class_entry *spl_ce_RecursiveRegexIterator;
54 extern PHPAPI zend_class_entry *spl_ce_Countable;
55 extern PHPAPI zend_class_entry *spl_ce_CallbackFilterIterator;
56 extern PHPAPI zend_class_entry *spl_ce_RecursiveCallbackFilterIterator;
57
58 PHP_MINIT_FUNCTION(spl_iterators);
59
60 PHP_FUNCTION(iterator_to_array);
61 PHP_FUNCTION(iterator_count);
62 PHP_FUNCTION(iterator_apply);
63
64 typedef enum {
65 DIT_Default = 0,
66 DIT_FilterIterator = DIT_Default,
67 DIT_RecursiveFilterIterator = DIT_Default,
68 DIT_ParentIterator = DIT_Default,
69 DIT_LimitIterator,
70 DIT_CachingIterator,
71 DIT_RecursiveCachingIterator,
72 DIT_IteratorIterator,
73 DIT_NoRewindIterator,
74 DIT_InfiniteIterator,
75 DIT_AppendIterator,
76 #if HAVE_PCRE || HAVE_BUNDLED_PCRE
77 DIT_RegexIterator,
78 DIT_RecursiveRegexIterator,
79 #endif
80 DIT_CallbackFilterIterator,
81 DIT_RecursiveCallbackFilterIterator,
82 DIT_Unknown = ~0
83 } dual_it_type;
84
85 typedef enum {
86 RIT_Default = 0,
87 RIT_RecursiveIteratorIterator = RIT_Default,
88 RIT_RecursiveTreeIterator,
89 RIT_Unknow = ~0
90 } recursive_it_it_type;
91
92 enum {
93 /* public */
94 CIT_CALL_TOSTRING = 0x00000001,
95 CIT_TOSTRING_USE_KEY = 0x00000002,
96 CIT_TOSTRING_USE_CURRENT = 0x00000004,
97 CIT_TOSTRING_USE_INNER = 0x00000008,
98 CIT_CATCH_GET_CHILD = 0x00000010,
99 CIT_FULL_CACHE = 0x00000100,
100 CIT_PUBLIC = 0x0000FFFF,
101 /* private */
102 CIT_VALID = 0x00010000,
103 CIT_HAS_CHILDREN = 0x00020000
104 };
105
106 enum {
107 /* public */
108 REGIT_USE_KEY = 0x00000001,
109 REGIT_INVERTED = 0x00000002
110 };
111
112 typedef enum {
113 REGIT_MODE_MATCH,
114 REGIT_MODE_GET_MATCH,
115 REGIT_MODE_ALL_MATCHES,
116 REGIT_MODE_SPLIT,
117 REGIT_MODE_REPLACE,
118 REGIT_MODE_MAX
119 } regex_mode;
120
121 typedef struct _spl_cbfilter_it_intern {
122 zend_fcall_info fci;
123 zend_fcall_info_cache fcc;
124 zend_object *object;
125 } _spl_cbfilter_it_intern;
126
127 typedef struct _spl_dual_it_object {
128 struct {
129 zval zobject;
130 zend_class_entry *ce;
131 zend_object *object;
132 zend_object_iterator *iterator;
133 } inner;
134 struct {
135 zval data;
136 zval key;
137 zend_long pos;
138 } current;
139 dual_it_type dit_type;
140 union {
141 struct {
142 zend_long offset;
143 zend_long count;
144 } limit;
145 struct {
146 zend_long flags; /* CIT_* */
147 zval zstr;
148 zval zchildren;
149 zval zcache;
150 } caching;
151 struct {
152 zval zarrayit;
153 zend_object_iterator *iterator;
154 } append;
155 #if HAVE_PCRE || HAVE_BUNDLED_PCRE
156 struct {
157 zend_long flags;
158 zend_long preg_flags;
159 pcre_cache_entry *pce;
160 zend_string *regex;
161 regex_mode mode;
162 int use_flags;
163 } regex;
164 #endif
165 _spl_cbfilter_it_intern *cbfilter;
166 } u;
167 zend_object std;
168 } spl_dual_it_object;
169
spl_dual_it_from_obj(zend_object * obj)170 static inline spl_dual_it_object *spl_dual_it_from_obj(zend_object *obj) /* {{{ */ {
171 return (spl_dual_it_object*)((char*)(obj) - XtOffsetOf(spl_dual_it_object, std));
172 } /* }}} */
173
174 #define Z_SPLDUAL_IT_P(zv) spl_dual_it_from_obj(Z_OBJ_P((zv)))
175
176 typedef int (*spl_iterator_apply_func_t)(zend_object_iterator *iter, void *puser);
177
178 PHPAPI int spl_iterator_apply(zval *obj, spl_iterator_apply_func_t apply_func, void *puser);
179
180 #endif /* SPL_ITERATORS_H */
181
182 /*
183 * Local Variables:
184 * c-basic-offset: 4
185 * tab-width: 4
186 * End:
187 * vim600: fdm=marker
188 * vim: noet sw=4 ts=4
189 */
190