zend_iterators.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998-2016 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. /* $Id$ */
  20. /* These iterators were designed to operate within the foreach()
  21. * structures provided by the engine, but could be extended for use
  22. * with other iterative engine opcodes.
  23. * These methods have similar semantics to the zend_hash API functions
  24. * with similar names.
  25. * */
  26. typedef struct _zend_object_iterator zend_object_iterator;
  27. typedef struct _zend_object_iterator_funcs {
  28. /* release all resources associated with this iterator instance */
  29. void (*dtor)(zend_object_iterator *iter TSRMLS_DC);
  30. /* check for end of iteration (FAILURE or SUCCESS if data is valid) */
  31. int (*valid)(zend_object_iterator *iter TSRMLS_DC);
  32. /* fetch the item data for the current element */
  33. void (*get_current_data)(zend_object_iterator *iter, zval ***data TSRMLS_DC);
  34. /* fetch the key for the current element (optional, may be NULL). The key
  35. * should be written into the provided zval* using the ZVAL_* macros. If
  36. * this handler is not provided auto-incrementing integer keys will be
  37. * used. */
  38. void (*get_current_key)(zend_object_iterator *iter, zval *key TSRMLS_DC);
  39. /* step forwards to next element */
  40. void (*move_forward)(zend_object_iterator *iter TSRMLS_DC);
  41. /* rewind to start of data (optional, may be NULL) */
  42. void (*rewind)(zend_object_iterator *iter TSRMLS_DC);
  43. /* invalidate current value/key (optional, may be NULL) */
  44. void (*invalidate_current)(zend_object_iterator *iter TSRMLS_DC);
  45. } zend_object_iterator_funcs;
  46. struct _zend_object_iterator {
  47. void *data;
  48. zend_object_iterator_funcs *funcs;
  49. ulong index; /* private to fe_reset/fe_fetch opcodes */
  50. };
  51. typedef struct _zend_class_iterator_funcs {
  52. zend_object_iterator_funcs *funcs;
  53. union _zend_function *zf_new_iterator;
  54. union _zend_function *zf_valid;
  55. union _zend_function *zf_current;
  56. union _zend_function *zf_key;
  57. union _zend_function *zf_next;
  58. union _zend_function *zf_rewind;
  59. } zend_class_iterator_funcs;
  60. enum zend_object_iterator_kind {
  61. ZEND_ITER_INVALID,
  62. ZEND_ITER_PLAIN_ARRAY,
  63. ZEND_ITER_PLAIN_OBJECT,
  64. ZEND_ITER_OBJECT
  65. };
  66. BEGIN_EXTERN_C()
  67. /* given a zval, returns stuff that can be used to iterate it. */
  68. ZEND_API enum zend_object_iterator_kind zend_iterator_unwrap(zval *array_ptr, zend_object_iterator **iter TSRMLS_DC);
  69. /* given an iterator, wrap it up as a zval for use by the engine opcodes */
  70. ZEND_API zval *zend_iterator_wrap(zend_object_iterator *iter TSRMLS_DC);
  71. ZEND_API void zend_register_iterator_wrapper(TSRMLS_D);
  72. END_EXTERN_C()
  73. /*
  74. * Local variables:
  75. * tab-width: 4
  76. * c-basic-offset: 4
  77. * indent-tabs-mode: t
  78. * End:
  79. */