1/*
2   +----------------------------------------------------------------------+
3   | Zend Engine                                                          |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1998-2014 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
29typedef struct _zend_object_iterator zend_object_iterator;
30
31typedef struct _zend_object_iterator_funcs {
32    /* release all resources associated with this iterator instance */
33    void (*dtor)(zend_object_iterator *iter TSRMLS_DC);
34
35    /* check for end of iteration (FAILURE or SUCCESS if data is valid) */
36    int (*valid)(zend_object_iterator *iter TSRMLS_DC);
37
38    /* fetch the item data for the current element */
39    zval *(*get_current_data)(zend_object_iterator *iter TSRMLS_DC);
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 TSRMLS_DC);
46
47    /* step forwards to next element */
48    void (*move_forward)(zend_object_iterator *iter TSRMLS_DC);
49
50    /* rewind to start of data (optional, may be NULL) */
51    void (*rewind)(zend_object_iterator *iter TSRMLS_DC);
52
53    /* invalidate current value/key (optional, may be NULL) */
54    void (*invalidate_current)(zend_object_iterator *iter TSRMLS_DC);
55} zend_object_iterator_funcs;
56
57struct _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
64typedef 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
74enum zend_object_iterator_kind {
75    ZEND_ITER_INVALID,
76    ZEND_ITER_PLAIN_ARRAY,
77    ZEND_ITER_PLAIN_OBJECT,
78    ZEND_ITER_OBJECT
79};
80
81BEGIN_EXTERN_C()
82/* given a zval, returns stuff that can be used to iterate it. */
83ZEND_API enum zend_object_iterator_kind zend_iterator_unwrap(zval *array_ptr, zend_object_iterator **iter TSRMLS_DC);
84
85/* given an iterator, wrap it up as a zval for use by the engine opcodes */
86ZEND_API void zend_iterator_init(zend_object_iterator *iter TSRMLS_DC);
87ZEND_API void zend_iterator_dtor(zend_object_iterator *iter TSRMLS_DC);
88
89ZEND_API void zend_register_iterator_wrapper(TSRMLS_D);
90END_EXTERN_C()
91
92/*
93 * Local variables:
94 * tab-width: 4
95 * c-basic-offset: 4
96 * indent-tabs-mode: t
97 * End:
98 */
99