MTMS main
Modern Turing Machine Simulator
Loading...
Searching...
No Matches
symbol.hpp
Go to the documentation of this file.
1
11#ifndef SYMBOL_HPP
12#define SYMBOL_HPP
13
14#include <iostream>
15#include <ostream>
16
20constexpr char kBlank = ' ';
21
29class Symbol
30{
31 public:
35 Symbol() noexcept : char_(kBlank) {}
36
41 explicit Symbol(char symbol) noexcept : char_(symbol) {}
42
47 [[nodiscard]] char get_char() const noexcept { return this->char_; }
48
57 [[nodiscard]] auto operator<=>(const Symbol &other) const noexcept = default;
58
66 Symbol &operator=(const Symbol &other) noexcept = default;
67
72 void print(std::ostream &os = std::cout) const noexcept { os << this->char_; }
73
82 friend std::ostream &operator<<(std::ostream &os, const Symbol &symbol) noexcept;
83
84 private:
85 char char_;
86};
87
92inline std::ostream &operator<<(std::ostream &os, const Symbol &symbol) noexcept
93{
94 symbol.print(os);
95 return os;
96}
97
98#endif // SYMBOL_HPP
Represents a single symbol on the Turing Machine's tape.
Definition symbol.hpp:30
Symbol(char symbol) noexcept
Explicit constructor to create a Symbol from a raw character.
Definition symbol.hpp:41
Symbol & operator=(const Symbol &other) noexcept=default
Defaulted copy assignment operator.
char char_
The primitive character backing this Symbol.
Definition symbol.hpp:85
void print(std::ostream &os=std::cout) const noexcept
Prints the symbol's character representation to the specified output stream.
Definition symbol.hpp:72
auto operator<=>(const Symbol &other) const noexcept=default
Defaulted three-way comparison operator (C++20 spaceship operator).
friend std::ostream & operator<<(std::ostream &os, const Symbol &symbol) noexcept
Overloaded stream insertion operator for native stream integration.
Definition symbol.hpp:92
char get_char() const noexcept
Getter for the underlying raw character.
Definition symbol.hpp:47
Symbol() noexcept
Default constructor.
Definition symbol.hpp:35
constexpr char kBlank
Representation of the default blank symbol used to fill the Turing Machine's tape.
Definition symbol.hpp:20
std::ostream & operator<<(std::ostream &os, const Symbol &symbol) noexcept
Global implementation of the stream insertion operator for Symbol.
Definition symbol.hpp:92