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

Public Member Functions

 __construct ($value=null)
 
 setValue ($value)
 
 getValue ()
 
 current ()
 
 key ()
 
 next ()
 
 rewind ()
 
 valid ()
 
 seek ($position)
 
 count ()
 
 getChild ($nodeId)
 
 getChilds ()
 
 childExists ($nodeId)
 
 insert (Generic $child)
 
 delete ($i)
 
 isLeaf ()
 
 isNode ()
 
 accept (Visitor\Visit $visitor, &$handle=null, $eldnah=null)
 
- Public Member Functions inherited from Hoa\Visitor\Element
 accept (Visit $visitor, &$handle=null, $eldnah=null)
 

Protected Attributes

 $_value = null
 
 $_childs = []
 

Detailed Description

Class .

Here is an abstract tree.

Definition at line 49 of file Generic.php.

Constructor & Destructor Documentation

Hoa\Tree\Generic::__construct (   $value = null)

Build a node. It can be a root, a node or a leaf of course.

Parameters
mixed$valueNode value.
Returns
void

Definition at line 76 of file Generic.php.

77  {
78  $this->setValue($value);
79 
80  return;
81  }
setValue($value)
Definition: Generic.php:89

Here is the call graph for this function:

Member Function Documentation

Hoa\Tree\Generic::accept ( Visitor\Visit  $visitor,
$handle = null,
  $eldnah = null 
)

Accept a visitor.

Parameters
\Hoa\Visitor\Visit$visitorVisitor.
mixed&$handleHandle (reference).
mixed$eldnaHandle (not reference).
Returns
mixed

Definition at line 286 of file Generic.php.

290  {
291  return $visitor->visit($this, $handle, $eldnah);
292  }
Hoa\Tree\Generic::childExists (   $nodeId)

Check if a child exists.

Parameters
mixed$nodeIdNode ID.
Returns
bool

Definition at line 240 of file Generic.php.

241  {
242  return array_key_exists($nodeId, $this->getChilds());
243  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Tree\Generic::count ( )

Count number of elements in collection.

Returns
int

Definition at line 203 of file Generic.php.

204  {
205  return count($this->_childs);
206  }
Hoa\Tree\Generic::current ( )

Get the current child for the iterator.

Returns

Definition at line 116 of file Generic.php.

117  {
118  return current($this->_childs);
119  }
Hoa\Tree\Generic::delete (   $i)
abstract

Delete a child.

Parameters
int$iChild index.
Returns
Exceptions
Hoa\Tree\Generic::getChild (   $nodeId)

Get a specific child.

Parameters
mixed$nodeIdNode ID.
Returns
Exceptions

Definition at line 215 of file Generic.php.

216  {
217  if (false === $this->childExists($nodeId)) {
218  throw new Exception('Child %s does not exist.', 0, $nodeId);
219  }
220 
221  return $this->_childs[$nodeId];
222  }
childExists($nodeId)
Definition: Generic.php:240

Here is the call graph for this function:

Hoa\Tree\Generic::getChilds ( )

Get all childs.

Returns
array

Definition at line 229 of file Generic.php.

230  {
231  return $this->_childs;
232  }

Here is the caller graph for this function:

Hoa\Tree\Generic::getValue ( )

Get the node value.

Returns

Definition at line 106 of file Generic.php.

107  {
108  return $this->_value;
109  }

Here is the caller graph for this function:

Hoa\Tree\Generic::insert ( Generic  $child)
abstract

Insert a child. Fill the child list from left to right.

Parameters
\Hoa\Tree\Generic$childChild to insert.
Returns
Exceptions
Hoa\Tree\Generic::isLeaf ( )
abstract

Check if the node is a leaf.

Returns
bool
Hoa\Tree\Generic::isNode ( )
abstract

Check if the node is a node (i.e. not a leaf).

Returns
bool
Hoa\Tree\Generic::key ( )

Get the current child id for the iterator.

Returns
int

Definition at line 126 of file Generic.php.

127  {
128  return key($this->_childs);
129  }

Here is the caller graph for this function:

Hoa\Tree\Generic::next ( )

Advance the internal child pointer, and return the current child.

Returns

Definition at line 136 of file Generic.php.

137  {
138  return next($this->_childs);
139  }

Here is the caller graph for this function:

Hoa\Tree\Generic::rewind ( )

Rewind the internal child pointer, and return the first child.

Returns

Definition at line 146 of file Generic.php.

147  {
148  return reset($this->_childs);
149  }

Here is the caller graph for this function:

Hoa\Tree\Generic::seek (   $position)

Seek to a position.

Parameters
mixed$positionPosition to seek.
Returns
void

Definition at line 183 of file Generic.php.

184  {
185  if (!array_key_exists($position, $this->_collection)) {
186  return;
187  }
188 
189  $this->rewind();
190 
191  while ($position != $this->key()) {
192  $this->next();
193  }
194 
195  return;
196  }

Here is the call graph for this function:

Hoa\Tree\Generic::setValue (   $value)

Set the node value.

Parameters
mixed$valueNode value.
Returns
mixed

Definition at line 89 of file Generic.php.

90  {
91  if (!($value instanceof ITree\Node)) {
92  $value = new SimpleNode(md5($value), $value);
93  }
94 
95  $old = $this->_value;
96  $this->_value = $value;
97 
98  return $old;
99  }

Here is the caller graph for this function:

Hoa\Tree\Generic::valid ( )

Check if there is a current element after calls to the rewind or the next methods.

Returns
bool

Definition at line 157 of file Generic.php.

158  {
159  if (empty($this->_collection)) {
160  return false;
161  }
162 
163  $key = key($this->_collection);
164  $return = (bool) next($this->_childs);
165  prev($this->_collection);
166 
167  if (false === $return) {
168  end($this->_childs);
169  if ($key === key($this->_childs)) {
170  $return = true;
171  }
172  }
173 
174  return $return;
175  }

Here is the call graph for this function:

Member Data Documentation

Hoa\Tree\Generic::$_childs = []
protected

Definition at line 67 of file Generic.php.

Hoa\Tree\Generic::$_value = null
protected

Definition at line 60 of file Generic.php.


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