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

Represents a single symbol on the Turing Machine's tape. More...

#include <symbol.hpp>

Collaboration diagram for Symbol:

Public Member Functions

char get_char () const noexcept
 Getter for the underlying raw character.
 
auto operator<=> (const Symbol &other) const noexcept=default
 Defaulted three-way comparison operator (C++20 spaceship operator).
 
Symboloperator= (const Symbol &other) noexcept=default
 Defaulted copy assignment operator.
 
void print (std::ostream &os=std::cout) const noexcept
 Prints the symbol's character representation to the specified output stream.
 
 Symbol () noexcept
 Default constructor.
 
 Symbol (char symbol) noexcept
 Explicit constructor to create a Symbol from a raw character.
 

Private Attributes

char char_
 The primitive character backing this Symbol.
 

Friends

std::ostream & operator<< (std::ostream &os, const Symbol &symbol) noexcept
 Overloaded stream insertion operator for native stream integration.
 

Detailed Description

Represents a single symbol on the Turing Machine's tape.

This class acts as a lightweight wrapper around a primitive char. It provides safe comparison mechanics through the C++20 spaceship operator and integrates natively with C++ standard output streams.

Definition at line 29 of file symbol.hpp.

Constructor & Destructor Documentation

◆ Symbol() [1/2]

Symbol::Symbol ( )
inlinenoexcept

Default constructor.

Initializes the symbol as a blank/white space.

Definition at line 35 of file symbol.hpp.

◆ Symbol() [2/2]

Symbol::Symbol ( char  symbol)
inlineexplicitnoexcept

Explicit constructor to create a Symbol from a raw character.

Parameters
symbolThe raw character representation to be stored.

Definition at line 41 of file symbol.hpp.

Member Function Documentation

◆ get_char()

char Symbol::get_char ( ) const
inlinenoexcept

Getter for the underlying raw character.

Returns
char The primitive character stored inside the Symbol object.

Definition at line 47 of file symbol.hpp.

References char_.

Referenced by Project::parse_alphabets().

◆ operator<=>()

auto Symbol::operator<=> ( const Symbol other) const
defaultnoexcept

Defaulted three-way comparison operator (C++20 spaceship operator).

Instructs the compiler to automatically generate standard relational operators (<, <=, >, >=, ==, !=) based on the underlying char_ member.

Parameters
otherThe other Symbol instance to compare against.
Returns
auto A strong ordering comparison category (std::strong_ordering).

◆ operator=()

Symbol & Symbol::operator= ( const Symbol other)
defaultnoexcept

Defaulted copy assignment operator.

Performs a fast, direct bitwise copy of the underlying primitive data.

Parameters
otherThe source Symbol to copy from.
Returns
Symbol& Reference to this instance (*this) to allow chain assignment.

◆ print()

void Symbol::print ( std::ostream &  os = std::cout) const
inlinenoexcept

Prints the symbol's character representation to the specified output stream.

Parameters
osThe output stream target (defaults to std::cout).

Definition at line 72 of file symbol.hpp.

References char_.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Symbol symbol 
)
friend

Overloaded stream insertion operator for native stream integration.

Allows syntax like std::cout << my_symbol; by forwarding to the print method.

Parameters
osThe target output stream.
symbolThe Symbol instance to be printed.
Returns
std::ostream& Reference to the output stream to allow cascading.
Note
Marked as inline to prevent ODR violations across multiple translation units.

Definition at line 92 of file symbol.hpp.

Member Data Documentation

◆ char_

char Symbol::char_
private

The primitive character backing this Symbol.

Definition at line 85 of file symbol.hpp.

Referenced by get_char(), and print().


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