Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Iterator\Counter Class Reference
Inheritance diagram for Hoa\Iterator\Counter:

Public Member Functions

 __construct ($from, $to, $step)
 
 current ()
 
 key ()
 
 next ()
 
 rewind ()
 
 valid ()
 

Protected Attributes

 $_from = 0
 
 $_key = 0
 
 $_i = 0
 
 $_to = 0
 
 $_step = 0
 

Detailed Description

Class .

A counter.

Definition at line 47 of file Counter.php.

Constructor & Destructor Documentation

Hoa\Iterator\Counter::__construct (   $from,
  $to,
  $step 
)

Constructor. Equivalent to: for($i = $from; $i < $to; $i += $step)

Parameters
int$fromStart value.
int$toMaximum value.
int$stepStep.
Returns
void
Exceptions

Definition at line 97 of file Counter.php.

98  {
99  if ($step <= 0) {
100  throw new Exception(
101  'The step must be non-negative; given %d.',
102  0,
103  $step
104  );
105  }
106 
107  $this->_from = $from;
108  $this->_to = $to;
109  $this->_step = $step;
110 
111  return;
112  }

Member Function Documentation

Hoa\Iterator\Counter::current ( )

Return the current element.

Returns
int

Definition at line 119 of file Counter.php.

120  {
121  return $this->_i;
122  }
Hoa\Iterator\Counter::key ( )

Return the key of the current element.

Returns
int

Definition at line 129 of file Counter.php.

130  {
131  return $this->_key;
132  }
Hoa\Iterator\Counter::next ( )

Move forward to next element.

Returns
void

Definition at line 139 of file Counter.php.

140  {
141  ++$this->_key;
142  $this->_i += $this->_step;
143 
144  return;
145  }
Hoa\Iterator\Counter::rewind ( )

Rewind the iterator to the first element.

Returns
void

Definition at line 152 of file Counter.php.

153  {
154  $this->_key = 0;
155  $this->_i = $this->_from;
156 
157  return;
158  }
Hoa\Iterator\Counter::valid ( )

Check if current position is valid.

Returns
bool

Definition at line 165 of file Counter.php.

166  {
167  return $this->_i < $this->_to;
168  }

Member Data Documentation

Hoa\Iterator\Counter::$_from = 0
protected

Definition at line 54 of file Counter.php.

Hoa\Iterator\Counter::$_i = 0
protected

Definition at line 68 of file Counter.php.

Hoa\Iterator\Counter::$_key = 0
protected

Definition at line 61 of file Counter.php.

Hoa\Iterator\Counter::$_step = 0
protected

Definition at line 82 of file Counter.php.

Hoa\Iterator\Counter::$_to = 0
protected

Definition at line 75 of file Counter.php.


The documentation for this class was generated from the following file: