18 #ifndef _XDRPP_CEREAL_H_HEADER_INCLUDED_ 19 #define _XDRPP_CEREAL_H_HEADER_INCLUDED_ 1 21 #include <type_traits> 22 #include <cereal/cereal.hpp> 23 #include <cereal/types/array.hpp> 24 #include <cereal/types/string.hpp> 25 #include <cereal/types/memory.hpp> 26 #include <cereal/types/vector.hpp> 27 #include <cereal/details/traits.hpp> 31 class JSONInputArchive;
32 class JSONOutputArchive;
33 class XMLOutputArchive;
34 class XMLInputArchive;
40 template<
typename Archive,
typename T>
typename 41 std::enable_if<xdr_traits<T>::is_class>::type
42 save(Archive &ar,
const T &t)
44 xdr_traits<T>::save(ar, t);
47 template<
typename Archive,
typename T>
typename 48 std::enable_if<xdr_traits<T>::is_class>::type
49 load(Archive &ar, T &t)
51 xdr_traits<T>::load(ar, t);
54 template<
typename Archive,
typename T>
typename 55 std::enable_if<cereal::traits::is_output_serializable<
56 cereal::BinaryData<char *>,Archive>::value
57 && xdr_traits<T>::is_bytes>::type
58 save(Archive &ar,
const T &t)
60 if (xdr_traits<T>::variable_length)
61 ar(cereal::make_size_tag(static_cast<cereal::size_type>(t.size())));
62 ar(cereal::binary_data(const_cast<char *>(
63 reinterpret_cast<const char *>(t.data())), t.size()));
66 template<
typename Archive,
typename T>
typename 67 std::enable_if<cereal::traits::is_input_serializable<
68 cereal::BinaryData<char *>,Archive>::value
69 && xdr_traits<T>::is_bytes>::type
70 load(Archive &ar, T &t)
72 cereal::size_type size;
73 if (xdr_traits<T>::variable_length)
74 ar(cereal::make_size_tag(size));
78 t.resize(static_cast<std::uint32_t>(size));
79 ar(cereal::binary_data(t.data(), size));
83 template<
typename Archive>
struct nvp_adapter {
84 template<
typename T>
static void 85 apply(Archive &ar, T &&t,
const char *field) {
87 ar(cereal::make_nvp(field, std::forward<T>(t)));
89 ar(std::forward<T>(t));
92 template<u
int32_t N>
static void 93 apply(Archive &ar, xstring<N> &s,
const char *field) {
94 apply(ar, field, static_cast<std::string &>(s));
96 template<u
int32_t N>
static void 97 apply(Archive &ar,
const xstring<N> &s,
const char *field) {
98 apply(ar, field, static_cast<const std::string &>(s));
104 #define CEREAL_ARCHIVE_TAKES_NAME(archive) \ 105 template<> struct archive_adapter<cereal::archive> \ 106 : detail::nvp_adapter<cereal::archive> {} 107 CEREAL_ARCHIVE_TAKES_NAME(JSONInputArchive);
108 CEREAL_ARCHIVE_TAKES_NAME(JSONOutputArchive);
109 CEREAL_ARCHIVE_TAKES_NAME(XMLOutputArchive);
110 CEREAL_ARCHIVE_TAKES_NAME(XMLInputArchive);
111 #undef CEREAL_ARCHIVE_TAKES_NAME 118 using xdr::detail::load;
119 using xdr::detail::save;
122 #endif // !_XDRPP_CEREAL_H_HEADER_INCLUDED_ Type definitions for xdrc compiler output.
Most of the xdrpp library is encapsulated in the xdr namespace.