32 #ifndef MADNESS_WORLD_CEREAL_ARCHIVE_H__INCLUDED
33 #define MADNESS_WORLD_CEREAL_ARCHIVE_H__INCLUDED
36 template <
typename Archive>
struct is_cereal_archive;
39 #ifdef MADNESS_HAS_CEREAL
40 # if ! __has_include(<cereal/cereal.hpp>)
41 # error "MADNESS_ENABLE_CEREAL is on, but cereal/cereal.hpp was not found."
45 #include <cereal/cereal.hpp>
46 #include <cereal/details/traits.hpp>
52 template <
typename Muesli>
54 mutable std::shared_ptr<Muesli>
58 CerealOutputArchive(Muesli &muesli) : muesli(&muesli, [](Muesli *) {}) {}
59 template <
typename Arg,
typename... RestOfArgs,
60 typename = std::enable_if_t<
61 !std::is_same<Muesli, std::decay_t<Arg>>::value>>
62 CerealOutputArchive(Arg &&
arg, RestOfArgs &&... rest_of_args)
63 : muesli(new Muesli(
std::forward<Arg>(
arg),
64 std::forward<RestOfArgs>(rest_of_args)...),
65 std::default_delete<Muesli>{}) {}
67 template <
class T,
class Cereal = Muesli>
68 inline std::enable_if_t<
70 !cereal::traits::is_text_archive<Cereal>::value,
72 store(
const T *t,
long n)
const {
73 const unsigned char *ptr = (
unsigned char *)t;
74 (*muesli)(cereal::binary_data(ptr,
sizeof(
T) * n));
77 template <
class T,
class Cereal = Muesli>
78 inline std::enable_if_t<
80 cereal::traits::is_text_archive<Cereal>::value,
void>
81 store(
const T *t,
long n)
const {
82 for (
long i = 0; i != n; ++i)
86 void open(std::size_t hint) {}
92 template <
typename Muesli>
class CerealInputArchive :
public BaseInputArchive {
93 std::shared_ptr<Muesli> muesli;
96 CerealInputArchive(Muesli &muesli) : muesli(&muesli, [](Muesli *) {}) {}
97 template <
typename Arg,
typename... RestOfArgs,
98 typename = std::enable_if_t<
99 !std::is_same<Muesli, std::decay_t<Arg>>::value>>
100 CerealInputArchive(Arg &&
arg, RestOfArgs &&... rest_of_args)
101 : muesli(new Muesli(
std::forward<Arg>(
arg),
102 std::forward<RestOfArgs>(rest_of_args)...),
103 std::default_delete<Muesli>{}) {}
105 template <
class T,
class Cereal = Muesli>
106 inline std::enable_if_t<
108 !cereal::traits::is_text_archive<Cereal>::value,
110 load(
T *t,
long n)
const {
111 (*muesli)(cereal::binary_data(t,
sizeof(
T) * n));
114 template <
class T,
class Cereal = Muesli>
115 inline std::enable_if_t<
117 cereal::traits::is_text_archive<Cereal>::value,
119 load(
T *t,
long n)
const {
120 for (
long i = 0; i != n; ++i)
124 void open(std::size_t hint) {}
125 void rewind()
const {}
130 template <
typename Muesli>
131 struct is_text_archive<
132 archive::CerealInputArchive<Muesli>,
133 std::enable_if_t<cereal::traits::is_text_archive<Muesli>::value>>
135 template <
typename Muesli>
136 struct is_text_archive<
137 archive::CerealOutputArchive<Muesli>,
138 std::enable_if_t<cereal::traits::is_text_archive<Muesli>::value>>
141 template <
typename Muesli,
typename T>
142 struct is_default_serializable_helper<
143 archive::CerealOutputArchive<Muesli>,
T,
144 std::enable_if_t<(is_trivially_serializable<T>::value &&
145 !cereal::traits::is_text_archive<Muesli>::value) ||
146 (cereal::traits::detail::count_output_serializers<T, Muesli>::value != 0 &&
147 cereal::traits::is_text_archive<Muesli>::value)>>
149 template <
typename Muesli,
typename T>
150 struct is_default_serializable_helper<
151 archive::CerealInputArchive<Muesli>,
T,
153 (is_trivially_serializable<T>::value &&
154 !cereal::traits::is_text_archive<Muesli>::value) ||
155 (cereal::traits::detail::count_input_serializers<T, Muesli>::value != 0 &&
156 cereal::traits::is_text_archive<Muesli>::value)>>
159 template <
typename Muesli>
160 struct is_cereal_archive<archive::CerealOutputArchive<Muesli>> : std::true_type {};
161 template <
typename Muesli>
162 struct is_cereal_archive<archive::CerealInputArchive<Muesli>> : std::true_type {};
165 template <
typename T>
166 struct is_archive<archive::CerealOutputArchive<T>, std::enable_if_t<std::is_base_of_v<cereal::detail::OutputArchiveBase, T>>> : std::true_type {};
167 template <
typename T>
168 struct is_archive<archive::CerealInputArchive<T>, std::enable_if_t<std::is_base_of_v<cereal::detail::InputArchiveBase, T>>> : std::true_type {};
169 template <
typename T>
170 struct is_output_archive<archive::CerealOutputArchive<T>, std::enable_if_t<std::is_base_of_v<cereal::detail::OutputArchiveBase, T>>> : std::true_type {};
171 template <
typename T>
172 struct is_input_archive<archive::CerealInputArchive<T>, std::enable_if_t<std::is_base_of_v<cereal::detail::InputArchiveBase, T>>> : std::true_type {};
173 template <
typename T>
174 struct is_archive<
T,
std::enable_if_t<std::is_base_of_v<cereal::detail::OutputArchiveBase, T>>> : std::true_type {};
175 template <
typename T>
176 struct is_archive<
T,
std::enable_if_t<std::is_base_of_v<cereal::detail::InputArchiveBase, T>>> : std::true_type {};
177 template <
typename T>
178 struct is_output_archive<
T,
std::enable_if_t<std::is_base_of_v<cereal::detail::OutputArchiveBase, T>>> : std::true_type {};
179 template <
typename T>
180 struct is_input_archive<
T,
std::enable_if_t<std::is_base_of_v<cereal::detail::InputArchiveBase, T>>> : std::true_type {};
Interface templates for the archives (serialization).
Base class for output archive classes.
Definition: archive.h:382
auto T(World &world, response_space &f) -> response_space
Definition: global_functions.cc:34
Tensor< typename Tensor< T >::scalar_type > arg(const Tensor< T > &t)
Return a new tensor holding the argument of each element of t (complex types only)
Definition: tensor.h:2502
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
void load(Function< T, NDIM > &f, const std::string name)
Definition: mra.h:2751
Definition: cereal_archive.h:187
Definition: type_traits.h:220