aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/manager/SaveManager.h
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-11 14:21:34 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-11 14:21:34 +0100
commite6a5bb579d0969245f34119ef2489f47039c523e (patch)
treee8b0b922cd28d6f83d7bf59ea1b69bbb84d0fd04 /src/crepe/manager/SaveManager.h
parent7b8de90699aea153e73b5f2cee05c69b966b81be (diff)
parent78c4a8772526f40c531b5402b56932b0a41e22e8 (diff)
Merge branch 'master' into niels/remove_singleton
Diffstat (limited to 'src/crepe/manager/SaveManager.h')
-rw-r--r--src/crepe/manager/SaveManager.h32
1 files changed, 11 insertions, 21 deletions
diff --git a/src/crepe/manager/SaveManager.h b/src/crepe/manager/SaveManager.h
index 3d8c852..61a978d 100644
--- a/src/crepe/manager/SaveManager.h
+++ b/src/crepe/manager/SaveManager.h
@@ -1,9 +1,12 @@
#pragma once
+#include <functional>
#include <memory>
#include "../ValueBroker.h"
+#include "Manager.h"
+
namespace crepe {
class DB;
@@ -18,7 +21,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 +66,8 @@ public:
*/
bool has(const std::string & key);
-private:
- SaveManager();
+public:
+ SaveManager(Mediator & mediator);
virtual ~SaveManager() = default;
private:
@@ -89,26 +92,13 @@ private:
template <typename T>
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<void, std::function<void(void *)>> db = nullptr;
};
} // namespace crepe