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

Represents the formal alphabet ( $\Sigma$ or $\Gamma$) of a Turing Machine. More...

#include <alphabet.hpp>

Collaboration diagram for Alphabet:

Public Member Functions

 Alphabet () noexcept=default
 Default constructor.
 
 Alphabet (const std::set< Symbol > &symbols) noexcept(false)
 Explicit constructor to build an Alphabet from an existing set of Symbols.
 
 Alphabet (std::string_view str) noexcept(false)
 Explicit constructor to build an Alphabet from a string view.
 
auto begin () const noexcept
 Returns an iterator to the beginning of the alphabet set.
 
bool contains (const Symbol &symbol) const noexcept
 Checks if a specific Symbol belongs to this alphabet.
 
auto end () const noexcept
 Returns an iterator to the end of the alphabet set.
 
const std::set< Symbol > & get_set () const noexcept
 Getter for the underlying standard set of symbols.
 
void print (std::ostream &os=std::cout) const noexcept
 Prints the alphabet in mathematical set notation format (e.g., "{0, 1}").
 
std::size_t size () const noexcept
 Retrieves the total number of unique symbols currently in the alphabet.
 

Private Member Functions

template<class T >
void insert (const T &data) noexcept(false)
 Private helper template to genericly process and insert elements into the alphabet.
 

Private Attributes

std::set< Symbolset_
 The unique, sorted collection of symbols composing the alphabet.
 

Friends

std::ostream & operator<< (std::ostream &os, const Alphabet &alphabet) noexcept
 Overloaded stream insertion operator to print the Alphabet object.
 

Detailed Description

Represents the formal alphabet ( $\Sigma$ or $\Gamma$) of a Turing Machine.

It stores a unique, ordered set of Symbol instances.

Definition at line 26 of file alphabet.hpp.

Constructor & Destructor Documentation

◆ Alphabet() [1/3]

Alphabet::Alphabet ( )
defaultnoexcept

Default constructor.

Initializes an empty alphabet.

◆ Alphabet() [2/3]

Alphabet::Alphabet ( std::string_view  str)
inlineexplicit

Explicit constructor to build an Alphabet from a string view.

Iterates through the provided string and inserts each unique character as a Symbol.

Parameters
strThe sequence of characters representing the alphabet symbols.

Definition at line 40 of file alphabet.hpp.

References insert().

◆ Alphabet() [3/3]

Alphabet::Alphabet ( const std::set< Symbol > &  symbols)
inlineexplicit

Explicit constructor to build an Alphabet from an existing set of Symbols.

Parameters
symbolsA standard set containing the initial Symbols.

Definition at line 46 of file alphabet.hpp.

References insert().

Member Function Documentation

◆ begin()

auto Alphabet::begin ( ) const
inlinenoexcept

Returns an iterator to the beginning of the alphabet set.

Definition at line 73 of file alphabet.hpp.

References set_.

◆ contains()

bool Alphabet::contains ( const Symbol symbol) const
inlinenoexcept

Checks if a specific Symbol belongs to this alphabet.

Parameters
symbolThe Symbol instance to look up.
Returns
true If the symbol is present in the alphabet, false otherwise.

Definition at line 65 of file alphabet.hpp.

References set_.

Referenced by Project::load_project().

◆ end()

auto Alphabet::end ( ) const
inlinenoexcept

Returns an iterator to the end of the alphabet set.

Definition at line 78 of file alphabet.hpp.

References set_.

◆ get_set()

const std::set< Symbol > & Alphabet::get_set ( ) const
inlinenoexcept

Getter for the underlying standard set of symbols.

Returns
const std::set<Symbol>& A read-only reference to the symbol set.

Definition at line 52 of file alphabet.hpp.

References set_.

◆ insert()

template<class T >
void Alphabet::insert ( const T &  data)
private

Private helper template to genericly process and insert elements into the alphabet.

Template Parameters
TA collection type that supports range-based loops (e.g., string_view, std::set).
Parameters
dataThe iterable dataset containing potential symbols.

Definition at line 106 of file alphabet.hpp.

Referenced by Alphabet(), and Alphabet().

◆ print()

void Alphabet::print ( std::ostream &  os = std::cout) const
noexcept

Prints the alphabet in mathematical set notation format (e.g., "{0, 1}").

Serializes the sorted collection layout using mathematical format markers.

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

Leverages C++20/C++23 structural views pipelines to enforce precise delimiter spacing.

Definition at line 20 of file alphabet.cpp.

◆ size()

std::size_t Alphabet::size ( ) const
inlinenoexcept

Retrieves the total number of unique symbols currently in the alphabet.

Returns
std::size_t The cardinality of the alphabet set.

Definition at line 58 of file alphabet.hpp.

References set_.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Alphabet alphabet 
)
friend

Overloaded stream insertion operator to print the Alphabet object.

Parameters
osThe target output stream.
alphabetThe Alphabet instance to be streamed.
Returns
std::ostream& Reference to the output stream to allow cascading.

Definition at line 37 of file alphabet.cpp.

Member Data Documentation

◆ set_

std::set<Symbol> Alphabet::set_
private

The unique, sorted collection of symbols composing the alphabet.

Definition at line 95 of file alphabet.hpp.

Referenced by begin(), contains(), end(), get_set(), and size().


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