MTMS main
Modern Turing Machine Simulator
Loading...
Searching...
No Matches
state.hpp
Go to the documentation of this file.
1
11#ifndef STATE_HPP
12#define STATE_HPP
13
14#include <string>
15#include <string_view>
16#include <utility>
17
25class State
26{
27 public:
31 State() noexcept : is_accept_(false) {}
32
40 explicit State(std::string label, bool is_accept) noexcept(false)
41 : label_(std::move(label)), is_accept_(is_accept)
42 {}
43
50 [[nodiscard]] std::string_view get_label() const noexcept { return this->label_; }
51
56 [[nodiscard]] bool is_accept() const noexcept { return this->is_accept_; }
57
68 [[nodiscard]] bool operator==(const State &other) const noexcept
69 {
70 return this->label_ == other.label_;
71 }
72
83 [[nodiscard]] auto operator<=>(const State &other) const noexcept
84 {
85 return this->label_ <=> other.label_;
86 }
87
88 private:
89 std::string label_;
91};
92
93#endif // STATE_HPP
Represents a single state in the finite set of states (Q) of the Turing Machine.
Definition state.hpp:26
std::string label_
The unique identifier name of the state.
Definition state.hpp:89
auto operator<=>(const State &other) const noexcept
Provides lexicographical ordering based solely on the state's label.
Definition state.hpp:83
State(std::string label, bool is_accept) noexcept(false)
Explicit constructor to create a named State.
Definition state.hpp:40
bool is_accept_
Flag indicating if this is a final/halting state.
Definition state.hpp:90
std::string_view get_label() const noexcept
Getter for the state's unique label.
Definition state.hpp:50
State() noexcept
Default constructor.
Definition state.hpp:31
bool operator==(const State &other) const noexcept
Compares two states for equality using only their unique identifier.
Definition state.hpp:68
bool is_accept() const noexcept
Checks if this state is an accepting (final) state.
Definition state.hpp:56