Back to index

php5  5.3.10
zend_iterators.h
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | Zend Engine                                                          |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1998-2012 Zend Technologies Ltd. (http://www.zend.com) |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 2.00 of the Zend license,     |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.zend.com/license/2_00.txt.                                |
00011    | If you did not receive a copy of the Zend license and are unable to  |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@zend.com so we can mail you a copy immediately.              |
00014    +----------------------------------------------------------------------+
00015    | Author: Wez Furlong <wez@thebrainroom.com>                           |
00016    |         Marcus Boerger <helly@php.net>                               |
00017    +----------------------------------------------------------------------+
00018 */
00019 
00020 /* $Id: zend_iterators.h 321634 2012-01-01 13:15:04Z felipe $ */
00021 
00022 /* These iterators were designed to operate within the foreach()
00023  * structures provided by the engine, but could be extended for use
00024  * with other iterative engine opcodes.
00025  * These methods have similar semantics to the zend_hash API functions
00026  * with similar names.
00027  * */
00028 
00029 typedef struct _zend_object_iterator zend_object_iterator;
00030 
00031 typedef struct _zend_object_iterator_funcs {
00032        /* release all resources associated with this iterator instance */
00033        void (*dtor)(zend_object_iterator *iter TSRMLS_DC);
00034 
00035        /* check for end of iteration (FAILURE or SUCCESS if data is valid) */
00036        int (*valid)(zend_object_iterator *iter TSRMLS_DC);
00037 
00038        /* fetch the item data for the current element */
00039        void (*get_current_data)(zend_object_iterator *iter, zval ***data TSRMLS_DC);
00040 
00041        /* fetch the key for the current element (return HASH_KEY_IS_STRING or HASH_KEY_IS_LONG) (optional, may be NULL) */
00042        int (*get_current_key)(zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC);
00043 
00044        /* step forwards to next element */
00045        void (*move_forward)(zend_object_iterator *iter TSRMLS_DC);
00046 
00047        /* rewind to start of data (optional, may be NULL) */
00048        void (*rewind)(zend_object_iterator *iter TSRMLS_DC);
00049 
00050        /* invalidate current value/key (optional, may be NULL) */
00051        void (*invalidate_current)(zend_object_iterator *iter TSRMLS_DC);
00052 } zend_object_iterator_funcs;
00053 
00054 struct _zend_object_iterator {
00055        void *data;
00056        zend_object_iterator_funcs *funcs;
00057        ulong index; /* private to fe_reset/fe_fetch opcodes */
00058 };
00059 
00060 typedef struct _zend_class_iterator_funcs {
00061        zend_object_iterator_funcs  *funcs;
00062        union _zend_function *zf_new_iterator;
00063        union _zend_function *zf_valid;
00064        union _zend_function *zf_current;
00065        union _zend_function *zf_key;
00066        union _zend_function *zf_next;
00067        union _zend_function *zf_rewind;
00068 } zend_class_iterator_funcs;
00069 
00070 enum zend_object_iterator_kind {
00071        ZEND_ITER_INVALID,
00072        ZEND_ITER_PLAIN_ARRAY,
00073        ZEND_ITER_PLAIN_OBJECT,
00074        ZEND_ITER_OBJECT
00075 };
00076 
00077 BEGIN_EXTERN_C()
00078 /* given a zval, returns stuff that can be used to iterate it. */
00079 ZEND_API enum zend_object_iterator_kind zend_iterator_unwrap(zval *array_ptr, zend_object_iterator **iter TSRMLS_DC);
00080 
00081 /* given an iterator, wrap it up as a zval for use by the engine opcodes */
00082 ZEND_API zval *zend_iterator_wrap(zend_object_iterator *iter TSRMLS_DC);
00083 
00084 ZEND_API void zend_register_iterator_wrapper(TSRMLS_D);
00085 END_EXTERN_C()
00086 
00087 /*
00088  * Local variables:
00089  * tab-width: 4
00090  * c-basic-offset: 4
00091  * indent-tabs-mode: t
00092  * End:
00093  */