1 /* 2 +----------------------------------------------------------------------+ 3 | Zend Engine | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) | 6 +----------------------------------------------------------------------+ 7 | This source file is subject to version 2.00 of the Zend 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.zend.com/license/2_00.txt. | 11 | If you did not receive a copy of the Zend license and are unable to | 12 | obtain it through the world-wide-web, please send a note to | 13 | license@zend.com so we can mail you a copy immediately. | 14 +----------------------------------------------------------------------+ 15 | Author: Wez Furlong <wez@thebrainroom.com> | 16 | Marcus Boerger <helly@php.net> | 17 +----------------------------------------------------------------------+ 18 */ 19 20 /* $Id$ */ 21 22 /* These iterators were designed to operate within the foreach() 23 * structures provided by the engine, but could be extended for use 24 * with other iterative engine opcodes. 25 * These methods have similar semantics to the zend_hash API functions 26 * with similar names. 27 * */ 28 29 typedef struct _zend_object_iterator zend_object_iterator; 30 31 typedef struct _zend_object_iterator_funcs { 32 /* release all resources associated with this iterator instance */ 33 void (*dtor)(zend_object_iterator *iter); 34 35 /* check for end of iteration (FAILURE or SUCCESS if data is valid) */ 36 int (*valid)(zend_object_iterator *iter); 37 38 /* fetch the item data for the current element */ 39 zval *(*get_current_data)(zend_object_iterator *iter); 40 41 /* fetch the key for the current element (optional, may be NULL). The key 42 * should be written into the provided zval* using the ZVAL_* macros. If 43 * this handler is not provided auto-incrementing integer keys will be 44 * used. */ 45 void (*get_current_key)(zend_object_iterator *iter, zval *key); 46 47 /* step forwards to next element */ 48 void (*move_forward)(zend_object_iterator *iter); 49 50 /* rewind to start of data (optional, may be NULL) */ 51 void (*rewind)(zend_object_iterator *iter); 52 53 /* invalidate current value/key (optional, may be NULL) */ 54 void (*invalidate_current)(zend_object_iterator *iter); 55 } zend_object_iterator_funcs; 56 57 struct _zend_object_iterator { 58 zend_object std; 59 zval data; 60 zend_object_iterator_funcs *funcs; 61 zend_ulong index; /* private to fe_reset/fe_fetch opcodes */ 62 }; 63 64 typedef struct _zend_class_iterator_funcs { 65 zend_object_iterator_funcs *funcs; 66 union _zend_function *zf_new_iterator; 67 union _zend_function *zf_valid; 68 union _zend_function *zf_current; 69 union _zend_function *zf_key; 70 union _zend_function *zf_next; 71 union _zend_function *zf_rewind; 72 } zend_class_iterator_funcs; 73 74 BEGIN_EXTERN_C() 75 /* given a zval, returns stuff that can be used to iterate it. */ 76 ZEND_API zend_object_iterator* zend_iterator_unwrap(zval *array_ptr); 77 78 /* given an iterator, wrap it up as a zval for use by the engine opcodes */ 79 ZEND_API void zend_iterator_init(zend_object_iterator *iter); 80 ZEND_API void zend_iterator_dtor(zend_object_iterator *iter); 81 82 ZEND_API void zend_register_iterator_wrapper(void); 83 END_EXTERN_C() 84 85 /* 86 * Local variables: 87 * tab-width: 4 88 * c-basic-offset: 4 89 * indent-tabs-mode: t 90 * End: 91 * vim600: sw=4 ts=4 fdm=marker 92 * vim<600: sw=4 ts=4 93 */ 94