16 #ifndef MLPACK_CORE_UTIL_SERIALIZATION_SHIM_HPP
17 #define MLPACK_CORE_UTIL_SERIALIZATION_SHIM_HPP
20 #include <boost/serialization/serialization.hpp>
21 #include <boost/archive/xml_oarchive.hpp>
37 HasSerializeCheck<T, void(T::*)(boost::archive::xml_oarchive&,
38 const unsigned int)>::
value ||
40 HasSerializeCheck<T,
void(*)(boost::archive::xml_oarchive&,
41 const unsigned int)>::
value;
50 template<
typename U,
typename V,
typename W>
struct check;
51 template<
typename U>
static yes&
chk(
53 typename boost::enable_if<boost::is_class<U>>::type*,
55 template<
typename >
static no&
chk(...);
57 static const bool value = (
sizeof(chk<T>(0)) ==
sizeof(
yes));
95 const std::string& name,
124 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
129 const std::string& name,
131 typename boost::disable_if<boost::is_pointer<T>>::type* = 0)
133 return boost::serialization::make_nvp(name.c_str(), t);
159 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
164 const std::string& name,
167 return boost::serialization::make_nvp(name.c_str(),
194 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
199 const std::string& name,
202 return boost::serialization::make_nvp(name.c_str(), t);
216 const std::string& name,
233 const std::string& name,
264 t(t), len(len), name(name) { }
281 t(t), len(len), name(name) { }
300 template<
typename Archive>
303 t.Serialize(ar, version);
321 template<
typename Archive>
325 for (
size_t i = 0; i <
len; ++i)
344 template<
typename Archive>
347 ar & boost::serialization::make_array(
t,
len);
369 template<
typename Archive,
typename T>
370 Archive& operator<<(Archive& ar, FirstShim<T> t)
373 return (ar << boost::serialization::make_nvp(t.name.c_str(), sh));
383 template<
typename Archive,
typename T>
387 return (ar & boost::serialization::make_nvp(t.name.c_str(), sh));
397 template<
typename Archive,
typename T>
401 return (ar >> boost::serialization::make_nvp(t.name.c_str(), sh));
411 template<
typename Archive,
typename T>
412 Archive& operator<<(Archive& ar, FirstArrayShim<T> t)
415 return (ar << boost::serialization::make_nvp(t.name.c_str(), sh));
425 template<
typename Archive,
typename T>
429 return (ar & boost::serialization::make_nvp(t.
name.c_str(), sh));
439 template<
typename Archive,
typename T>
443 return (ar >> boost::serialization::make_nvp(t.
name.c_str(), sh));
453 template<
typename Archive,
typename T>
454 Archive& operator<<(Archive& ar, FirstNormalArrayShim<T> t)
457 return (ar << boost::serialization::make_nvp(t.name.c_str(), sh));
467 template<
typename Archive,
typename T>
471 return (ar & boost::serialization::make_nvp(t.
name.c_str(), sh));
481 template<
typename Archive,
typename T>
485 return (ar >> boost::serialization::make_nvp(t.
name.c_str(), sh));
492 namespace serialization {
498 template<
typename Archive,
typename T>
503 T* tptr =
reinterpret_cast<T*
>(&t);
504 tptr->Serialize(ar, version);
FirstArrayShim< T > CreateArrayNVP(T *t, const size_t len, const std::string &name, typename boost::enable_if< HasSerialize< T >>::type *=0)
Call this function to produce a name-value pair for an array; this is similar to boost::serialization...
FirstShim(T &t, const std::string &name)
Construct the first shim with the given object and name.
SecondShim(T &t)
Construct the second shim. The name isn't necessary for this shim.
FirstShim< T > CreateNVP(T &t, const std::string &name, typename boost::enable_if< HasSerialize< T >>::type *=0)
Call this function to produce a name-value pair; this is similar to BOOST_SERIALIZATION_NVP(), but should be used for types that have a Serialize() function (or contain a type that has a Serialize() function) instead of a serialize() function.
void serialize(Archive &ar, const unsigned int)
A wrapper for Serialize() for each element.
Archive & operator&(Archive &ar, FirstShim< T > t)
Catch when we call operator& with a FirstShim object.
void serialize(Archive &ar, mlpack::data::PointerShim< T > &t, const BOOST_PFTO unsigned int version)
Catch a call to serialize() with a PointerShim, and call the Serialize() function directly...
SecondArrayShim(T *t, const size_t len)
Construct the shim.
A shim for objects in an array which do not have a Serialize() function.
FirstArrayShim(T *t, const size_t len, const std::string &name)
Construct the first shim with the given objects, length, and name.
A first shim for arrays without a Serialize() method.
FirstNormalArrayShim(T *t, const size_t len, const std::string &name)
Construct the first shim with the given objects, length, and name.
void serialize(Archive &ar, const unsigned int)
A wrapper for make_array().
Archive & operator>>(Archive &ar, FirstShim< T > t)
Catch when we call operator>> with a FirstShim object.
static yes & chk(check< U, typename boost::enable_if< boost::is_class< U >>::type *, typename boost::enable_if< HasSerializeFunction< U >>::type * > *)
SecondNormalArrayShim(T *t, const size_t len)
Construct the shim.
HAS_MEM_FUNC(Serialize, HasSerializeCheck)
A shim for objects in an array; this is basically like the SecondShim, but for arrays that hold objec...
The first shim: simply holds the object and its name.
void serialize(Archive &ar, const unsigned int version)
A wrapper for t.Serialize().
The second shim: wrap the call to Serialize() inside of a serialize() function, so that an archive ty...