diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-07 15:29:33 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-07 15:29:33 +0100 |
commit | f19f37ae3eff84161f86e62a26fbd8b68f8f91a9 (patch) | |
tree | 492ab107b375e51eef084b7be0f608b7f4fae319 /src/crepe/manager/SaveManager.h | |
parent | fdb4c99e139a264d4e15e6913a3756fc6cccb2f2 (diff) |
make SaveManager no longer a singleton
Diffstat (limited to 'src/crepe/manager/SaveManager.h')
-rw-r--r-- | src/crepe/manager/SaveManager.h | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/src/crepe/manager/SaveManager.h b/src/crepe/manager/SaveManager.h index 3d8c852..d13a97a 100644 --- a/src/crepe/manager/SaveManager.h +++ b/src/crepe/manager/SaveManager.h @@ -4,6 +4,8 @@ #include "../ValueBroker.h" +#include "Manager.h" + namespace crepe { class DB; @@ -18,7 +20,7 @@ class DB; * * The underlying database is a key-value store. */ -class SaveManager { +class SaveManager : public Manager { public: /** * \brief Get a read/write reference to a value and initialize it if it does not yet exist @@ -63,8 +65,8 @@ public: */ bool has(const std::string & key); -private: - SaveManager(); +public: + SaveManager(Mediator & mediator); virtual ~SaveManager() = default; private: @@ -90,25 +92,18 @@ private: T deserialize(const std::string & value) const noexcept; public: - // singleton - static SaveManager & get_instance(); SaveManager(const SaveManager &) = delete; SaveManager(SaveManager &&) = delete; SaveManager & operator=(const SaveManager &) = delete; SaveManager & operator=(SaveManager &&) = delete; +protected: + //! Create or return DB + virtual DB & get_db(); + private: - /** - * \brief Create an instance of DB and return its reference - * - * \returns DB instance - * - * This function exists because DB is a facade class, which can't directly be used in the API - * without workarounds - * - * TODO: better solution - */ - static DB & get_db(); + //! Database + std::unique_ptr<DB> db = nullptr; }; } // namespace crepe |