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

Public Member Functions

 __construct ($order=parent::IN_ORDER)
 
 visit (Visitor\Element $element, &$handle=null, $eldnah=null)
 
- Public Member Functions inherited from Hoa\Tree\Visitor\Generic
 __construct ($order=self::PRE_ORDER)
 
 getOrder ()
 
- Public Member Functions inherited from Hoa\Visitor\Visit
 visit (Element $element, &$handle=null, $eldnah=null)
 

Protected Attributes

 $_i = 0
 
- Protected Attributes inherited from Hoa\Tree\Visitor\Generic
 $_order = self::PRE_ORDER
 

Additional Inherited Members

- Public Attributes inherited from Hoa\Tree\Visitor\Generic
const PRE_ORDER = 0
 
const IN_ORDER = 1
 
const POST_ORDER = 2
 
- Protected Member Functions inherited from Hoa\Tree\Visitor\Generic
 setOrder ($order)
 

Detailed Description

Class .

Dump a tree.

Definition at line 49 of file Dump.php.

Constructor & Destructor Documentation

Hoa\Tree\Visitor\Dump::__construct (   $order = parent::IN_ORDER)

Just change the default transversal order value.

Parameters
int$orderTraversal order (please, see the * self::*_ORDER constants).
Returns
void

Definition at line 67 of file Dump.php.

68  {
69  parent::__construct($order);
70 
71  return;
72  }

Member Function Documentation

Hoa\Tree\Visitor\Dump::visit ( Visitor\Element  $element,
$handle = null,
  $eldnah = null 
)

Visit an element.

Parameters
\Hoa\Visitor\Element$elementElement to visit.
mixed&$handleHandle (reference).
mixed$eldnahHandle (not reference).
Returns
string

Definition at line 82 of file Dump.php.

86  {
87  $pre = null;
88  $in = '> ' . str_repeat(' ', $this->_i) . $element->getValue() . "\n";
89  $post = null;
90  $childs = $element->getChilds();
91  $i = 0;
92  $max = floor(count($childs) / 2);
93 
94  ++$this->_i;
95 
96  foreach ($childs as $id => $child) {
97  if ($i++ < $max) {
98  $pre .= $child->accept($this, $handle, $eldnah);
99  } else {
100  $post .= $child->accept($this, $handle, $eldnah);
101  }
102  }
103 
104  --$this->_i;
105 
106  switch ($this->getOrder()) {
107  case parent::IN_ORDER:
108  return $in . $pre . $post;
109 
110  case parent::POST_ORDER:
111  return $post . $in . $pre;
112 
113  default:
114  return $pre . $in . $post;
115  }
116  }

Here is the call graph for this function:

Member Data Documentation

Hoa\Tree\Visitor\Dump::$_i = 0
protected

Definition at line 56 of file Dump.php.


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