From b36d072ad7a7b9c6e30fcb25d6bbb001a8393468 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 10 Apr 2022 17:20:49 +0200 Subject: refactor: add factory class & make DI container return unique ptrs --- src/interfaces/game.hpp | 10 +++++++++- src/interfaces/generation_tracker.hpp | 5 ++++- src/interfaces/matrix.hpp | 4 ++-- src/interfaces/randomization.hpp | 4 +++- src/interfaces/scene.hpp | 6 ++++-- src/interfaces/status_updater.hpp | 5 +++-- src/interfaces/statusline.hpp | 6 ++++-- 7 files changed, 29 insertions(+), 11 deletions(-) (limited to 'src/interfaces') diff --git a/src/interfaces/game.hpp b/src/interfaces/game.hpp index 46d79e4..0f5c895 100644 --- a/src/interfaces/game.hpp +++ b/src/interfaces/game.hpp @@ -5,6 +5,8 @@ #include "interfaces/scene.hpp" #include "interfaces/window.hpp" +#include "DI/factory.hpp" + #include #include @@ -24,6 +26,12 @@ public: -> std::unordered_map> = 0; }; -using IGameFactory = std::shared_ptr (*)( +/* +using IGameFactory = std::unique_ptr (*)( const std::shared_ptr &window, const std::shared_ptr &scene, const std::shared_ptr &cursor_controller); + */ + +using IGameFactory = Factory( + const std::shared_ptr &window, const std::shared_ptr &scene, + const std::shared_ptr &cursor_controller)>; diff --git a/src/interfaces/generation_tracker.hpp b/src/interfaces/generation_tracker.hpp index fcd2426..fd2c130 100644 --- a/src/interfaces/generation_tracker.hpp +++ b/src/interfaces/generation_tracker.hpp @@ -1,5 +1,7 @@ #pragma once +#include "DI/factory.hpp" + #include #include @@ -16,4 +18,5 @@ public: virtual void set_is_paused(bool is_paused) noexcept = 0; }; -using IGenerationTrackerFactory = std::shared_ptr (*)(bool is_paused); +using IGenerationTrackerFactory = + Factory(bool is_paused)>; diff --git a/src/interfaces/matrix.hpp b/src/interfaces/matrix.hpp index edcf935..7fea003 100644 --- a/src/interfaces/matrix.hpp +++ b/src/interfaces/matrix.hpp @@ -1,8 +1,8 @@ #pragma once +#include "DI/factory.hpp" #include "engine/data/bounds.hpp" #include "engine/data/vector2.hpp" - #include "engine/matrix_iterator.hpp" #include @@ -39,4 +39,4 @@ public: }; template -using IMatrixFactory = std::shared_ptr> (*)(const Bounds &bounds); +using IMatrixFactory = Factory>(const Bounds &bounds)>; diff --git a/src/interfaces/randomization.hpp b/src/interfaces/randomization.hpp index 8b1631c..4abad1d 100644 --- a/src/interfaces/randomization.hpp +++ b/src/interfaces/randomization.hpp @@ -1,5 +1,7 @@ #pragma once +#include "DI/factory.hpp" + #include // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) @@ -28,4 +30,4 @@ public: }; using IRandomNumberGeneratorFactory = - std::shared_ptr (*)(const uint32_t &seed); + Factory(const uint32_t &seed)>; diff --git a/src/interfaces/scene.hpp b/src/interfaces/scene.hpp index 3960985..0a51b6e 100644 --- a/src/interfaces/scene.hpp +++ b/src/interfaces/scene.hpp @@ -4,6 +4,8 @@ #include "interfaces/matrix.hpp" #include "interfaces/window.hpp" +#include "DI/factory.hpp" + #include // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) @@ -20,6 +22,6 @@ public: -> const std::shared_ptr> & = 0; }; -using ISceneFactory = std::shared_ptr (*)( +using ISceneFactory = Factory( const std::shared_ptr &cursor_controller, - const std::shared_ptr &window); + const std::shared_ptr &window)>; diff --git a/src/interfaces/status_updater.hpp b/src/interfaces/status_updater.hpp index 2770d5e..e5081ef 100644 --- a/src/interfaces/status_updater.hpp +++ b/src/interfaces/status_updater.hpp @@ -4,6 +4,7 @@ #include "interfaces/statusline.hpp" #include "interfaces/subscriber.hpp" +#include "DI/factory.hpp" #include "engine/data/vector2.hpp" #include @@ -15,6 +16,6 @@ public: void update(const Vector2 &context) noexcept override = 0; }; -using IStatusUpdaterFactory = std::shared_ptr (*)( +using IStatusUpdaterFactory = Factory( const std::shared_ptr &statusline, - const std::shared_ptr &generation_tracker); + const std::shared_ptr &generation_tracker)>; diff --git a/src/interfaces/statusline.hpp b/src/interfaces/statusline.hpp index f07c1a0..bbd8e4a 100644 --- a/src/interfaces/statusline.hpp +++ b/src/interfaces/statusline.hpp @@ -3,6 +3,8 @@ #include "interfaces/cursor.hpp" #include "interfaces/window.hpp" +#include "DI/factory.hpp" + #include enum StatusLineSection @@ -23,6 +25,6 @@ public: const std::string_view &str) noexcept = 0; }; -using IStatusLineFactory = std::shared_ptr (*)( +using IStatusLineFactory = Factory( const std::shared_ptr &cursor_controller, - const std::shared_ptr &window); + const std::shared_ptr &window)>; -- cgit v1.2.3-18-g5258