summaryrefslogtreecommitdiff
path: root/lib/jsonParse-persistance.h
blob: bea93e0b1fc1d7dced74795c6d4425ec58ad4828 (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
#ifndef JSONPARSE_PERSISTANCE
#define JSONPARSE_PERSISTANCE

#include "jsonParse.h" // IWYU pragma: export
#include "persistance.h" // IWYU pragma: export
#include <functional>
#include <iosfwd>
#include <memory>
#include <string>

namespace Persistanace {
	class JsonParsePersistance : public json::jsonParser {
	public:
		template<typename T>
		inline T
		loadState(std::istream & in)
		{
			T t {};
			stk.push(std::make_unique<SelectionT<T>>(std::ref(t)));
			loadState(in);
			return t;
		}

	protected:
		void loadState(std::istream & in);

		void BeginObject() override;
		void BeginArray() override;
		void PushBoolean(bool value) override;
		void PushNumber(float value) override;
		void PushNull() override;
		void PushText(std::string && value) override;
		void PushKey(std::string && k) override;
		void EndArray() override;
		void EndObject() override;

		Stack stk;

		template<typename T> inline void PushValue(T && value);
		inline SelectionPtr & current();
	};
}

#endif