From 91286f9dbb85fc2805345ba72468d5f145228be8 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 16 Feb 2022 19:31:24 +0100 Subject: refactor: create app class & simplify app options --- src/app/app.cpp | 12 +++++++----- src/app/app.hpp | 11 ++++++++++- src/app/options.cpp | 43 ------------------------------------------- src/app/options.hpp | 32 +++++--------------------------- 4 files changed, 22 insertions(+), 76 deletions(-) delete mode 100644 src/app/options.cpp (limited to 'src/app') diff --git a/src/app/app.cpp b/src/app/app.cpp index 0942c3e..d860b16 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -8,19 +8,21 @@ #include #include -void app_start(const AppOptions &app_options) +App::App(const AppOptions &options) : _options(options) {} + +void App::run() { - Matrix matrix(*app_options.maze_bounds() * + Matrix matrix(*_options.maze_bounds * Bounds({.width = 2U, .height = 2U}) + Bounds({.width = 1U, .height = 1U})); - matrix.fill(app_options.wall()); + matrix.fill(_options.wall); - auto start_pos = *app_options.start_coords() * Vector2({.x = 2U, .y = 2U}) + + auto start_pos = *_options.start_coords * Vector2({.x = 2U, .y = 2U}) + Vector2({.x = 1U, .y = 1U}); matrix_to_maze(&matrix, std::make_shared(start_pos), " ", - app_options.random_gen()); + _options.random_gen); matrix.print(); } diff --git a/src/app/app.hpp b/src/app/app.hpp index d02c405..cafb864 100644 --- a/src/app/app.hpp +++ b/src/app/app.hpp @@ -2,4 +2,13 @@ #include "app/options.hpp" -void app_start(const AppOptions &app_options); +class App +{ +public: + explicit App(const AppOptions &options); + + void run(); + +private: + const AppOptions &_options; +}; diff --git a/src/app/options.cpp b/src/app/options.cpp deleted file mode 100644 index cb6e20e..0000000 --- a/src/app/options.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "options.hpp" - -#include - -std::shared_ptr AppOptions::maze_bounds() const -{ - return _maze_bounds; -} - -void AppOptions::maze_bounds(std::shared_ptr maze_bounds) -{ - _maze_bounds = std::move(maze_bounds); -} - -std::shared_ptr AppOptions::start_coords() const -{ - return _start_coords; -} - -void AppOptions::start_coords(std::shared_ptr start_coords) -{ - _start_coords = std::move(start_coords); -} - -std::string_view AppOptions::wall() const -{ - return _wall; -} - -void AppOptions::wall(std::string_view wall) -{ - _wall = wall; -} - -std::shared_ptr AppOptions::random_gen() const -{ - return _random_gen; -} - -void AppOptions::random_gen(std::shared_ptr random_gen) -{ - _random_gen = std::move(random_gen); -} diff --git a/src/app/options.hpp b/src/app/options.hpp index 0023283..7e691e3 100644 --- a/src/app/options.hpp +++ b/src/app/options.hpp @@ -7,32 +7,10 @@ #include #include -/** - * Application options. - */ -class AppOptions +struct AppOptions { -public: - AppOptions() = default; - - [[nodiscard]] std::shared_ptr maze_bounds() const; - void maze_bounds(std::shared_ptr maze_bounds); - - [[nodiscard]] std::shared_ptr start_coords() const; - void start_coords(std::shared_ptr start_coords); - - [[nodiscard]] std::string_view wall() const; - void wall(std::string_view wall); - - [[nodiscard]] std::shared_ptr random_gen() const; - void random_gen(std::shared_ptr random_gen); - -private: - std::shared_ptr _maze_bounds = nullptr; - - std::shared_ptr _start_coords = nullptr; - - std::string_view _wall; - - std::shared_ptr _random_gen = nullptr; + std::shared_ptr maze_bounds; + std::shared_ptr start_coords; + std::string_view wall; + std::shared_ptr random_gen; }; -- cgit v1.2.3-18-g5258