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

Represents a formal string (w) consisting of a finite sequence of Symbols. More...

#include <string.hpp>

Collaboration diagram for String:

Public Member Functions

auto begin () const noexcept
 Returns an iterator to the beginning of the symbol sequence.
 
auto end () const noexcept
 Returns an iterator to the end of the symbol sequence.
 
std::string get_str () const noexcept(false)
 Reconstructs a standard std::string representation from the underlying symbols.
 
bool is_valid_for (const Alphabet &alphabet) const noexcept
 Validates if all symbols within this string belong to a specific formal Alphabet.
 
std::size_t length () const noexcept
 Returns the total number of symbols contained in the string.
 
auto operator<=> (const String &other) const noexcept=default
 Defaulted three-way comparison operator (C++20 spaceship operator).
 
 String () noexcept=default
 Default constructor.
 
 String (const Symbol &symbol) noexcept(false)
 Constructs a single-symbol string.
 
 String (std::string_view str) noexcept(false)
 Constructs a formal String from a raw string view.
 
 String (std::vector< Symbol > vec) noexcept(false)
 Constructs a String by taking ownership of an existing vector of symbols.
 

Private Attributes

std::vector< Symbolsymbols_
 The finite sequence of symbols forming the string.
 

Detailed Description

Represents a formal string (w) consisting of a finite sequence of Symbols.

This class encapsulates a collection of symbols, providing validation tools against formal alphabets and standard iterator access for processing.

Definition at line 28 of file string.hpp.

Constructor & Destructor Documentation

◆ String() [1/4]

String::String ( )
defaultnoexcept

Default constructor.

Initializes an empty string with no symbols.

◆ String() [2/4]

String::String ( const Symbol symbol)
inlineexplicit

Constructs a single-symbol string.

Parameters
symbolThe initial Symbol to wrap.

Definition at line 40 of file string.hpp.

References symbols_.

◆ String() [3/4]

String::String ( std::string_view  str)
explicit

Constructs a formal String from a raw string view.

Custom constructor to morph a raw character stream view into a formal sequence.

Parameters
strThe raw character sequence.

Leverages vector internal resizing strategies via sequential emplace_back pipeline pushes.

Definition at line 20 of file string.cpp.

References symbols_.

◆ String() [4/4]

String::String ( std::vector< Symbol vec)
inlineexplicit

Constructs a String by taking ownership of an existing vector of symbols.

Uses pass-by-value and std::move to prevent redundant overhead dynamic allocations.

Parameters
vecThe source vector of symbols.

Definition at line 55 of file string.hpp.

Member Function Documentation

◆ begin()

auto String::begin ( ) const
inlinenoexcept

Returns an iterator to the beginning of the symbol sequence.

Definition at line 72 of file string.hpp.

References symbols_.

◆ end()

auto String::end ( ) const
inlinenoexcept

Returns an iterator to the end of the symbol sequence.

Definition at line 77 of file string.hpp.

References symbols_.

◆ get_str()

std::string String::get_str ( ) const

Reconstructs a standard std::string representation from the underlying symbols.

Serializes the formal layout array back into a standard standard library string.

Returns
std::string A standard string concatenation of all wrapped symbols.

Optimizes performance overhead by pre-allocating heap capacity tokens via reserve().

Definition at line 34 of file string.cpp.

References symbols_.

◆ is_valid_for()

bool String::is_valid_for ( const Alphabet alphabet) const
noexcept

Validates if all symbols within this string belong to a specific formal Alphabet.

Predicate logic pipeline evaluating structural correctness against an Alphabet.

Uses C++20 ranges to perform a clean and optimized all-of predicate check.

Parameters
alphabetThe formal Alphabet descriptor to validate against.
Returns
true If every single symbol is registered in the alphabet, false otherwise.

Evaluates short-circuit logical breaks using standard library ranges algorithms.

Definition at line 52 of file string.cpp.

Referenced by TuringMachine::load_input().

◆ length()

std::size_t String::length ( ) const
inlinenoexcept

Returns the total number of symbols contained in the string.

Returns
std::size_t The length of the formal string.

Definition at line 61 of file string.hpp.

References symbols_.

◆ operator<=>()

auto String::operator<=> ( const String 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 symbols_ member.

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

Member Data Documentation

◆ symbols_

std::vector<Symbol> String::symbols_
private

The finite sequence of symbols forming the string.

Definition at line 101 of file string.hpp.

Referenced by begin(), end(), get_str(), length(), String(), and String().


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