diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-17 09:23:09 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-17 09:23:09 +0100 |
commit | cf1cd5c771db918dc73609848780f1b51f1f47f4 (patch) | |
tree | 887c92bd7d62d3f1db4a790766200b26e57e0116 | |
parent | 87bc164a5100b980ff75b5304623938f85eb2c0e (diff) |
fixed ValueIterator to compile on php 5.3 and php 5.4, fixed post increment operator for ValueIterator
-rw-r--r-- | include/valueiterator.h | 42 | ||||
-rw-r--r-- | src/valueiterator.cpp | 25 |
2 files changed, 64 insertions, 3 deletions
diff --git a/include/valueiterator.h b/include/valueiterator.h index 11c412e..037f061 100644 --- a/include/valueiterator.h +++ b/include/valueiterator.h @@ -36,21 +36,59 @@ public: ValueIterator(struct _hashtable *hashtable, bool first); /** + * Copy constructor + * @param that + */ + ValueIterator(const ValueIterator &that); + + /** * Destructor */ virtual ~ValueIterator() {} /** - * Increment position + * Increment position (pre-increment) * @return ValueIterator */ ValueIterator &operator++(); /** - * Decrement position + * Increment position (post-increment) + * @return ValueIterator + */ + ValueIterator operator++(int) + { + // make a copy + ValueIterator copy(*this); + + // increment current object + ++(*this); + + // and return the unchanged original + return copy; + } + + /** + * Decrement position (pre-decrement) * @return ValueIterator */ ValueIterator &operator--(); + + /** + * Increment position (post-decrement) + * @return ValueIterator + */ + ValueIterator operator--(int) + { + // make a copy + ValueIterator copy(*this); + + // decrement current object + --(*this); + + // and return the unchanged original + return copy; + } /** * Compare with other iterator diff --git a/src/valueiterator.cpp b/src/valueiterator.cpp index a40ff81..08520d5 100644 --- a/src/valueiterator.cpp +++ b/src/valueiterator.cpp @@ -91,13 +91,36 @@ ValueIterator &ValueIterator::read() { // zval to read the current key in Value key; - + +#if PHP_VERSION_ID >= 50500 + // read in the current key zend_hash_get_current_key_zval_ex(_table, key._val, &_position); // if the key is set to NULL, it means that the object is not at a valid position if (key.isNull()) return invalidate(); +#else + + // php 5.3 and php 5.4 need a different implementation because the function + // zend_hash_get_current_key_zval_ex is missing in php 5.3, declare variables + // we need for storing the key in + char *string_key; + unsigned int str_len; + unsigned long num_key; + + // get the current key + int type = zend_hash_get_current_key_ex(_table, &string_key, &str_len, &num_key, 0, &_position); + + // if key is not found, the iterator is at an invalid position + if (type == HASH_KEY_NON_EXISTANT) return invalidate(); + + // numeric keys are the easiest ones + if (type == HASH_KEY_NON_EXISTANT) key = (int64_t)num_key; + else key = string_key; + +#endif + // iterator is at a valid position, go fetch the data // this is the variable we need for fetching the data zval **value; |