-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserialize.h
75 lines (68 loc) · 1.53 KB
/
serialize.h
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
73
74
75
#pragma once
#include <cereal/types/vector.hpp>
#include <cereal/cereal.hpp>
#include <cereal/archives/json.hpp>
#include <fstream>
#include <functional>
using namespace std;
#define N(x) CEREAL_NVP(x)
#define META(...) template <class Archive> void serialize(Archive & ar){ar( __VA_ARGS__);}
//template<typename T>
//class Serialize {
//public:
static auto serializeSave = [](string fname, auto& x) {
std::ofstream os(fname, std::ios::binary);
if (os.good()) {
cereal::JSONOutputArchive archive(os);
archive(x);
}
};
static auto serializeLoad = [](string fname, auto& x) {
std::ifstream os(fname, std::ios::binary);
if (os.good()) {
cereal::JSONInputArchive archive(os);
archive(x);
}
};
//};
//void serializeSave(string fname,auto x) {
// std::ofstream os(fname, std::ios::binary);
// cereal::JSONOutputArchive archive(os);
// archive(x);
//}
//struct MyRecord
//{
// uint8_t x, y;
// shared_ptr<float> z;
//
//
// META(N(x), N(y), N(z));
//};
//
//struct SomeData
//{
// int32_t id;
// std::shared_ptr<std::unordered_map<uint32_t, MyRecord>> data;
//
// META(data);
//};
//
//int main()
//{
// std::ofstream os("out.txt", std::ios::binary);
// // std::ifstream os2("out.txt", std::ios::binary);
// cereal::JSONOutputArchive archive(os);
// // cereal::JSONInputArchive a2(os2);
// SomeData myData;
// // archive( myData );
// int x = 1, y = 2;
//
// MyRecord m, m2;
// float c = 5.4;
// m.x = 8; m.y = 1; m.z = make_shared<float>(c);
// archive(m);
// //auto t = make_tuple(m.x, m.y, m.z);
// //a2(m2);
//
// return 0;
//}