summaryrefslogtreecommitdiff
path: root/framework/Collections/TQueueIterator.php
diff options
context:
space:
mode:
authorFabio Bas <ctrlaltca@gmail.com>2015-01-20 19:22:34 +0100
committerFabio Bas <ctrlaltca@gmail.com>2015-01-20 19:22:34 +0100
commit169950e09cad0e69a7dcbcdabe7ef86086766483 (patch)
treeadfd97a9f81f77ba424092b22504039cf38def0e /framework/Collections/TQueueIterator.php
parentd45b5615d48bff5373a6cda0728cb26332c3d962 (diff)
One class per file: framework/Collections/
Diffstat (limited to 'framework/Collections/TQueueIterator.php')
-rw-r--r--framework/Collections/TQueueIterator.php99
1 files changed, 99 insertions, 0 deletions
diff --git a/framework/Collections/TQueueIterator.php b/framework/Collections/TQueueIterator.php
new file mode 100644
index 00000000..29a973d1
--- /dev/null
+++ b/framework/Collections/TQueueIterator.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * TQueue, TQueueIterator classes
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2014 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Collections
+ */
+
+/**
+ * TQueueIterator class
+ *
+ * TQueueIterator implements Iterator interface.
+ *
+ * TQueueIterator is used by TQueue. It allows TQueue to return a new iterator
+ * for traversing the items in the queue.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Collections
+ * @since 3.1
+ */
+class TQueueIterator implements Iterator
+{
+ /**
+ * @var array the data to be iterated through
+ */
+ private $_d;
+ /**
+ * @var integer index of the current item
+ */
+ private $_i;
+ /**
+ * @var integer count of the data items
+ */
+ private $_c;
+
+ /**
+ * Constructor.
+ * @param array the data to be iterated through
+ */
+ public function __construct(&$data)
+ {
+ $this->_d=&$data;
+ $this->_i=0;
+ $this->_c=count($this->_d);
+ }
+
+ /**
+ * Rewinds internal array pointer.
+ * This method is required by the interface Iterator.
+ */
+ public function rewind()
+ {
+ $this->_i=0;
+ }
+
+ /**
+ * Returns the key of the current array item.
+ * This method is required by the interface Iterator.
+ * @return integer the key of the current array item
+ */
+ public function key()
+ {
+ return $this->_i;
+ }
+
+ /**
+ * Returns the current array item.
+ * This method is required by the interface Iterator.
+ * @return mixed the current array item
+ */
+ public function current()
+ {
+ return $this->_d[$this->_i];
+ }
+
+ /**
+ * Moves the internal pointer to the next array item.
+ * This method is required by the interface Iterator.
+ */
+ public function next()
+ {
+ $this->_i++;
+ }
+
+ /**
+ * Returns whether there is an item at current position.
+ * This method is required by the interface Iterator.
+ * @return boolean
+ */
+ public function valid()
+ {
+ return $this->_i<$this->_c;
+ }
+} \ No newline at end of file