zend_iterators.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 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. /* Expose owned values to GC.
  45. * This has the same semantics as the corresponding object handler. */
  46. HashTable *(*get_gc)(zend_object_iterator *iter, zval **table, int *n);
  47. } zend_object_iterator_funcs;
  48. struct _zend_object_iterator {
  49. zend_object std;
  50. zval data;
  51. const zend_object_iterator_funcs *funcs;
  52. zend_ulong index; /* private to fe_reset/fe_fetch opcodes */
  53. };
  54. typedef struct _zend_class_iterator_funcs {
  55. zend_function *zf_new_iterator;
  56. zend_function *zf_valid;
  57. zend_function *zf_current;
  58. zend_function *zf_key;
  59. zend_function *zf_next;
  60. zend_function *zf_rewind;
  61. } zend_class_iterator_funcs;
  62. BEGIN_EXTERN_C()
  63. /* given a zval, returns stuff that can be used to iterate it. */
  64. ZEND_API zend_object_iterator* zend_iterator_unwrap(zval *array_ptr);
  65. /* given an iterator, wrap it up as a zval for use by the engine opcodes */
  66. ZEND_API void zend_iterator_init(zend_object_iterator *iter);
  67. ZEND_API void zend_iterator_dtor(zend_object_iterator *iter);
  68. ZEND_API void zend_register_iterator_wrapper(void);
  69. END_EXTERN_C()