summaryrefslogtreecommitdiff
path: root/slicer/json/serializer.h
blob: 2e54a2dd77b79c5bb74bd390cec13ea1ecd571bb (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once

#include <filesystem>
#include <fstream>
#include <iosfwd>
#include <jsonpp.h>
#include <slicer/modelParts.h>
#include <slicer/serializer.h>
#include <string>
#include <visibility.h>

namespace Slicer {
	class DLL_PUBLIC JsonValueSerializer : public Serializer {
	public:
		JsonValueSerializer() = default;
		~JsonValueSerializer() override;
		SPECIAL_MEMBERS_DEFAULT(JsonValueSerializer);

		void Serialize(ModelPartForRootParam) override;

	protected:
		json::Value value;
	};

	class DLL_PUBLIC JsonStreamSerializer : public JsonValueSerializer {
	public:
		explicit JsonStreamSerializer(std::ostream &);

		void Serialize(ModelPartForRootParam) override;

	protected:
		std::ostream & strm;
	};

	class DLL_PUBLIC JsonFileSerializer : public JsonStreamSerializer {
	public:
		explicit JsonFileSerializer(const std::filesystem::path &);

	protected:
		std::ofstream strm;
	};

	class DLL_PUBLIC JsonStreamDeserializer : public Deserializer {
	public:
		explicit JsonStreamDeserializer(std::istream &);

		void Deserialize(ModelPartForRootParam) override;

	protected:
		std::istream & strm;
	};

	class DLL_PUBLIC JsonFileDeserializer : public Deserializer {
	public:
		explicit JsonFileDeserializer(std::filesystem::path);

		void Deserialize(ModelPartForRootParam) override;

	protected:
		const std::filesystem::path path;
	};

	class DLL_PUBLIC JsonValueDeserializer : public Deserializer {
	public:
		explicit JsonValueDeserializer(const json::Value &);

		void Deserialize(ModelPartForRootParam) override;

	protected:
		const json::Value & value;
	};
}