helly           Sun Oct 31 15:59:39 2004 EDT

  Added files:                 
    /php-src/ext/spl/internal   emptyiterator.inc 
    /php-src/ext/spl/tests      iterator_009.phpt 

  Removed files:               
    /php-src/ext/spl/examples   emptyiterator.inc 

  Modified files:              
    /php-src/ext/spl    php_spl.c spl_functions.c spl_iterators.c 
                        spl_iterators.h 
  Log:
  - Implement EmptyIterator in C
  
  
http://cvs.php.net/diff.php/php-src/ext/spl/php_spl.c?r1=1.32&r2=1.33&ty=u
Index: php-src/ext/spl/php_spl.c
diff -u php-src/ext/spl/php_spl.c:1.32 php-src/ext/spl/php_spl.c:1.33
--- php-src/ext/spl/php_spl.c:1.32      Sun Oct 31 14:49:15 2004
+++ php-src/ext/spl/php_spl.c   Sun Oct 31 15:59:37 2004
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_spl.c,v 1.32 2004/10/31 19:49:15 helly Exp $ */
+/* $Id: php_spl.c,v 1.33 2004/10/31 20:59:37 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
        #include "config.h"
@@ -166,6 +166,7 @@
        SPL_ADD_CLASS(CachingIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(CachingRecursiveIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(DirectoryIterator, z_list, sub, allow, ce_flags); \
+       SPL_ADD_CLASS(EmptyIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(FilterIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(InfiniteIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(IteratorIterator, z_list, sub, allow, ce_flags); \
http://cvs.php.net/diff.php/php-src/ext/spl/spl_functions.c?r1=1.25&r2=1.26&ty=u
Index: php-src/ext/spl/spl_functions.c
diff -u php-src/ext/spl/spl_functions.c:1.25 php-src/ext/spl/spl_functions.c:1.26
--- php-src/ext/spl/spl_functions.c:1.25        Tue Mar  9 11:38:37 2004
+++ php-src/ext/spl/spl_functions.c     Sun Oct 31 15:59:37 2004
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: spl_functions.c,v 1.25 2004/03/09 16:38:37 helly Exp $ */
+/* $Id: spl_functions.c,v 1.26 2004/10/31 20:59:37 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
        #include "config.h"
@@ -59,7 +59,9 @@
        *ppce = zend_register_internal_class(&ce TSRMLS_CC);
 
        /* entries changed by initialize */
-       (*ppce)->create_object = obj_ctor;
+       if (obj_ctor) {
+               (*ppce)->create_object = obj_ctor;
+       }
 }
 /* }}} */
 
http://cvs.php.net/diff.php/php-src/ext/spl/spl_iterators.c?r1=1.47&r2=1.48&ty=u
Index: php-src/ext/spl/spl_iterators.c
diff -u php-src/ext/spl/spl_iterators.c:1.47 php-src/ext/spl/spl_iterators.c:1.48
--- php-src/ext/spl/spl_iterators.c:1.47        Sun Oct 31 14:49:15 2004
+++ php-src/ext/spl/spl_iterators.c     Sun Oct 31 15:59:37 2004
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: spl_iterators.c,v 1.47 2004/10/31 19:49:15 helly Exp $ */
+/* $Id: spl_iterators.c,v 1.48 2004/10/31 20:59:37 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
@@ -48,6 +48,7 @@
 zend_class_entry *spl_ce_IteratorIterator;
 zend_class_entry *spl_ce_NoRewindIterator;
 zend_class_entry *spl_ce_InfiniteIterator;
+zend_class_entry *spl_ce_EmptyIterator;
 
 function_entry spl_funcs_RecursiveIterator[] = {
        SPL_ABSTRACT_ME(RecursiveIterator, hasChildren,  NULL)
@@ -1465,7 +1466,6 @@
                        spl_dual_it_fetch(intern, 0 TSRMLS_CC);
                }
        }
-
 } /* }}} */
 
 static zend_function_entry spl_funcs_InfiniteIterator[] = {
@@ -1473,6 +1473,47 @@
        SPL_ME(InfiniteIterator, next,             NULL, ZEND_ACC_PUBLIC)
 };
 
