summaryrefslogtreecommitdiff
path: root/lib/jsonParse-persistence.h
blob: 6449f7b7c9765d8155c0c5d72b54e59507cb33d6 (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 "persistence.h" // IWYU pragma: export
#include <functional>
#include <iosfwd>
#include <memory>
#include <string>

namespace Persistence {
	class JsonParsePersistence : 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