cvs: pecl /spl/examples cachingiterator.inc cachingrecursiveiterator.inc directorygraphiterator.inc directorytreeiterator.inc

From: Date: Sun, 07 Dec 2003 15:03:11 +0000
Subject: cvs: pecl /spl/examples cachingiterator.inc cachingrecursiveiterator.inc directorygraphiterator.inc directorytreeiterator.inc
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-561@lists.php.net to get a copy of this message
helly Sun Dec 7 10:03:11 2003 EDT Modified files: /pecl/spl/examples cachingiterator.inc cachingrecursiveiterator.inc directorygraphiterator.inc directorytreeiterator.inc Log: Use a single bit field for the flags here Index: pecl/spl/examples/cachingiterator.inc diff -u pecl/spl/examples/cachingiterator.inc:1.4 pecl/spl/examples/cachingiterator.inc:1.5 --- pecl/spl/examples/cachingiterator.inc:1.4 Sat Dec 6 14:03:17 2003 +++ pecl/spl/examples/cachingiterator.inc Sun Dec 7 10:03:11 2003 @@ -1,5 +1,8 @@ <?php +define('CIT_GET_STR_VALUE', 1); +define('CIT_CATCH_GET_CHILD', 2); + class CachingIterator { protected $it; @@ -9,10 +12,10 @@ protected $strValue; protected $getStrVal; - function __construct(Iterator $it, $getStrVal = true) + function __construct(Iterator $it, $flags = CIT_GET_STR_VALUE) { $this->it = $it; - $this->getStrVal = (boolean)$getStrVal; + $this->flags = $flags & (CIT_GET_STR_VALUE|CIT_CATCH_GET_CHILD); } function rewind() @@ -26,7 +29,7 @@ if ($this->more = $this->it->hasMore()) { $this->current = $this->it->current(); $this->key = $this->it->key(); - if ($this->getStrVal) { + if ($this->flags & CIT_GET_STR_VALUE) { if (is_object($this->current)) { $this->strValue = $this->current->__toString(); } else { @@ -36,7 +39,7 @@ } else { $this->current = NULL; $this->key = NULL; - $this->strValue = ''; + $this->strValue = NULL; } $this->it->next(); } @@ -68,7 +71,7 @@ function __toString() { - if (!$this->getStrVal) { + if (!$this->flags & CIT_GET_STR_VALUE) { throw new exception('CachingIterator does not fetch string value (see CachingIterator::__construct)'); } return $this->strValue; Index: pecl/spl/examples/cachingrecursiveiterator.inc diff -u pecl/spl/examples/cachingrecursiveiterator.inc:1.4 pecl/spl/examples/cachingrecursiveiterator.inc:1.5 --- pecl/spl/examples/cachingrecursiveiterator.inc:1.4 Sun Dec 7 08:21:47 2003 +++ pecl/spl/examples/cachingrecursiveiterator.inc Sun Dec 7 10:03:11 2003 @@ -6,23 +6,22 @@ protected $getChildren; protected $catch_get_child; - function __construct(RecursiveIterator $it, $getStrVal = true, $catch_get_child = false) + function __construct(RecursiveIterator $it, $flags = CIT_GET_STR_VALUE) { - $this->catch_get_child = $catch_get_child; - parent::__construct($it, $getStrVal); + parent::__construct($it, $flags); } function next() { if ($this->hasChildren = $this->it->hasChildren()) { try { - //$this->getChildren = new CachingRecursiveIterator($this->it->getChildren(), $this->getStrVal, $this->catch_get_child); + //$this->getChildren = new CachingRecursiveIterator($this->it->getChildren(), $this->flags); // workaround memleaks... $child = $this->it->getChildren(); - $this->getChildren = new CachingRecursiveIterator($child, $this->getStrVal, $this->catch_get_child); + $this->getChildren = new CachingRecursiveIterator($child, $this->flags); } catch(Exception $e) { - if (!$this->catch_get_child) { + if (!$this->flags & CIT_CATCH_GET_CHILD) { throw $e; } $this->hasChildren = false; Index: pecl/spl/examples/directorygraphiterator.inc diff -u pecl/spl/examples/directorygraphiterator.inc:1.2 pecl/spl/examples/directorygraphiterator.inc:1.3 --- pecl/spl/examples/directorygraphiterator.inc:1.2 Sun Dec 7 08:21:47 2003 +++ pecl/spl/examples/directorygraphiterator.inc Sun Dec 7 10:03:11 2003 @@ -4,7 +4,7 @@ { function __construct($path) { - RecursiveIteratorIterator::__construct(new CachingRecursiveIterator(new ParentIterator(new RecursiveDirectoryIterator($path)), true, true), 1); + RecursiveIteratorIterator::__construct(new CachingRecursiveIterator(new ParentIterator(new RecursiveDirectoryIterator($path)), CIT_GET_STR_VALUE|CIT_CATCH_GET_CHILD), 1); } } Index: pecl/spl/examples/directorytreeiterator.inc diff -u pecl/spl/examples/directorytreeiterator.inc:1.6 pecl/spl/examples/directorytreeiterator.inc:1.7 --- pecl/spl/examples/directorytreeiterator.inc:1.6 Sun Dec 7 08:21:47 2003 +++ pecl/spl/examples/directorytreeiterator.inc Sun Dec 7 10:03:11 2003 @@ -4,7 +4,7 @@ { function __construct($path) { - parent::__construct(new CachingRecursiveIterator(new RecursiveDirectoryIterator($path), true, true), 1); + parent::__construct(new CachingRecursiveIterator(new RecursiveDirectoryIterator($path), CIT_GET_STR_VALUE|CIT_CATCH_GET_CHILD), 1); } function current()

« previous php.pecl.cvs (#561) next »