xref: /ext-ds/src/php/objects/php_map.h (revision 8595b29f)
1 #ifndef PHP_DS_MAP_H
2 #define PHP_DS_MAP_H
3 
4 #include "../../ds/ds_map.h"
5 
6 typedef struct _php_ds_map_t {
7     ds_map_t    *map;
8     zend_object  std;
9 } php_ds_map_t;
10 
php_ds_map_fetch_object(zend_object * obj)11 static inline php_ds_map_t *php_ds_map_fetch_object(zend_object *obj) {
12 	return (php_ds_map_t *)((char*)(obj) - XtOffsetOf(php_ds_map_t, std));
13 }
14 
15 #define Z_DS_MAP(z)   (php_ds_map_fetch_object(Z_OBJ(z))->map)
16 #define Z_DS_MAP_P(z) Z_DS_MAP(*z)
17 #define THIS_DS_MAP() Z_DS_MAP_P(getThis())
18 
19 #define ZVAL_DS_MAP(z, map) ZVAL_OBJ(z, php_ds_map_create_object_ex(map))
20 
21 #define RETURN_DS_MAP(m)                    \
22 do {                                        \
23     ds_map_t *_m = m;                       \
24     if (_m) {                               \
25         ZVAL_DS_MAP(return_value, _m);      \
26     } else {                                \
27         ZVAL_NULL(return_value);            \
28     }                                       \
29     return;                                 \
30 } while(0)
31 
32 zend_object *php_ds_map_create_object_ex(ds_map_t *map);
33 zend_object *php_ds_map_create_object(zend_class_entry *ce);
34 zend_object *php_ds_map_create_clone(ds_map_t *map);
35 
36 zval      *ds_map_pairs(ds_map_t *map);
37 HashTable *ds_map_pairs_to_php_hashtable(ds_map_t *map);
38 
39 PHP_DS_SERIALIZE_FUNCIONS(php_ds_map);
40 
41 #endif
42