philips-cnc6600-interpreter/src/Automata/Storage/ToolMemory.php

35 lines
529 B
PHP
Raw Normal View History

2020-05-08 00:37:29 +02:00
<?php
namespace Automata\Storage;
use Automata\Tool;
use InvalidArgumentException;
2020-05-08 00:37:29 +02:00
class ToolMemory
{
/** @var Tool[] */
private array $memory = [];
public function save(Tool $tool): void
{
$this->guardInvalidToolNumber($tool->T);
2020-05-08 00:37:29 +02:00
$this->memory[$tool->T] = $tool;
}
public function read(int $T): ?Tool
{
return @$this->memory[$T];
}
private function guardInvalidToolNumber(int $T): void
{
if ($T < 1 || $T > 64) {
throw new InvalidArgumentException('Tool number must be in range 1 - 64');
}
}
2020-05-08 00:37:29 +02:00
}