From b86672080ecd25c8a3103c58cd68812902728631 Mon Sep 17 00:00:00 2001 From: valmat Date: Sun, 9 Mar 2014 01:30:54 +0600 Subject: issue #23 implemented --- src/value.cpp | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 112 insertions(+), 6 deletions(-) (limited to 'src/value.cpp') diff --git a/src/value.cpp b/src/value.cpp index 7b1a931..7af94fa 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -1411,17 +1411,120 @@ int Value::size() const */ std::map Value::mapValue() const { + // result variable + std::map result; + // check type - if (isArray()) + if (isArray() || isObject()) { - // result variable - std::map result; - // @todo loop through the zval key/value pairs, and return a map + + // loop through the zval key/value pairs, and return a map + + zval **value; + char *key; + unsigned long ind; - // done - return result; + + // get access to the internal hash table of _val + // Zend/zend_API.h 723 + //HashTable *arr = HASH_OF(_val); + HashTable *arr = isArray() ? Z_ARRVAL_P(_val) : Z_OBJ_HT_P(_val)->get_properties((_val) TSRMLS_CC); + //#define HASH_OF(p) (Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties((p) TSRMLS_CC) : NULL))) + + // similarly php: reset($array): + // Maybe make it optional? + // If the following line to remove, then repeated calling the Value::mapValue() will return an empty map + zend_hash_internal_pointer_reset(arr); + + //HashPosition pos; + + if(zend_hash_has_more_elements(arr) == FAILURE) { + return result; + } + + //while( zend_hash_has_more_elements_ex(arr, pos) != FAILURE ) { + //while( zend_hash_has_more_elements(arr) != FAILURE ) { + //zend_hash_get_current_key_ex(const HashTable *ht, char **str_index, uint *str_length, ulong *num_index, zend_bool duplicate, HashPosition *pos); + /* + #define HASH_KEY_IS_STRING 1 + #define HASH_KEY_IS_LONG 2 + #define HASH_KEY_NON_EXISTENT 3 + */ + uint r; + //while( (r = zend_hash_get_current_key_type(arr)) != HASH_KEY_NON_EXISTENT ) { + while( (r = zend_hash_get_current_key(arr, &key, &ind, 0)) != HASH_KEY_NON_EXISTENT ) { + + //zend_hash_get_current_key(arr, &key, &ind, 0); + zend_hash_get_current_data(arr, (void **) &value); + + + + if(HASH_KEY_IS_LONG == r) { + //result[std::to_string(ind)] = Value(*value); + //std::cout << "std::to_string(" < Value::mapValue() const // return an empty map return std::map(); } + */ + // done + return result; } /** -- cgit v1.2.3