MTMS main
Modern Turing Machine Simulator
Loading...
Searching...
No Matches
alphabet.hpp
Go to the documentation of this file.
1
11#ifndef ALPHABET_HPP
12#define ALPHABET_HPP
13
14#include "symbol.hpp"
15
16#include <iostream>
17#include <set>
18#include <string_view>
19
27{
28 public:
32 Alphabet() noexcept = default;
33
40 explicit Alphabet(std::string_view str) noexcept(false) { this->insert(str); }
41
46 explicit Alphabet(const std::set<Symbol> &symbols) noexcept(false) { this->insert(symbols); }
47
52 [[nodiscard]] const std::set<Symbol> &get_set() const noexcept { return this->set_; }
53
58 [[nodiscard]] std::size_t size() const noexcept { return this->set_.size(); }
59
65 [[nodiscard]] bool contains(const Symbol &symbol) const noexcept
66 {
67 return this->set_.contains(symbol);
68 }
69
73 [[nodiscard]] auto begin() const noexcept { return this->set_.begin(); }
74
78 [[nodiscard]] auto end() const noexcept { return this->set_.end(); }
79
84 void print(std::ostream &os = std::cout) const noexcept;
85
92 friend std::ostream &operator<<(std::ostream &os, const Alphabet &alphabet) noexcept;
93
94 private:
95 std::set<Symbol> set_;
96
103 template <class T> void insert(const T &data) noexcept(false);
104};
105
106template <class T> void Alphabet::insert(const T &data) noexcept(false)
107{
108 for (const auto &s : data)
109 {
110 this->set_.insert(Symbol(s));
111 }
112}
113
114#endif // ALPHABET_HPP
Represents the formal alphabet ( or ) of a Turing Machine.
Definition alphabet.hpp:27
void print(std::ostream &os=std::cout) const noexcept
Prints the alphabet in mathematical set notation format (e.g., "{0, 1}").
Definition alphabet.cpp:20
auto begin() const noexcept
Returns an iterator to the beginning of the alphabet set.
Definition alphabet.hpp:73
const std::set< Symbol > & get_set() const noexcept
Getter for the underlying standard set of symbols.
Definition alphabet.hpp:52
void insert(const T &data) noexcept(false)
Private helper template to genericly process and insert elements into the alphabet.
Definition alphabet.hpp:106
bool contains(const Symbol &symbol) const noexcept
Checks if a specific Symbol belongs to this alphabet.
Definition alphabet.hpp:65
friend std::ostream & operator<<(std::ostream &os, const Alphabet &alphabet) noexcept
Overloaded stream insertion operator to print the Alphabet object.
Definition alphabet.cpp:37
Alphabet() noexcept=default
Default constructor.
std::size_t size() const noexcept
Retrieves the total number of unique symbols currently in the alphabet.
Definition alphabet.hpp:58
Alphabet(const std::set< Symbol > &symbols) noexcept(false)
Explicit constructor to build an Alphabet from an existing set of Symbols.
Definition alphabet.hpp:46
auto end() const noexcept
Returns an iterator to the end of the alphabet set.
Definition alphabet.hpp:78
std::set< Symbol > set_
The unique, sorted collection of symbols composing the alphabet.
Definition alphabet.hpp:95
Represents a single symbol on the Turing Machine's tape.
Definition symbol.hpp:30
Symbol class to represent the symbols on the Turing Machine's tape.