MTMS main
Modern Turing Machine Simulator
Loading...
Searching...
No Matches
State Class Reference

Represents a single state in the finite set of states (Q) of the Turing Machine. More...

#include <state.hpp>

Collaboration diagram for State:

Public Member Functions

std::string_view get_label () const noexcept
 Getter for the state's unique label.
 
bool is_accept () const noexcept
 Checks if this state is an accepting (final) state.
 
auto operator<=> (const State &other) const noexcept
 Provides lexicographical ordering based solely on the state's label.
 
bool operator== (const State &other) const noexcept
 Compares two states for equality using only their unique identifier.
 
 State () noexcept
 Default constructor.
 
 State (std::string label, bool is_accept) noexcept(false)
 Explicit constructor to create a named State.
 

Private Attributes

bool is_accept_
 Flag indicating if this is a final/halting state.
 
std::string label_
 The unique identifier name of the state.
 

Detailed Description

Represents a single state in the finite set of states (Q) of the Turing Machine.

This class stores the unique identifier (label) of the state and determines whether it acts as an accepting/halting condition for the machine's execution.

Definition at line 25 of file state.hpp.

Constructor & Destructor Documentation

◆ State() [1/2]

State::State ( )
inlinenoexcept

Default constructor.

Initializes an empty state that is not accepting.

Definition at line 31 of file state.hpp.

◆ State() [2/2]

State::State ( std::string  label,
bool  is_accept 
)
inlineexplicit

Explicit constructor to create a named State.

Takes the label by value and moves it internally to optimize memory allocations.

Parameters
labelThe unique string identifier for this state (e.g., "q0", "init").
is_acceptBoolean flag indicating if this is an accepting/final state.

Definition at line 40 of file state.hpp.

Member Function Documentation

◆ get_label()

std::string_view State::get_label ( ) const
inlinenoexcept

Getter for the state's unique label.

Returning a std::string_view prevents unnecessary string copies.

Returns
std::string_view A view of the state's internal name string.

Definition at line 50 of file state.hpp.

References label_.

Referenced by render_dashboard(), and run_cli_session().

◆ is_accept()

bool State::is_accept ( ) const
inlinenoexcept

Checks if this state is an accepting (final) state.

Returns
true If the machine should halt and accept when entering this state, false otherwise.

Definition at line 56 of file state.hpp.

References is_accept_.

Referenced by run_cli_session(), and TuringMachine::step().

◆ operator<=>()

auto State::operator<=> ( const State other) const
inlinenoexcept

Provides lexicographical ordering based solely on the state's label.

This ordering allows State objects to be stored in ordered associative containers such as std::set while preserving the mathematical uniqueness of states by their identifier.

Parameters
otherThe state to compare against.
Returns
std::strong_ordering The ordering relationship between both labels.

Definition at line 83 of file state.hpp.

◆ operator==()

bool State::operator== ( const State other) const
inlinenoexcept

Compares two states for equality using only their unique identifier.

Within the formal definition of a Turing Machine, each state is uniquely identified by its label. Therefore, the acceptance flag is intentionally ignored during equality comparisons.

Parameters
otherThe state to compare against.
Returns
true if both states share the same label, false otherwise.

Definition at line 68 of file state.hpp.

References label_.

Member Data Documentation

◆ is_accept_

bool State::is_accept_
private

Flag indicating if this is a final/halting state.

Definition at line 90 of file state.hpp.

Referenced by is_accept().

◆ label_

std::string State::label_
private

The unique identifier name of the state.

Definition at line 89 of file state.hpp.

Referenced by get_label(), and operator==().


The documentation for this class was generated from the following file: