serialization: add deque serialization

This commit is contained in:
moneromooo-monero 2017-09-10 22:30:08 +01:00
parent fa54b20584
commit 493fad8053
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
3 changed files with 70 additions and 2 deletions

View file

@ -227,6 +227,18 @@ namespace epee
} }
//------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------
template<class t_type, class t_storage> template<class t_type, class t_storage>
static bool kv_serialize(const std::deque<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{
return serialize_stl_container_t_val(d, stg, hparent_section, pname);
}
//-------------------------------------------------------------------------------------------------------------------
template<class t_type, class t_storage>
static bool kv_unserialize(std::deque<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{
return unserialize_stl_container_t_val(d, stg, hparent_section, pname);
}
//-------------------------------------------------------------------------------------------------------------------
template<class t_type, class t_storage>
static bool kv_serialize(const std::list<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname) static bool kv_serialize(const std::list<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{ {
return serialize_stl_container_t_val(d, stg, hparent_section, pname); return serialize_stl_container_t_val(d, stg, hparent_section, pname);
@ -268,6 +280,18 @@ namespace epee
} }
//------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------
template<class t_type, class t_storage> template<class t_type, class t_storage>
static bool kv_serialize(const std::deque<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{
return serialize_stl_container_t_obj(d, stg, hparent_section, pname);
}
//-------------------------------------------------------------------------------------------------------------------
template<class t_type, class t_storage>
static bool kv_unserialize(std::deque<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{
return unserialize_stl_container_t_obj(d, stg, hparent_section, pname);
}
//-------------------------------------------------------------------------------------------------------------------
template<class t_type, class t_storage>
static bool kv_serialize(const std::list<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname) static bool kv_serialize(const std::list<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{ {
return serialize_stl_container_t_obj(d, stg, hparent_section, pname); return serialize_stl_container_t_obj(d, stg, hparent_section, pname);
@ -353,6 +377,18 @@ namespace epee
} }
//------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------
template<class t_type, class t_storage> template<class t_type, class t_storage>
bool kv_serialize(const std::deque<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{
return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types<t_storage>, typename std::remove_const<t_type>::type>::value>::kv_serialize(d, stg, hparent_section, pname);
}
//-------------------------------------------------------------------------------------------------------------------
template<class t_type, class t_storage>
bool kv_unserialize(std::deque<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{
return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types<t_storage>, typename std::remove_const<t_type>::type>::value>::kv_unserialize(d, stg, hparent_section, pname);
}
//-------------------------------------------------------------------------------------------------------------------
template<class t_type, class t_storage>
bool kv_serialize(const std::list<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname) bool kv_serialize(const std::list<t_type>& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{ {
return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types<t_storage>, typename std::remove_const<t_type>::type>::value>::kv_serialize(d, stg, hparent_section, pname); return kv_serialization_overloads_impl_is_base_serializable_types<boost::mpl::contains<base_serializable_types<t_storage>, typename std::remove_const<t_type>::type>::value>::kv_serialize(d, stg, hparent_section, pname);

View file

@ -41,6 +41,7 @@
#pragma once #pragma once
#include <vector> #include <vector>
#include <deque>
#include <list> #include <list>
#include <string> #include <string>
#include <boost/type_traits/is_integral.hpp> #include <boost/type_traits/is_integral.hpp>
@ -198,6 +199,11 @@ inline bool do_serialize(Archive &ar, bool &v)
#define PREPARE_CUSTOM_VECTOR_SERIALIZATION(size, vec) \ #define PREPARE_CUSTOM_VECTOR_SERIALIZATION(size, vec) \
::serialization::detail::prepare_custom_vector_serialization(size, vec, typename Archive<W>::is_saving()) ::serialization::detail::prepare_custom_vector_serialization(size, vec, typename Archive<W>::is_saving())
/*! \macro PREPARE_CUSTOM_DEQUE_SERIALIZATION
*/
#define PREPARE_CUSTOM_DEQUE_SERIALIZATION(size, vec) \
::serialization::detail::prepare_custom_deque_serialization(size, vec, typename Archive<W>::is_saving())
/*! \macro END_SERIALIZE /*! \macro END_SERIALIZE
* \brief self-explanatory * \brief self-explanatory
*/ */
@ -292,6 +298,17 @@ namespace serialization {
vec.resize(size); vec.resize(size);
} }
template <typename T>
void prepare_custom_deque_serialization(size_t size, std::deque<T>& vec, const boost::mpl::bool_<true>& /*is_saving*/)
{
}
template <typename T>
void prepare_custom_deque_serialization(size_t size, std::deque<T>& vec, const boost::mpl::bool_<false>& /*is_saving*/)
{
vec.resize(size);
}
/*! \fn do_check_stream_state /*! \fn do_check_stream_state
* *
* \brief self explanatory * \brief self explanatory

View file

@ -37,6 +37,11 @@ bool do_serialize(Archive<false> &ar, std::vector<T> &v);
template <template <bool> class Archive, class T> template <template <bool> class Archive, class T>
bool do_serialize(Archive<true> &ar, std::vector<T> &v); bool do_serialize(Archive<true> &ar, std::vector<T> &v);
template <template <bool> class Archive, class T>
bool do_serialize(Archive<false> &ar, std::deque<T> &v);
template <template <bool> class Archive, class T>
bool do_serialize(Archive<true> &ar, std::deque<T> &v);
namespace serialization namespace serialization
{ {
namespace detail namespace detail
@ -64,7 +69,7 @@ namespace serialization
} }
template <template <bool> class Archive, class T> template <template <bool> class Archive, class T>
bool do_serialize(Archive<false> &ar, std::vector<T> &v) bool do_serialize_vd(Archive<false> &ar, T &v)
{ {
size_t cnt; size_t cnt;
ar.begin_array(cnt); ar.begin_array(cnt);
@ -93,7 +98,7 @@ bool do_serialize(Archive<false> &ar, std::vector<T> &v)
} }
template <template <bool> class Archive, class T> template <template <bool> class Archive, class T>
bool do_serialize(Archive<true> &ar, std::vector<T> &v) bool do_serialize_vd(Archive<true> &ar, T &v)
{ {
size_t cnt = v.size(); size_t cnt = v.size();
ar.begin_array(cnt); ar.begin_array(cnt);
@ -110,3 +115,13 @@ bool do_serialize(Archive<true> &ar, std::vector<T> &v)
ar.end_array(); ar.end_array();
return true; return true;
} }
template <template <bool> class Archive, class T>
bool do_serialize(Archive<false> &ar, std::vector<T> &v) { return do_serialize_vd(ar, v); }
template <template <bool> class Archive, class T>
bool do_serialize(Archive<true> &ar, std::vector<T> &v) { return do_serialize_vd(ar, v); }
template <template <bool> class Archive, class T>
bool do_serialize(Archive<false> &ar, std::deque<T> &v) { return do_serialize_vd(ar, v); }
template <template <bool> class Archive, class T>
bool do_serialize(Archive<true> &ar, std::deque<T> &v) { return do_serialize_vd(ar, v); }