From: Marcus Boerger Date: Fri, 29 Oct 2004 20:12:57 +0000 (+0000) Subject: - Implement OuterIterator in C X-Git-Tag: RELEASE_0_2~807 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=208a97a221055eba43430139fef0d02875e3ffbd;p=php - Implement OuterIterator in C --- diff --git a/ext/spl/internal/cachingiterator.inc b/ext/spl/internal/cachingiterator.inc index ac2476f1f8..a474131b5c 100755 --- a/ext/spl/internal/cachingiterator.inc +++ b/ext/spl/internal/cachingiterator.inc @@ -3,7 +3,7 @@ define('CIT_CALL_TOSTRING', 1); define('CIT_CATCH_GET_CHILD', 2); -class CachingIterator +class CachingIterator implements OuterIterator { protected $it; protected $current; @@ -76,6 +76,11 @@ class CachingIterator } return $this->strValue; } + + function getInnerIterator() + { + return $this->it; + } } ?> \ No newline at end of file diff --git a/ext/spl/internal/filteriterator.inc b/ext/spl/internal/filteriterator.inc index 7040c4bef9..73c993af84 100755 --- a/ext/spl/internal/filteriterator.inc +++ b/ext/spl/internal/filteriterator.inc @@ -9,7 +9,7 @@ * you can put an iterator into the constructor and the instance will only * return selected (accepted) elements. */ -abstract class FilterIterator implements Iterator +abstract class FilterIterator implements OuterIterator { protected $it; @@ -92,6 +92,14 @@ abstract class FilterIterator implements Iterator protected function __clone() { // disallow clone } + + /** + * @return The inner iterator + */ + function getInnerIterator() + { + return $this->it; + } } ?> \ No newline at end of file diff --git a/ext/spl/internal/limititerator.inc b/ext/spl/internal/limititerator.inc index 9a87f6874f..4625ae9f22 100755 --- a/ext/spl/internal/limititerator.inc +++ b/ext/spl/internal/limititerator.inc @@ -1,6 +1,6 @@ pos; } + + /** + * @return The inner iterator + */ + function getInnerIterator() + { + return $this->it; + } } ?> \ No newline at end of file diff --git a/ext/spl/examples/outeriterator.inc b/ext/spl/internal/outeriterator.inc similarity index 100% rename from ext/spl/examples/outeriterator.inc rename to ext/spl/internal/outeriterator.inc diff --git a/ext/spl/internal/recursiveiteratoriterator.inc b/ext/spl/internal/recursiveiteratoriterator.inc index 05e31df464..a04d860008 100755 --- a/ext/spl/internal/recursiveiteratoriterator.inc +++ b/ext/spl/internal/recursiveiteratoriterator.inc @@ -6,7 +6,7 @@ * @version 1.0 * */ -class RecursiveIteratorIterator implements Iterator +class RecursiveIteratorIterator implements OuterIterator { protected $ait = array(); protected $count = 0; @@ -92,6 +92,14 @@ class RecursiveIteratorIterator implements Iterator return @$this->ait[$level]; } + /** + * @return The inner iterator + */ + function getInnerIterator() + { + return $this->it; + } + function getDepth() { return $this->level; diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index c33a49041b..d8a298676c 100755 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -168,6 +168,7 @@ PHP_FUNCTION(class_implements) SPL_ADD_CLASS(DirectoryIterator, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(FilterIterator, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(LimitIterator, z_list, sub, allow, ce_flags); \ + SPL_ADD_CLASS(OuterIterator, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(ParentIterator, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(RecursiveDirectoryIterator, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(RecursiveIterator, z_list, sub, allow, ce_flags); \ diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 2b911559c6..cd80c3b067 100755 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -44,6 +44,7 @@ zend_class_entry *spl_ce_SeekableIterator; zend_class_entry *spl_ce_LimitIterator; zend_class_entry *spl_ce_CachingIterator; zend_class_entry *spl_ce_CachingRecursiveIterator; +zend_class_entry *spl_ce_OuterIterator; function_entry spl_funcs_RecursiveIterator[] = { SPL_ABSTRACT_ME(RecursiveIterator, hasChildren, NULL) @@ -59,6 +60,7 @@ SPL_METHOD(RecursiveIteratorIterator, current); SPL_METHOD(RecursiveIteratorIterator, next); SPL_METHOD(RecursiveIteratorIterator, getDepth); SPL_METHOD(RecursiveIteratorIterator, getSubIterator); +SPL_METHOD(RecursiveIteratorIterator, getInnerIterator); static ZEND_BEGIN_ARG_INFO(arginfo_recursive_it___construct, 0) @@ -80,6 +82,7 @@ static zend_function_entry spl_funcs_RecursiveIteratorIterator[] = { SPL_ME(RecursiveIteratorIterator, next, NULL, ZEND_ACC_PUBLIC) SPL_ME(RecursiveIteratorIterator, getDepth, NULL, ZEND_ACC_PUBLIC) SPL_ME(RecursiveIteratorIterator, getSubIterator,arginfo_recursive_it_getSubIterator, ZEND_ACC_PUBLIC) + SPL_ME(RecursiveIteratorIterator, getInnerIterator,NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; @@ -414,8 +417,8 @@ SPL_METHOD(RecursiveIteratorIterator, getDepth) RETURN_LONG(object->level); } /* }}} */ -/* {{{ proto RecursiveIterator RecursiveIteratorIterator::getSubIterator() - The current active sub iterator */ +/* {{{ proto RecursiveIterator RecursiveIteratorIterator::getSubIterator([int level]) + The current active sub iterator or the iterator at specified level */ SPL_METHOD(RecursiveIteratorIterator, getSubIterator) { spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); @@ -430,6 +433,16 @@ SPL_METHOD(RecursiveIteratorIterator, getSubIterator) RETURN_ZVAL(object->iterators[level].zobject, 1, 0); } /* }}} */ +/* {{{ proto RecursiveIterator RecursiveIteratorIterator::getInnerIterator() + The current active sub iterator */ +SPL_METHOD(RecursiveIteratorIterator, getInnerIterator) +{ + spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + long level = object->level; + + RETURN_ZVAL(object->iterators[level].zobject, 1, 0); +} /* }}} */ + /* {{{ spl_RecursiveIteratorIterator_dtor */ static void spl_RecursiveIteratorIterator_free_storage(void *_object TSRMLS_DC) { @@ -1386,6 +1399,11 @@ PHP_FUNCTION(iterator_count) } /* }}} */ +static zend_function_entry spl_funcs_OuterIterator[] = { + SPL_ABSTRACT_ME(OuterIterator, getInnerIterator, NULL) + {NULL, NULL, NULL} +}; + /* {{{ PHP_MINIT_FUNCTION(spl_iterators) */ PHP_MINIT_FUNCTION(spl_iterators) @@ -1432,7 +1450,15 @@ PHP_MINIT_FUNCTION(spl_iterators) REGISTER_SPL_SUB_CLASS_EX(CachingRecursiveIterator, CachingIterator, spl_dual_it_new, spl_funcs_CachingRecursiveIterator); REGISTER_SPL_IMPLEMENTS(CachingRecursiveIterator, RecursiveIterator); - + + REGISTER_SPL_INTERFACE(OuterIterator); + REGISTER_SPL_ITERATOR(OuterIterator); + + REGISTER_SPL_IMPLEMENTS(RecursiveIteratorIterator, OuterIterator); + REGISTER_SPL_IMPLEMENTS(CachingIterator, OuterIterator); + REGISTER_SPL_IMPLEMENTS(FilterIterator, OuterIterator); + REGISTER_SPL_IMPLEMENTS(LimitIterator, OuterIterator); + return SUCCESS; } /* }}} */ diff --git a/ext/spl/spl_iterators.h b/ext/spl/spl_iterators.h index cdec65c047..3459b0f94b 100755 --- a/ext/spl/spl_iterators.h +++ b/ext/spl/spl_iterators.h @@ -32,6 +32,7 @@ extern zend_class_entry *spl_ce_SeekableIterator; extern zend_class_entry *spl_ce_LimitIterator; extern zend_class_entry *spl_ce_CachingIterator; extern zend_class_entry *spl_ce_CachingRecursiveIterator; +extern zend_class_entry *spl_ce_OuterIterator; PHP_MINIT_FUNCTION(spl_iterators);