zend_iterators.h 3.5 KB

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