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> 22 #include <type_traits> 38 HasSerializeCheck<T, void(T::*)(boost::archive::xml_oarchive&,
39 const unsigned int)>::value ||
41 HasSerializeCheck<T,
void(*)(boost::archive::xml_oarchive&,
42 const unsigned int)>::value;
51 template<
typename U,
typename V,
typename W>
struct check;
52 template<
typename U>
static yes& chk(
56 template<
typename >
static no& chk(...);
58 static const bool value = (
sizeof(chk<T>(0)) ==
sizeof(yes));
125 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 134 return boost::serialization::make_nvp(name.c_str(), t);
160 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 168 return boost::serialization::make_nvp(name.c_str(),
195 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 203 return boost::serialization::make_nvp(name.c_str(), t);
265 t(t), len(len), name(name) { }
282 t(t), len(len), name(name) { }
301 template<
typename Archive>
304 t.Serialize(ar, version);
322 template<
typename Archive>
326 for (
size_t i = 0; i < len; ++i)
345 template<
typename Archive>
348 ar & boost::serialization::make_array(t, len);
370 template<
typename Archive,
typename T>
371 Archive& operator<<(Archive& ar, FirstShim<T> t)
374 return (ar << boost::serialization::make_nvp(t.name.c_str(), sh));
384 template<
typename Archive,
typename T>
388 return (ar & boost::serialization::make_nvp(t.
name.c_str(), sh));
398 template<
typename Archive,
typename T>
402 return (ar >> boost::serialization::make_nvp(t.
name.c_str(), sh));
412 template<
typename Archive,
typename T>
413 Archive& operator<<(Archive& ar, FirstArrayShim<T> t)
416 return (ar << boost::serialization::make_nvp(t.name.c_str(), sh));
426 template<
typename Archive,
typename T>
430 return (ar & boost::serialization::make_nvp(t.
name.c_str(), sh));
440 template<
typename Archive,
typename T>
444 return (ar >> boost::serialization::make_nvp(t.
name.c_str(), sh));
454 template<
typename Archive,
typename T>
455 Archive& operator<<(Archive& ar, FirstNormalArrayShim<T> t)
458 return (ar << boost::serialization::make_nvp(t.name.c_str(), sh));
468 template<
typename Archive,
typename T>
472 return (ar & boost::serialization::make_nvp(t.
name.c_str(), sh));
482 template<
typename Archive,
typename T>
486 return (ar >> boost::serialization::make_nvp(t.
name.c_str(), sh));
493 namespace serialization {
499 template<
typename Archive,
typename T>
504 T* tptr =
reinterpret_cast<T*
>(&t);
505 tptr->Serialize(ar, version);
FirstShim(T &t, const std::string &name)
Construct the first shim with the given object and name.
Linear algebra utility functions, generally performed on matrices or vectors.
FirstShim< T > CreateNVP(T &t, const std::string &name, typename std::enable_if_t< HasSerialize< T >::value > *=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.
FirstArrayShim< T > CreateArrayNVP(T *t, const size_t len, const std::string &name, typename std::enable_if_t< HasSerialize< T >::value > *=0)
Call this function to produce a name-value pair for an array; this is similar to boost::serialization...
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.
test cpp RESULT_VARIABLE MEX_RESULT_TRASH OUTPUT_VARIABLE MEX_OUTPUT ERROR_VARIABLE MEX_ERROR_TRASH string(REGEX MATCH"Warning: You are using"MEX_WARNING"${MEX_OUTPUT}") if(MEX_WARNING) string(REGEX REPLACE".*using [a-zA-Z]* version \"([0-9.]*)[^\"]*\".*""\\1"OTHER_COMPILER_VERSION"$
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...
typename enable_if< B, T >::type enable_if_t
void serialize(Archive &ar, const unsigned int version)
A wrapper for t.Serialize().