diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-08-12 23:06:48 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-09-26 23:12:28 +0100 |
commit | 98f19d40aacf835bb63be8534eea2b29e77e48ac (patch) | |
tree | 5937444b6f3b3730da1116ff15952311981aee71 /src/serialization/serialization.h | |
parent | Merge pull request #1102 (diff) | |
download | monero-98f19d40aacf835bb63be8534eea2b29e77e48ac.tar.xz |
serialization: add support for serializing std::pair and std::list
Diffstat (limited to '')
-rw-r--r-- | src/serialization/serialization.h | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/serialization/serialization.h b/src/serialization/serialization.h index 177cdf33a..dac43720b 100644 --- a/src/serialization/serialization.h +++ b/src/serialization/serialization.h @@ -41,6 +41,7 @@ #pragma once #include <vector> +#include <list> #include <string> #include <boost/type_traits/is_integral.hpp> #include <boost/type_traits/integral_constant.hpp> @@ -59,6 +60,16 @@ struct is_blob_type { typedef boost::false_type type; }; template <class T> struct has_free_serializer { typedef boost::true_type type; }; +/*! \struct is_pair_type + * + * \brief a descriptor for dispatching serialize + */ +template <class T> +struct is_pair_type { typedef boost::false_type type; }; + +template<typename F, typename S> +struct is_pair_type<std::pair<F,S>> { typedef boost::true_type type; }; + /*! \struct serializer * * \brief ... wouldn't a class be better? @@ -75,20 +86,26 @@ struct has_free_serializer { typedef boost::true_type type; }; template <class Archive, class T> struct serializer{ static bool serialize(Archive &ar, T &v) { - return serialize(ar, v, typename boost::is_integral<T>::type(), typename is_blob_type<T>::type()); + return serialize(ar, v, typename boost::is_integral<T>::type(), typename is_blob_type<T>::type(), typename is_pair_type<T>::type()); } - static bool serialize(Archive &ar, T &v, boost::false_type, boost::true_type) { + template<typename A> + static bool serialize(Archive &ar, T &v, boost::false_type, boost::true_type, A a) { ar.serialize_blob(&v, sizeof(v)); return true; } - static bool serialize(Archive &ar, T &v, boost::true_type, boost::false_type) { + template<typename A> + static bool serialize(Archive &ar, T &v, boost::true_type, boost::false_type, A a) { ar.serialize_int(v); return true; } - static bool serialize(Archive &ar, T &v, boost::false_type, boost::false_type) { + static bool serialize(Archive &ar, T &v, boost::false_type, boost::false_type, boost::false_type) { //serialize_custom(ar, v, typename has_free_serializer<T>::type()); return v.do_serialize(ar); } + static bool serialize(Archive &ar, T &v, boost::false_type, boost::false_type, boost::true_type) { + //serialize_custom(ar, v, typename has_free_serializer<T>::type()); + return do_serialize(ar, v); + } static void serialize_custom(Archive &ar, T &v, boost::true_type) { } }; @@ -328,3 +345,5 @@ namespace serialization { #include "string.h" #include "vector.h" +#include "list.h" +#include "pair.h" |