MTMS main
Modern Turing Machine Simulator
Loading...
Searching...
No Matches
project.hpp
Go to the documentation of this file.
1
11#ifndef PROJECT_HPP
12#define PROJECT_HPP
13
14#include "tm.hpp"
15
16#include <filesystem>
17#include <memory>
18#include <string>
19#include <toml++/toml.hpp>
20#include <unordered_map>
21#include <unordered_set>
22
23#define TOML_HEADER_ONLY 1
24
31{
32 public:
33 Project() noexcept : name_("Untitled TM") {}
34
40 bool load_project(const std::filesystem::path &filepath) noexcept(false);
41
47 [[nodiscard]] bool save_project(const std::filesystem::path &filepath) const noexcept(false);
48
53 [[nodiscard]] bool has_active_machine() const noexcept { return this->machine_ != nullptr; }
54
59 [[nodiscard]] std::shared_ptr<TuringMachine> get_machine() noexcept { return this->machine_; }
60
65 [[nodiscard]] std::string_view get_name() const noexcept { return this->name_; }
66
67 private:
68 std::shared_ptr<TuringMachine> machine_;
69 std::string name_;
70 std::string description_;
71
77 bool parse_metadata(const toml::table &config) noexcept;
78
89 static bool parse_states(
90 const toml::table &config,
91 std::set<State> &parsed_states,
92 State &initial_state,
93 std::unordered_map<std::string, State> &state_map
94 ) noexcept(false);
95
104 static bool parse_alphabets(
105 const toml::table &config,
106 Alphabet &input_alpha,
107 Alphabet &tape_alpha
108 ) noexcept(false);
109
120 static bool parse_transitions(
121 const toml::table &config,
122 std::size_t tape_count,
123 const std::unordered_map<std::string, State> &state_map,
124 const std::shared_ptr<TuringMachine> &machine,
125 std::unordered_map<std::string, std::vector<std::string>> &graph
126 ) noexcept(false);
127
135 static std::unordered_set<std::string> compute_reachability(
136 const std::string &start_state,
137 const std::unordered_map<std::string, std::vector<std::string>> &graph
138 ) noexcept(false);
139
147 static bool validate_machine_structure(
148 const std::set<State> &parsed_states,
149 const std::unordered_set<std::string> &reachable,
150 const std::unordered_map<std::string, std::vector<std::string>> &graph
151 ) noexcept(false);
152};
153
154#endif // PROJECT_HPP
Represents the formal alphabet ( or ) of a Turing Machine.
Definition alphabet.hpp:27
Orchestrates configuration ingestion and state saves, abstraction layer bridging core computation wit...
Definition project.hpp:31
std::string description_
Project description block or summary.
Definition project.hpp:70
static bool validate_machine_structure(const std::set< State > &parsed_states, const std::unordered_set< std::string > &reachable, const std::unordered_map< std::string, std::vector< std::string > > &graph) noexcept(false)
Verifies structural integrity rules against isolated or broken nodes.
Definition project.cpp:235
static bool parse_transitions(const toml::table &config, std::size_t tape_count, const std::unordered_map< std::string, State > &state_map, const std::shared_ptr< TuringMachine > &machine, std::unordered_map< std::string, std::vector< std::string > > &graph) noexcept(false)
Decodes the matrix table containing legal execution step pathways.
Definition project.cpp:107
bool parse_metadata(const toml::table &config) noexcept
Extracts project identification block from TOML file.
Definition project.cpp:20
static bool parse_alphabets(const toml::table &config, Alphabet &input_alpha, Alphabet &tape_alpha) noexcept(false)
Validates and builds formal inclusion alphabets (Sigma and Gamma matrices).
Definition project.cpp:62
bool load_project(const std::filesystem::path &filepath) noexcept(false)
Parses a TM configuration file using toml++ and instantiates the TuringMachine.
Definition project.cpp:265
static std::unordered_set< std::string > compute_reachability(const std::string &start_state, const std::unordered_map< std::string, std::vector< std::string > > &graph) noexcept(false)
Computes reaching pathways from the start state over the adjacency graph via DFS.
Definition project.cpp:203
bool has_active_machine() const noexcept
Checks if there is a valid Turing Machine instance active.
Definition project.hpp:53
std::string_view get_name() const noexcept
Retrieves the project's friendly configuration name.
Definition project.hpp:65
std::shared_ptr< TuringMachine > machine_
Active Turing Machine computation engine backend.
Definition project.hpp:68
static bool parse_states(const toml::table &config, std::set< State > &parsed_states, State &initial_state, std::unordered_map< std::string, State > &state_map) noexcept(false)
Parses and instantiates structural computational states from TOML configuration array.
Definition project.cpp:27
std::shared_ptr< TuringMachine > get_machine() noexcept
Retrieves the pointer to the active Turing Machine instance.
Definition project.hpp:59
bool save_project(const std::filesystem::path &filepath) const noexcept(false)
Exports the current machine configuration snapshot back to a TOML file.
Definition project.cpp:331
std::string name_
Friendly identifier extracted from config metadata.
Definition project.hpp:69
Project() noexcept
Definition project.hpp:33
Represents a single state in the finite set of states (Q) of the Turing Machine.
Definition state.hpp:26