aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/SaveManager.h
blob: a1f239df97056d04b3e577cd130246c1c4cda051 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once

#include <memory>

#include "../ValueBroker.h"

namespace crepe {
class DB;
}

namespace crepe::api {

class SaveManager {
public:
	//! Get a reference to a value and initialize it with a value if it does not yet exist
	template <typename T>
	ValueBroker<T> get(const std::string & key, const T & default_value);

	//! Get a reference to a value
	template <typename T>
	ValueBroker<T> get(const std::string & key);

	//! Set a value directly
	template <typename T>
	void set(const std::string & key, const T & value);

	//! Check if the save file has a value for this \c key
	bool has(const std::string & key);

private:
	SaveManager();
	virtual ~SaveManager() = default;

private:
	template <typename T>
	std::string serialize(const T &);

	template <typename T>
	T deserialize(const std::string &);

public:
	// singleton
	static SaveManager & get_instance();
	SaveManager(const SaveManager &) = delete;
	SaveManager(SaveManager &&) = delete;
	SaveManager & operator = (const SaveManager &) = delete;
	SaveManager & operator = (SaveManager &&) = delete;

private:
	static DB & get_db();
};

}