13 #ifndef MLPACK_CORE_CEREAL_POINTER_VARIANT_WRAPPER_HPP 14 #define MLPACK_CORE_CEREAL_POINTER_VARIANT_WRAPPER_HPP 16 #include <cereal/archives/json.hpp> 17 #include <cereal/archives/portable_binary.hpp> 18 #include <cereal/archives/xml.hpp> 19 #include <cereal/types/boost_variant.hpp> 21 #include <boost/variant.hpp> 22 #include <boost/variant/variant_fwd.hpp> 23 #include <boost/variant/static_visitor.hpp> 30 template<
typename... VariantTypes>
40 template<
typename... VariantTypes>
47 template<
class Archive>
58 template<
typename... Types>
70 template<
typename Archive,
typename VariantType>
71 static void load_impl(Archive&
ar, VariantType& variant, std::true_type)
76 variant = loadVariant;
79 template<
typename Archive,
typename VariantType>
80 static void load_impl(Archive&
ar, VariantType& value, std::false_type)
88 template<
typename Archive,
typename VariantType>
89 static void load(Archive&
ar, VariantType& variant)
94 load_impl(ar, variant,
typename std::is_pointer<T>::type());
106 template<
typename... VariantTypes>
111 pointerVariant(pointerVar)
114 template<
class Archive>
118 int which = pointerVariant.which();
119 ar(CEREAL_NVP(which));
121 boost::apply_visitor(s, pointerVariant);
124 template<
class Archive>
129 ar(CEREAL_NVP(which));
133 using LoadFuncType = void(*)(Archive&, boost::variant<VariantTypes...>&);
136 if (which >=
int(
sizeof(loadFuncArray)/
sizeof(loadFuncArray[0])))
137 throw std::runtime_error(
"Invalid 'which' selector when" 138 "deserializing boost::variant");
140 loadFuncArray[which](
ar, pointerVariant);
144 boost::variant<VariantTypes...>& pointerVariant;
155 #define CEREAL_VARIANT_POINTER(T) cereal::make_pointer_variant(T) 159 #endif // CEREAL_POINTER_VARIANT_WRAPPER_HPP PointerVariantWrapper< VariantTypes... > make_pointer_variant(boost::variant< VariantTypes... > &t)
Serialize a boost variant in which the variant it self is a raw pointer.
void save(Archive &ar) const
void operator()(boost::variant< Types *... > &value) const
static void load_impl(Archive &ar, VariantType &value, std::false_type)
PointerVariantWrapper(boost::variant< VariantTypes... > &pointerVar)
#define CEREAL_POINTER(T)
Cereal does not support the serialization of raw pointer.
static void load_impl(Archive &ar, VariantType &variant, std::true_type)
save_visitor(Archive &ar)
The objective of this class is to create a wrapper for boost::variant.
static void load(Archive &ar, VariantType &variant)
void operator()(const T *value) const