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    void (*get_current_data)(zend_object_iterator *iter, zval ***data 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    void *data;
59    zend_object_iterator_funcs *funcs;
60    ulong index; /* private to fe_reset/fe_fetch opcodes */
61};
62
63typedef struct _zend_class_iterator_funcs {
64    zend_object_iterator_funcs  *funcs;
65    union _zend_function *zf_new_iterator;
66    union _zend_function *zf_valid;
67    union _zend_function *zf_current;
68    union _zend_function *zf_key;
69    union _zend_function *zf_next;
70    union _zend_function *zf_rewind;
71} zend_class_iterator_funcs;
72
73enum zend_object_iterator_kind {
74    ZEND_ITER_INVALID,
75    ZEND_ITER_PLAIN_ARRAY,
76    ZEND_ITER_PLAIN_OBJECT,
77    ZEND_ITER_OBJECT
78};
79
80BEGIN_EXTERN_C()
81/* given a zval, returns stuff that can be used to iterate it. */
82ZEND_API enum zend_object_iterator_kind zend_iterator_unwrap(zval *array_ptr, zend_object_iterator **iter TSRMLS_DC);
83
84/* given an iterator, wrap it up as a zval for use by the engine opcodes */
85ZEND_API zval *zend_iterator_wrap(zend_object_iterator *iter TSRMLS_DC);
86
87ZEND_API void zend_register_iterator_wrapper(TSRMLS_D);
88END_EXTERN_C()
89
90/*
91 * Local variables:
92 * tab-width: 4
93 * c-basic-offset: 4
94 * indent-tabs-mode: t
95 * End:
96 */
97