Hoa central
TreeNode.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Compiler\Llk;
38 
39 use Hoa\Visitor;
40 
49 class TreeNode implements Visitor\Element
50 {
56  protected $_id = null;
57 
63  protected $_value = null;
64 
70  protected $_children = null;
71 
77  protected $_parent = null;
78 
84  protected $_data = [];
85 
86 
87 
97  public function __construct(
98  $id,
99  $value = null,
100  Array $children = [],
101  TreeNode $parent = null
102  ) {
103  $this->setId($id);
104  $this->setValue($value);
105  $this->setChildren($children);
106 
107  if (null !== $parent) {
108  $this->setParent($parent);
109  }
110 
111  return;
112  }
113 
120  public function setId($id)
121  {
122  $old = $this->_id;
123  $this->_id = $id;
124 
125  return $old;
126  }
127 
133  public function getId()
134  {
135  return $this->_id;
136  }
137 
144  public function setValue($value)
145  {
146  $old = $this->_value;
147  $this->_value = $value;
148 
149  return $old;
150  }
151 
157  public function getValue()
158  {
159  return $this->_value;
160  }
161 
167  public function getValueToken()
168  {
169  return $this->_value['token'];
170  }
171 
177  public function getValueValue()
178  {
179  return $this->_value['value'];
180  }
181 
187  public function isToken()
188  {
189  return null !== $this->_value;
190  }
191 
198  public function prependChild(TreeNode $child)
199  {
200  array_unshift($this->_children, $child);
201 
202  return $this;
203  }
204 
211  public function appendChild(TreeNode $child)
212  {
213  $this->_children[] = $child;
214 
215  return $this;
216  }
217 
223  public function setChildren(Array $children)
224  {
225  $old = $this->_children;
226  $this->_children = $children;
227 
228  return $old;
229  }
230 
237  public function getChild($i)
238  {
239  return $this->_children[$i];
240  }
241 
247  public function getChildren()
248  {
249  return $this->_children;
250  }
251 
257  public function getChildrenNumber()
258  {
259  return count($this->_children);
260  }
261 
267  public function childExists($i)
268  {
269  return array_key_exists($i, $this->_children);
270  }
271 
278  public function setParent(TreeNode $parent)
279  {
280  $old = $this->_parent;
281  $this->_parent = $parent;
282 
283  return $old;
284  }
285 
291  public function getParent()
292  {
293  return $this->_parent;
294  }
295 
301  public function &getData()
302  {
303  return $this->_data;
304  }
305 
314  public function accept(
315  Visitor\Visit $visitor,
316  &$handle = null,
317  $eldnah = null
318  ) {
319  return $visitor->visit($this, $handle, $eldnah);
320  }
321 
327  public function __destruct()
328  {
329  unset($this->_parent);
330 
331  return;
332  }
333 }
accept(Visitor\Visit $visitor, &$handle=null, $eldnah=null)
Definition: TreeNode.php:314
setChildren(Array $children)
Definition: TreeNode.php:223
setParent(TreeNode $parent)
Definition: TreeNode.php:278
prependChild(TreeNode $child)
Definition: TreeNode.php:198
appendChild(TreeNode $child)
Definition: TreeNode.php:211
__construct($id, $value=null, Array $children=[], TreeNode $parent=null)
Definition: TreeNode.php:97