MTMS main
Modern Turing Machine Simulator
Loading...
Searching...
No Matches
string.hpp
Go to the documentation of this file.
1
11#ifndef STRING_HPP
12#define STRING_HPP
13
14#include "alphabet.hpp"
15#include "symbol.hpp"
16
17#include <string>
18#include <string_view>
19#include <vector>
20
28class String
29{
30 public:
34 String() noexcept = default;
35
40 explicit String(const Symbol &symbol) noexcept(false) { this->symbols_.emplace_back(symbol); }
41
46 explicit String(std::string_view str) noexcept(false);
47
55 explicit String(std::vector<Symbol> vec) noexcept(false) : symbols_(std::move(vec)) {}
56
61 [[nodiscard]] std::size_t length() const noexcept { return this->symbols_.size(); }
62
67 [[nodiscard]] std::string get_str() const noexcept(false);
68
72 [[nodiscard]] auto begin() const noexcept { return this->symbols_.begin(); }
73
77 [[nodiscard]] auto end() const noexcept { return this->symbols_.end(); }
78
87 [[nodiscard]] bool is_valid_for(const Alphabet &alphabet) const noexcept;
88
98 [[nodiscard]] auto operator<=>(const String &other) const noexcept = default;
99
100 private:
101 std::vector<Symbol> symbols_;
102};
103
104#endif // STRING_HPP
Alphabet class to manage the collection of valid symbols for the Turing Machine.
Represents the formal alphabet ( or ) of a Turing Machine.
Definition alphabet.hpp:27
Represents a formal string (w) consisting of a finite sequence of Symbols.
Definition string.hpp:29
auto operator<=>(const String &other) const noexcept=default
Defaulted three-way comparison operator (C++20 spaceship operator).
std::vector< Symbol > symbols_
The finite sequence of symbols forming the string.
Definition string.hpp:101
std::string get_str() const noexcept(false)
Reconstructs a standard std::string representation from the underlying symbols.
Definition string.cpp:34
String(std::vector< Symbol > vec) noexcept(false)
Constructs a String by taking ownership of an existing vector of symbols.
Definition string.hpp:55
std::size_t length() const noexcept
Returns the total number of symbols contained in the string.
Definition string.hpp:61
bool is_valid_for(const Alphabet &alphabet) const noexcept
Validates if all symbols within this string belong to a specific formal Alphabet.
Definition string.cpp:52
String() noexcept=default
Default constructor.
auto end() const noexcept
Returns an iterator to the end of the symbol sequence.
Definition string.hpp:77
auto begin() const noexcept
Returns an iterator to the beginning of the symbol sequence.
Definition string.hpp:72
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.