+/* {{{ proto EmptyIterator::rewind()
+   Does nothing  */
+SPL_METHOD(EmptyIterator, rewind)
+{
+} /* }}} */
+
+/* {{{ proto EmptyIterator::valid()
+   Return false */
+SPL_METHOD(EmptyIterator, valid)
+{
+       RETURN_FALSE;
+} /* }}} */
+
+/* {{{ proto EmptyIterator::key()
+   Throws exception */
+SPL_METHOD(EmptyIterator, key)
+{
+       zend_throw_exception(NULL, "Accessing the key of an EmptyIterator", 0 
TSRMLS_CC);
+} /* }}} */
+
+/* {{{ proto EmptyIterator::current()
+   Throws exception */
+SPL_METHOD(EmptyIterator, current)
+{
+       zend_throw_exception(NULL, "Accessing the value of an EmptyIterator", 0 
TSRMLS_CC);
+} /* }}} */
+
+/* {{{ proto EmptyIterator::next()
+   Does nothing */
+SPL_METHOD(EmptyIterator, next)
+{
+} /* }}} */
+
+static zend_function_entry spl_funcs_EmptyIterator[] = {
+       SPL_ME(EmptyIterator, rewind,           NULL, ZEND_ACC_PUBLIC)
+       SPL_ME(EmptyIterator, valid,            NULL, ZEND_ACC_PUBLIC)
+       SPL_ME(EmptyIterator, key,              NULL, ZEND_ACC_PUBLIC)
+       SPL_ME(EmptyIterator, current,          NULL, ZEND_ACC_PUBLIC)
+       SPL_ME(EmptyIterator, next,             NULL, ZEND_ACC_PUBLIC)
+};
+
 /* {{{ array iterator_to_array(IteratorAggregate it) 
    Copy the iterator into an array */
 PHP_FUNCTION(iterator_to_array)
@@ -1607,6 +1648,9 @@
        REGISTER_SPL_IMPLEMENTS(NoRewindIterator, OuterIterator);
 
        REGISTER_SPL_SUB_CLASS_EX(InfiniteIterator, IteratorIterator, spl_dual_it_new, 
spl_funcs_InfiniteIterator);
+       
+       REGISTER_SPL_STD_CLASS_EX(EmptyIterator, NULL, spl_funcs_EmptyIterator);
+       REGISTER_SPL_ITERATOR(EmptyIterator);
 
        return SUCCESS;
 }
http://cvs.php.net/diff.php/php-src/ext/spl/spl_iterators.h?r1=1.13&r2=1.14&ty=u
Index: php-src/ext/spl/spl_iterators.h
diff -u php-src/ext/spl/spl_iterators.h:1.13 php-src/ext/spl/spl_iterators.h:1.14
--- php-src/ext/spl/spl_iterators.h:1.13        Sun Oct 31 14:49:15 2004
+++ php-src/ext/spl/spl_iterators.h     Sun Oct 31 15:59:37 2004
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: spl_iterators.h,v 1.13 2004/10/31 19:49:15 helly Exp $ */
+/* $Id: spl_iterators.h,v 1.14 2004/10/31 20:59:37 helly Exp $ */
 
 #ifndef SPL_ITERATORS_H
 #define SPL_ITERATORS_H
@@ -36,6 +36,7 @@
 extern zend_class_entry *spl_ce_IteratorIterator;
 extern zend_class_entry *spl_ce_NoRewindIterator;
 extern zend_class_entry *spl_ce_InfiniteIterator;
+extern zend_class_entry *spl_ce_EmptyIterator;
 
 PHP_MINIT_FUNCTION(spl_iterators);
 

http://cvs.php.net/co.php/php-src/ext/spl/internal/emptyiterator.inc?r=1.1&p=1
Index: php-src/ext/spl/internal/emptyiterator.inc
+++ php-src/ext/spl/internal/emptyiterator.inc
<?php

/** @file emptyiterator.inc
 * @ingroup SPL
 * @brief class EmptyIterator
 * @author  Marcus Boerger
 * @date    2003 - 2004
 *
 * SPL - Standard PHP Library
 */

/** @ingroup SPL
 * @brief   An empty Iterator
 * @author  Marcus Boerger
 * @version 1.0
 *
 */
class EmptyIterator implements Iterator
{
        /** No operation.
         * @return void
         */
        function rewind()
        {
                // nothing to do
        }

        /** @return \c false
         */
        function valid()
        {
                return false;
        }

        /** This function must not be called. It throws an exception upon access.
         * @throw Exception
         * @return void
         */
        function current()
        {
                throw new Exception('Accessing the value of an EmptyIterator');
        }

        /** This function must not be called. It throws an exception upon access.
         * @throw Exception
         * @return void
         */
        function key()
        {
                throw new Exception('Accessing the key of an EmptyIterator');
        }

        /** No operation.
         * @return void
         */
        function next()
        {
                // nothing to do
        }
}

?>
http://cvs.php.net/co.php/php-src/ext/spl/tests/iterator_009.phpt?r=1.1&p=1
Index: php-src/ext/spl/tests/iterator_009.phpt
+++ php-src/ext/spl/tests/iterator_009.phpt
--TEST--
SPL: EmptyIterator
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php

class EmptyIteratorEx extends EmptyIterator
{
        function rewind()
        {
                echo __METHOD__ . "\n";
                parent::rewind();
        }
        function valid()
        {
                echo __METHOD__ . "\n";
                return parent::valid();
        }
        function current()
        {
                echo __METHOD__ . "\n";
                return parent::current();
        }
        function key()
        {
                echo __METHOD__ . "\n";
                return parent::key();
        }
        function next()
        {
                echo __METHOD__ . "\n";
                parent::next();
        }
}

foreach (new EmptyIteratorEx() as $v) {
        var_dump($v);
}

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
EmptyIteratorEx::rewind
EmptyIteratorEx::valid
===DONE===

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to