1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 7 |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | http://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Vadim Savchuk <vsavchuk@productengine.com> |
14 | Dmitry Lakhtyuk <dlakhtyuk@productengine.com> |
15 +----------------------------------------------------------------------+
16 */
17
18 #ifndef INTL_COMMON_ENUM_H
19 #define INTL_COMMON_ENUM_H
20
21 #include <unicode/umachine.h>
22 #ifdef __cplusplus
23 #include <unicode/strenum.h>
24 extern "C" {
25 #include <math.h>
26 #endif
27 #include <php.h>
28 #include "../intl_error.h"
29 #include "../intl_data.h"
30 #ifdef __cplusplus
31 }
32 #endif
33
34 #define INTLITERATOR_ERROR(ii) (ii)->err
35 #define INTLITERATOR_ERROR_P(ii) &(INTLITERATOR_ERROR(ii))
36
37 #define INTLITERATOR_ERROR_CODE(ii) INTL_ERROR_CODE(INTLITERATOR_ERROR(ii))
38 #define INTLITERATOR_ERROR_CODE_P(ii) &(INTL_ERROR_CODE(INTLITERATOR_ERROR(ii)))
39
40 #define INTLITERATOR_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(IntlIterator, ii)
41 #define INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_ITERATOR, ii)
42 #define INTLITERATOR_METHOD_FETCH_OBJECT\
43 object = getThis(); \
44 INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; \
45 if (ii->iterator == NULL) { \
46 intl_errors_set(&ii->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlIterator", 0); \
47 RETURN_FALSE; \
48 }
49
50 typedef struct {
51 intl_error err;
52 zend_object_iterator *iterator;
53 zend_object zo;
54 } IntlIterator_object;
55
56
php_intl_iterator_fetch_object(zend_object * obj)57 static inline IntlIterator_object *php_intl_iterator_fetch_object(zend_object *obj) {
58 return (IntlIterator_object *)((char*)(obj) - XtOffsetOf(IntlIterator_object, zo));
59 }
60 #define Z_INTL_ITERATOR_P(zv) php_intl_iterator_fetch_object(Z_OBJ_P(zv))
61
62 typedef struct {
63 zend_object_iterator zoi;
64 zval current;
65 zval wrapping_obj;
66 void (*destroy_it)(zend_object_iterator *iterator);
67 } zoi_with_current;
68
69 extern zend_class_entry *IntlIterator_ce_ptr;
70 extern zend_object_handlers IntlIterator_handlers;
71
72 U_CFUNC void zoi_with_current_dtor(zend_object_iterator *iter);
73 U_CFUNC int zoi_with_current_valid(zend_object_iterator *iter);
74 U_CFUNC zval *zoi_with_current_get_current_data(zend_object_iterator *iter);
75 U_CFUNC void zoi_with_current_invalidate_current(zend_object_iterator *iter);
76
77 #ifdef __cplusplus
78 using icu::StringEnumeration;
79 U_CFUNC void IntlIterator_from_StringEnumeration(StringEnumeration *se, zval *object);
80 #endif
81
82 U_CFUNC void intl_register_IntlIterator_class(void);
83
84 #endif // INTL_COMMON_ENUM_H
85