pointer_vector_variant_wrapper.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_CEREAL_POINTER_VECTOR_VARIANT_WRAPPER_HPP
14 #define MLPACK_CORE_CEREAL_POINTER_VECTOR_VARIANT_WRAPPER_HPP
15 
16 #include "pointer_wrapper.hpp"
19 
20 namespace cereal {
21 
22 // Forward declaration
23 template<typename... VariantTypes>
25 
34 template<typename... VariantTypes>
35 inline PointerVectorVariantWrapper<VariantTypes...>
36 make_vector_pointer_variant(std::vector<boost::variant<VariantTypes...>>& t)
37 {
38  return PointerVectorVariantWrapper<VariantTypes...>(t);
39 }
40 
48 template<typename... VariantTypes>
50 {
51  public:
53  std::vector<boost::variant<VariantTypes...>>& vecPointerVar)
54  : vectorPointerVariant(vecPointerVar)
55  {}
56 
57  template<class Archive>
58  void save(Archive& ar) const
59  {
60  size_t vecSize = vectorPointerVariant.size();
61  ar(CEREAL_NVP(vecSize));
62  for (size_t i = 0; i < vectorPointerVariant.size(); ++i)
63  {
64  ar(CEREAL_VARIANT_POINTER(vectorPointerVariant.at(i)));
65  }
66  }
67 
68  template<class Archive>
69  void load(Archive& ar)
70  {
71  size_t vecSize = 0;
72  ar(CEREAL_NVP(vecSize));
73  vectorPointerVariant.resize(vecSize);
74  for (size_t i = 0; i < vectorPointerVariant.size(); ++i)
75  {
76  ar(CEREAL_VARIANT_POINTER(vectorPointerVariant.at(i)));
77  }
78  }
79 
80  private:
81  std::vector<boost::variant<VariantTypes...>>& vectorPointerVariant;
82 };
83 
92 #define CEREAL_VECTOR_VARIANT_POINTER(T) cereal::make_vector_pointer_variant(T)
93 
94 } // namespace cereal
95 
96 #endif // CEREAL_POINTER_VECTOR_VARIANT_WRAPPER_HPP
97 
PointerVectorVariantWrapper(std::vector< boost::variant< VariantTypes... >> &vecPointerVar)
PointerVectorVariantWrapper< VariantTypes... > make_vector_pointer_variant(std::vector< boost::variant< VariantTypes... >> &t)
Serialize a std::vector of boost variants in which the variant in each boost variant is a raw pointer...
The objective of this class is to create a wrapper for a vector of boost::variant that holds pointer...
#define CEREAL_VARIANT_POINTER(T)
Cereal does not support the serialization of raw pointer.