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