* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ class VariableIndex extends Composite { private $pos; public function __construct($pos) { $this->pos = $pos; } public function getPos() { return $this->pos; } public function testPos($pos) { return $this->pos == $pos; } public function testPosInChildren($pos) { throw new Exception("Position in children of VariableIndex cannot be tested."); } public function testNameInChildren($name) { foreach($this->children as $child) { if($child->getName() === $name) return true; } return false; } public function testName($name) { throw new Exeption("VariableIndex has no Name attribute."); } public function getChildByPos($pos) { foreach($this->children as $child) { if($child->getPos() == $pos) return $child; } throw new Exception("No child with position '$pos' found."); } public function getChildByName($name) { foreach($this->children as $child) { if($child->getName() == $name) return $child; } throw new Exception("No child with name '$name' found."); } public function accept(Visitor $visitor, $level = 1) { $visitor->visit($this, $level++); foreach($this->children as $child) { $child->accept($visitor, $level); } $visitor->removeLastVariablePart(); } } ?>