Maze Builder Docs 8.2.1
Loading...
Searching...
No Matches
runtime_app.h
Go to the documentation of this file.
1#ifndef RUNTIME_APP_H
2#define RUNTIME_APP_H
3
4#include <MazeBuilder/args.h>
12
13#include <memory>
14#include <mutex>
15#include <optional>
16#include <string>
17#include <vector>
18
21namespace mazes
22{
23 class grid_interface;
24 class runtime_stack;
25
27 class runtime_app final : public app_contract, public singleton_base<runtime_app>
28 {
29 friend class singleton_base<runtime_app>;
30
31 public:
33 struct context final
34 {
35 [[nodiscard]] args_manager *get_args_manager() const noexcept { return _args; }
36
37 context &with_args_manager(args_manager &am) noexcept
38 {
39 _args = &am;
40 return *this;
41 }
42
43 [[nodiscard]] grid_manager *get_grid_manager() const noexcept { return _grid_manager; }
44
45 context &with_grid_manager(grid_manager &g) noexcept
46 {
47 _grid_manager = &g;
48 return *this;
49 }
50
51 [[nodiscard]] processed_text_manager *get_text_manager() const noexcept
52 {
53 return _text_manager;
54 }
55
56 context &with_text_manager(processed_text_manager &ptm) noexcept
57 {
58 _text_manager = &ptm;
59 return *this;
60 }
61
62 [[nodiscard]] randomizer *get_rng() const noexcept { return _rng; }
63
64 context &with_rng(randomizer &r) noexcept
65 {
66 _rng = &r;
67 return *this;
68 }
69
70 [[nodiscard]] const std::string *get_raw_input() const noexcept { return _raw_input; }
71
72 context &with_raw_input(const std::string &raw_input) noexcept
73 {
74 _raw_input = &raw_input;
75 return *this;
76 }
77
78 private:
79 args_manager *_args{};
80 grid_manager *_grid_manager{};
81 processed_text_manager *_text_manager{};
82 randomizer *_rng{};
83 const std::string *_raw_input{};
84 };
85
86 // Constructor / Destructor
87 explicit runtime_app();
88 ~runtime_app() override;
89
93 [[nodiscard]] std::string_view apply(std::string_view unformatted_sv) noexcept override;
94
96 [[nodiscard]] const grid_interface *get_last_grid() const noexcept;
97
98 private:
100 void register_states() const noexcept;
101
107 [[nodiscard]] std::string_view visit_states(const std::optional<args> &arguments) noexcept;
108
109 args_manager m_args_mapper;
110 grid_manager m_grid_mapper;
111 processed_text_manager m_processed_text_mapper;
112 randomizer m_rng;
113
114 async_logger m_logger;
115 std::mutex m_logging_mtx;
116 std::vector<std::string> m_received_logs;
117
118 std::string m_last_result;
119 std::string m_current_input;
120 grid_identifier m_last_grid_id{grid_identifier::BASIC};
121 std::unique_ptr<runtime_stack> runtime_stack_ptr;
122 };
123} // namespace mazes
124
125#endif // RUNTIME_APP_H
Class for enforcing contracts on the runtime.
Definition app_contract.h:12
Command-line argument handler with JSON support.
Definition args.h:19
Asynchronous logger class.
Definition async_logger.h:24
Interface for the grid class.
Definition grid_interface.h:20
Provides random-number generating capabilities.
Definition randomizer.h:15
The main application class for the maze builder, responsible for managing the runtime stack and resou...
Definition runtime_app.h:28
std::string_view apply(std::string_view unformatted_sv) noexcept override
Applies the given unformatted string view to the runtime application.
const grid_interface * get_last_grid() const noexcept
Returns the last generated grid used by apply(), if available.
Base class for implementing the singleton pattern.
Definition singleton_base.h:14
struct representing the context passed to states in the runtime_app stack
Definition runtime_app.h:34