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