|
| void | move (Direction dir) noexcept |
| | Shifts the tape head one cell to the left, right or make it stay.
|
| |
| void | print (std::ostream &os=std::cout) const noexcept |
| | Renders the active layout of the tape and the head tracking to an output stream.
|
| |
| Symbol | read () const noexcept |
| | Reads the symbol currently located under the tape head.
|
| |
| | Tape () noexcept |
| | Default constructor.
|
| |
| | Tape (String str) noexcept(false) |
| | Constructs a Tape populated with an initial formal String.
|
| |
| void | write (Symbol symbol) noexcept(false) |
| | Writes a symbol into the cell currently under the tape head.
|
| |
Simulates the bilateral infinite tape layout of a Turing Machine.
Uses a dynamic std::map indexed by signed integers to support infinite expansion toward both negative and positive coordinates with logarithmic lookup overhead.
Definition at line 29 of file tape.hpp.
Constructs a Tape populated with an initial formal String.
Custom constructor to load a formal Word into the machine's memory.
Places the string's symbols sequentially starting at index 0 and sets the head to 0.
- Parameters
-
| str | The formal String sequence to load onto the tape. |
- Exceptions
-
| std::out_of_range | If the input string length exceeds the maximum signed integer capacity of the tape. |
Uses C++20 views::enumerate to extract both the structural index and the Symbol object, populating the map from coordinate 0 onward.
- Parameters
-
| str | The formal String sequence to load onto the tape. |
- Exceptions
-
| std::out_of_range | If the input string length exceeds the maximum signed integer capacity of the tape. |
Definition at line 27 of file tape.cpp.
Shifts the tape head one cell to the left, right or make it stay.
Passed by value since Direction is an enum class.
- Parameters
-
| dir | The movement direction (LEFT, RIGHT or STAY). |
Definition at line 74 of file tape.hpp.
References head_pos_, LEFT, RIGHT, and STAY.
| void Tape::print |
( |
std::ostream & |
os = std::cout | ) |
const |
|
noexcept |
Renders the active layout of the tape and the head tracking to an output stream.
Renders a structural blueprint of the active tape cells to any std::ostream.
- Parameters
-
| os | The target output stream (defaults to std::cout). |
Automatically wraps current track margins based on the dynamic map bounds and the current hardware head displacement coordinates.
Definition at line 63 of file tape.cpp.
References kBlank.
Reads the symbol currently located under the tape head.
Scans the active cell under the simulation head.
If the current coordinate has not been modified yet, it assumes the cell belongs to the infinite blank space and safely returns a kBlank symbol.
- Returns
- Symbol The symbol scanned at the current head position.
Safeguards the infinite tape constraint by looking up coordinates via std::map::find. If the element is missing, it dynamically rolls a virtual kBlank context.
Definition at line 48 of file tape.cpp.
References cells_, head_pos_, and kBlank.