Source for file TList.php

Documentation is available at TList.php

  1. <?php
  2. /**
  3.  * Defines TList class.
  4.  *
  5.  * @package recAnalyst
  6.  * @version $Id: TList.php 24 2009-05-11 12:51:54Z biegleux $
  7.  * @author biegleux <biegleux[at]gmail[dot]com>
  8.  * @copyright copyright (c) 2008-2009 biegleux
  9.  * @license http://www.opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
  10.  * @link http://recanalyst.sourceforge.net/
  11.  * @filesource
  12.  */
  13.  
  14. /**
  15.  * Class TList.
  16.  *
  17.  * TList implements a list.
  18.  *
  19.  * @package recAnalyst
  20.  */
  21. class TList implements Iterator
  22. {
  23.     /**
  24.      * Internal list of items.
  25.      *
  26.      * @var array 
  27.      */
  28.     protected $list;
  29.  
  30.     /**
  31.      * Number of items in the list.
  32.      *
  33.      * @var int 
  34.      */
  35.     protected $count;
  36.  
  37.     /**
  38.      * Class constructor.
  39.      *
  40.      */
  41.     public function __construct ()
  42.     {
  43.         $this->list = array ();
  44.         $this->count = 0;
  45.     }
  46.  
  47.     /**
  48.      * Adds an item to the list.
  49.      *
  50.      * @param mixed $item the item we wish to add
  51.      */
  52.     protected function addItem ($item)
  53.     {
  54.         $this->list[$item;
  55.         $this->count++;
  56.     }
  57.  
  58.     /**
  59.      * Returns an item at the specified offset.
  60.      *
  61.      * @param int $index the index of item
  62.      * @return mixed|boolthe item or false if index is out of the range
  63.      */
  64.     protected function getItem ($index)
  65.     {
  66.         return ($index >= && $index $this->count$this->list[$indexfalse;
  67.     }
  68.  
  69.     /**
  70.      * Returns the number of items in the list.
  71.      *
  72.      * @return int the number of items
  73.      */
  74.     public function getCount ()
  75.     {
  76.         return $this->count;
  77.     }
  78.  
  79.     /**
  80.      * Clears the list.
  81.      *
  82.      * @return void 
  83.      */
  84.     public function clear ()
  85.     {
  86.         $this->list = array ();
  87.         $this->count = 0;
  88.     }
  89.  
  90.     /**
  91.      * Rewinds internal array pointer.
  92.      * This method is required by the interface Iterator.
  93.      *
  94.      */
  95.     public function rewind ()
  96.     {
  97.         if (is_array ($this->list|| is_object ($this->list))
  98.         {
  99.             reset ($this->list);
  100.         }
  101.     }
  102.  
  103.     /**
  104.      * Returns the current array item.
  105.      * This method is required by the interface Iterator.
  106.      *
  107.      * @return mixed the current array item
  108.      */
  109.     public function current ()
  110.        {
  111.            if (!is_array ($this->list&& !is_object ($this->list))
  112.                return false;
  113.  
  114.         $var current ($this->list);
  115.         return $var;
  116.     }
  117.  
  118.     /**
  119.      * Returns the key of the current array item.
  120.      * This method is required by the interface Iterator.
  121.      *
  122.      * @return int the key of the current array item
  123.      */
  124.     public function key ()
  125.     {
  126.         $var key ($this->list);
  127.         return $var;
  128.     }
  129.  
  130.     /**
  131.      * Moves the internal pointer to the next array item.
  132.      * This method is required by the interface Iterator.
  133.      *
  134.      * @return mixed the next array item
  135.      */
  136.     public function next ()
  137.     {
  138.         $var next ($this->list);
  139.         return $var;
  140.     }
  141.  
  142.     /**
  143.      * Returns whether there is an item at current position.
  144.      * This method is required by the interface Iterator.
  145.      *
  146.      * @return bool 
  147.      */
  148.     public function valid ()
  149.     {
  150.         $var $this->current (!== false;
  151.         return $var;
  152.     }
  153. }
  154. ?>

Documentation generated on Mon, 11 May 2009 16:43:55 +0200 by phpDocumentor 1.4.1