32#ifndef MADNESS_WORLD_CEREAL_ARCHIVE_H__INCLUDED
33#define MADNESS_WORLD_CEREAL_ARCHIVE_H__INCLUDED
36template <
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>
52template <
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) {}
92template <
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 {}
130template <
typename Muesli>
131struct is_text_archive<
132 archive::CerealInputArchive<Muesli>,
133 std::enable_if_t<cereal::traits::is_text_archive<Muesli>::value>>
135template <
typename Muesli>
136struct is_text_archive<
137 archive::CerealOutputArchive<Muesli>,
138 std::enable_if_t<cereal::traits::is_text_archive<Muesli>::value>>
141template <
typename Muesli,
typename T>
142struct 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)>>
149template <
typename Muesli,
typename T>
150struct 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)>>
159template <
typename Muesli>
160struct is_cereal_archive<archive::CerealOutputArchive<Muesli>> : std::true_type {};
161template <
typename Muesli>
162struct is_cereal_archive<archive::CerealInputArchive<Muesli>> : std::true_type {};
166struct is_archive<archive::CerealOutputArchive<T>, std::enable_if_t<std::is_base_of_v<cereal::detail::OutputArchiveBase, T>>> : std::true_type {};
168struct is_archive<archive::CerealInputArchive<T>, std::enable_if_t<std::is_base_of_v<cereal::detail::InputArchiveBase, T>>> : std::true_type {};
170struct is_output_archive<archive::CerealOutputArchive<T>, std::enable_if_t<std::is_base_of_v<cereal::detail::OutputArchiveBase, T>>> : std::true_type {};
172struct is_input_archive<archive::CerealInputArchive<T>, std::enable_if_t<std::is_base_of_v<cereal::detail::InputArchiveBase, T>>> : std::true_type {};
174struct is_archive<
T,
std::enable_if_t<std::is_base_of_v<cereal::detail::OutputArchiveBase, T>>> : std::true_type {};
176struct is_archive<
T,
std::enable_if_t<std::is_base_of_v<cereal::detail::InputArchiveBase, T>>> : std::true_type {};
178struct is_output_archive<
T,
std::enable_if_t<std::is_base_of_v<cereal::detail::OutputArchiveBase, T>>> : std::true_type {};
180struct 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
void load(World &world, real_function_6d &f, std::string filename)
Definition helium_exact.cc:369
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
Definition cereal_archive.h:187
Definition type_traits.h:227