Skip to content

Commit 8eefeb9

Browse files
committed
XXX Needs good cleanup. It loads stuff!
1 parent b9570ff commit 8eefeb9

File tree

5 files changed

+424
-104
lines changed

5 files changed

+424
-104
lines changed

immer/extra/archive/json/inline.hpp

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// https://github.com/LowCostCustoms/cereal-inline/blob/master/cereal_inline.hpp
2+
3+
#pragma once
4+
5+
#include "cereal/cereal.hpp"
6+
#include "cereal/details/traits.hpp"
7+
8+
#include <type_traits>
9+
10+
#ifndef CEREAL_LOAD_INLINE_FUNCTION_NAME
11+
#define CEREAL_LOAD_INLINE_FUNCTION_NAME load_inline
12+
#endif // CEREAL_LOAD_INLINE_FUNCTION_NAME
13+
14+
#ifndef CEREAL_SAVE_INLINE_FUNCTION_NAME
15+
#define CEREAL_SAVE_INLINE_FUNCTION_NAME save_inline
16+
#endif // CEREAL_SAVE_INLINE_FUNCTION_NAME
17+
18+
/**
19+
* @namespace cereal
20+
* Cereal serialization methods
21+
*/
22+
namespace cereal {
23+
24+
// you can use it later
25+
#define PROCESS_IF(name) \
26+
traits::EnableIf<(!traits::is_specialized<T, A>::value && \
27+
traits::has_##name<T, A>::value) || \
28+
traits::is_specialized_##name<T, A>::value> = \
29+
traits::sfinae
30+
31+
/**
32+
* Loads `flat` cereal value (without need to process prologue and epilogue)
33+
*/
34+
template <class A, class T, PROCESS_IF(member_serialize)>
35+
void CEREAL_LOAD_INLINE_FUNCTION_NAME(A& archive, T& value)
36+
{
37+
value.CEREAL_SERIALIZE_FUNCTION_NAME(archive);
38+
}
39+
40+
template <class A, class T, PROCESS_IF(non_member_serialize)>
41+
void CEREAL_LOAD_INLINE_FUNCTION_NAME(A& archive, T& value)
42+
{
43+
CEREAL_SERIALIZE_FUNCTION_NAME(archive, value);
44+
}
45+
46+
template <class A, class T, PROCESS_IF(member_load)>
47+
void CEREAL_LOAD_INLINE_FUNCTION_NAME(A& archive, T& value)
48+
{
49+
value.CEREAL_LOAD_FUNCTION_NAME(archive);
50+
}
51+
52+
template <class A, class T, PROCESS_IF(non_member_load)>
53+
void CEREAL_LOAD_INLINE_FUNCTION_NAME(A& archive, T& value)
54+
{
55+
CEREAL_LOAD_FUNCTION_NAME(archive, value);
56+
}
57+
58+
/**
59+
* Saves `flat` cereal value (without prologue and epilogue)
60+
*/
61+
template <class A, class T, PROCESS_IF(member_serialize)>
62+
void CEREAL_SAVE_INLINE_FUNCTION_NAME(A& archive, const T& value)
63+
{
64+
const_cast<T&>(value).CEREAL_SERIALIZE_FUNCTION_NAME(archive);
65+
}
66+
67+
template <class A, class T, PROCESS_IF(non_member_serialize)>
68+
void CEREAL_SAVE_INLINE_FUNCTION_NAME(A& archive, const T& value)
69+
{
70+
CEREAL_SERIALIZE_FUNCTION_NAME(archive, const_cast<T&>(value));
71+
}
72+
73+
template <class A, class T, PROCESS_IF(member_save)>
74+
void CEREAL_SAVE_INLINE_FUNCTION_NAME(A& archive, const T& value)
75+
{
76+
value.CEREAL_SAVE_FUNCTION_NAME(archive);
77+
}
78+
79+
template <class A, class T, PROCESS_IF(non_member_save)>
80+
void CEREAL_SAVE_INLINE_FUNCTION_NAME(A& archive, const T& value)
81+
{
82+
CEREAL_SAVE_FUNCTION_NAME(archive, value);
83+
}
84+
85+
// nope ;)
86+
#undef PROCESS_IF
87+
88+
} // namespace cereal

0 commit comments

Comments
 (0)