From eb75c246a74f53fd6325f45ded47533d278b6b47 Mon Sep 17 00:00:00 2001 From: Martin Beseda <martin.beseda@vsb.cz> Date: Wed, 20 Mar 2019 00:47:53 +0100 Subject: [PATCH] ENH: Added serialization method to NeuronDifferentiable class --- src/Neuron/NeuronSerialization.h | 37 +++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Neuron/NeuronSerialization.h b/src/Neuron/NeuronSerialization.h index c1fd0330..f2aca6f7 100644 --- a/src/Neuron/NeuronSerialization.h +++ b/src/Neuron/NeuronSerialization.h @@ -13,14 +13,28 @@ #include "Neuron.h" BOOST_SERIALIZATION_ASSUME_ABSTRACT(lib4neuro::Neuron); - BOOST_CLASS_EXPORT_KEY(lib4neuro::Neuron); -struct lib4neuro::Neuron::access { - template<class Archive> - static void serialize(Archive &ar, lib4neuro::Neuron &n, const unsigned int version) {} -}; +BOOST_SERIALIZATION_ASSUME_ABSTRACT(lib4neuro::NeuronDifferentiable); +BOOST_CLASS_EXPORT_KEY(lib4neuro::NeuronDifferentiable); + +namespace lib4neuro { + struct Neuron::access { + template<class Archive> + static void serialize(Archive& ar, + Neuron& n, + const unsigned int version) {} + }; + struct NeuronDifferentiable::access { + template<class Archive> + static void serialize(Archive& ar, + NeuronDifferentiable& n, + const unsigned int version) { + ar & boost::serialization::base_object<Neuron>(n); + } + }; +} namespace boost { namespace serialization { @@ -38,6 +52,19 @@ namespace boost { lib4neuro::Neuron::access::serialize(ar, n, version); } + /** + * Serialization function + * @tparam Archive Boost library template + * @param ar Boost parameter - filled automatically during serialization! + * @param n NeuronDifferentiable instance + * @param version Boost parameter - filled automatically during serialization! + */ + template<class Archive> + void serialize(Archive & ar, lib4neuro::NeuronDifferentiable& n, const unsigned int version) + { + lib4neuro::NeuronDifferentiable::access::serialize(ar, n, version); + } + } // namespace serialization } // namespace boost -- GitLab