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>
53 void operator()(
const T* value)
const 58 template<
typename... Types>
59 void operator()(boost::variant<Types*...>& value)
const 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>
115 void save(Archive& ar)
const 118 int which = pointerVariant.which();
119 ar(CEREAL_NVP(which));
121 boost::apply_visitor(s, pointerVariant);
124 template<
class Archive>
125 void load(Archive& ar)
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.
Definition: pointer_variant_wrapper.hpp:42
Add an external serialization function for SpMat.
Definition: serialize_armadillo.hpp:26
#define CEREAL_POINTER(T)
Cereal does not support the serialization of raw pointer.
Definition: pointer_wrapper.hpp:96
The objective of this class is to create a wrapper for boost::variant.
Definition: pointer_variant_wrapper.hpp:31
Definition: pointer_variant_wrapper.hpp:48
Definition: pointer_variant_wrapper.hpp:68