Maze Builder Docs 8.10.23
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>
6#include <MazeBuilder/async_logger.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 private:
71 args_manager *_args{};
72 grid_manager *_grid_manager{};
73 processed_text_manager *_text_manager{};
74 randomizer *_rng{};
75 };
76
77 // Constructor / Destructor
78 explicit runtime_app();
79 ~runtime_app() override;
80
84 [[nodiscard]] std::string_view apply(std::string_view unformatted_args) noexcept override;
85
87 [[nodiscard]] std::string get_finished_text() noexcept;
88
89 // Print out logs to the console or any other configured sink
90 void dump_logs() noexcept;
91
92 private:
94 void register_states() const noexcept;
95
98 void visit_states() noexcept;
99
100 args_manager args_mapper;
101 grid_manager grid_mapper;
102 processed_text_manager processed_text_mapper;
103
104 randomizer rng;
105
106 std::mutex logging_mtx;
107 std::vector<std::string> received_logs;
108 std::string last_result_buffer;
109
110 std::unique_ptr<runtime_stack> runtime_stack_ptr;
111 };
112} // namespace mazes
113
114#endif // RUNTIME_APP_H
Class for enforcing contracts on the runtime.
Definition app_contract.h:12
Interface for the grid class.
Definition grid_interface.h:20
Provides random-number generating capabilities.
Definition randomizer.h:16
std::string_view apply(std::string_view unformatted_args) noexcept override
Applies the given unformatted string view to the runtime application.
std::string get_finished_text() noexcept
Returns the last generated grid used by apply(), if available.
Class representing the runtime stack of states in the maze builder application.
Definition runtime_stack.h:25
struct representing the context passed to states in the runtime_app stack
Definition runtime_app.h:34