18 #ifndef __MLPACK_CORE_UTIL_SERIALIZATION_SHIM_HPP 19 #define __MLPACK_CORE_UTIL_SERIALIZATION_SHIM_HPP 22 #include <boost/serialization/serialization.hpp> 23 #include <boost/archive/xml_oarchive.hpp> 39 HasSerializeCheck<T, void(T::*)(boost::archive::xml_oarchive&,
40 const unsigned int)>::value ||
42 HasSerializeCheck<T,
void(*)(boost::archive::xml_oarchive&,
43 const unsigned int)>::value;
52 template<
typename U,
typename V,
typename W>
struct check;
53 template<
typename U>
static yes& chk(
55 typename boost::enable_if<boost::is_class<U>>::type*,
57 template<
typename >
static no& chk(...);
59 static const bool value = (
sizeof(chk<T>(0)) ==
sizeof(yes));
97 const std::string& name,
126 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 131 const std::string& name,
133 typename boost::disable_if<boost::is_pointer<T>>::type* = 0)
135 return boost::serialization::make_nvp(name.c_str(), t);
161 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 166 const std::string& name,
169 return boost::serialization::make_nvp(name.c_str(),
196 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 201 const std::string& name,
204 return boost::serialization::make_nvp(name.c_str(), t);
218 const std::string& name,
235 const std::string& name,
250 FirstShim(T& t,
const std::string& name) : t(t), name(name) { }
266 t(t), len(len), name(name) { }
283 t(t), len(len), name(name) { }
302 template<
typename Archive>
305 t.Serialize(ar, version);
323 template<
typename Archive>
327 for (
size_t i = 0; i < len; ++i)
346 template<
typename Archive>
349 ar & boost::serialization::make_array(t, len);
371 template<
typename Archive,
typename T>
372 Archive& operator<<(Archive& ar, FirstShim<T> t)
375 return (ar << boost::serialization::make_nvp(t.name.c_str(), sh));
385 template<
typename Archive,
typename T>
389 return (ar & boost::serialization::make_nvp(t.
name.c_str(), sh));
399 template<
typename Archive,
typename T>
403 return (ar >> boost::serialization::make_nvp(t.
name.c_str(), sh));
413 template<
typename Archive,
typename T>
414 Archive& operator<<(Archive& ar, FirstArrayShim<T> t)
417 return (ar << boost::serialization::make_nvp(t.name.c_str(), sh));
427 template<
typename Archive,
typename T>
431 return (ar & boost::serialization::make_nvp(t.
name.c_str(), sh));
441 template<
typename Archive,
typename T>
445 return (ar >> boost::serialization::make_nvp(t.
name.c_str(), sh));
455 template<
typename Archive,
typename T>
456 Archive& operator<<(Archive& ar, FirstNormalArrayShim<T> t)
459 return (ar << boost::serialization::make_nvp(t.name.c_str(), sh));
469 template<
typename Archive,
typename T>
473 return (ar & boost::serialization::make_nvp(t.
name.c_str(), sh));
483 template<
typename Archive,
typename T>
487 return (ar >> boost::serialization::make_nvp(t.
name.c_str(), sh));
494 namespace serialization {
500 template<
typename Archive,
typename T>
505 T* tptr =
reinterpret_cast<T*
>(&t);
506 tptr->Serialize(ar, version);
FirstShim(T &t, const std::string &name)
Construct the first shim with the given object and name.
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...
Linear algebra utility functions, generally performed on matrices or vectors.
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.
FirstArrayShim(T *t, const size_t len, const std::string &name)
Construct the first shim with the given objects, length, and name.
Archive & operator&(Archive &ar, FirstShim< T > t)
Catch when we call operator& with a FirstShim object.
SecondShim(T &t)
Construct the second shim. The name isn't necessary for this shim.
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...
A shim for objects in an array which do not have a Serialize() function.
A first shim for arrays without a Serialize() method.
SecondNormalArrayShim(T *t, const size_t len)
Construct the shim.
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.
HAS_MEM_FUNC(Serialize, HasSerializeCheck)
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 Serialize() for each element.
SecondArrayShim(T *t, const size_t len)
Construct the shim.
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.
The second shim: wrap the call to Serialize() inside of a serialize() function, so that an archive ty...
void serialize(Archive &ar, const unsigned int version)
A wrapper for t.Serialize().