From ae0bd74390a0ad99946b33d3d882cad87efeb330 Mon Sep 17 00:00:00 2001 From: AntonBikineev Date: Wed, 16 Sep 2015 21:02:32 -0500 Subject: [PATCH 1/7] Added support for const-correctness of data for output_archives --- hpx/runtime/serialization/access.hpp | 29 +++++++------------ .../serialization/serialization_fwd.hpp | 3 -- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/hpx/runtime/serialization/access.hpp b/hpx/runtime/serialization/access.hpp index a249ed41b7ae..3ba23bbf8e25 100644 --- a/hpx/runtime/serialization/access.hpp +++ b/hpx/runtime/serialization/access.hpp @@ -52,7 +52,7 @@ namespace hpx { namespace serialization } }; - struct non_intrusive_polymorphic + struct non_intrusive { // this additional indirection level is needed to // force ADL on the second phase of template lookup. @@ -74,7 +74,7 @@ namespace hpx { namespace serialization } }; - struct usual + struct intrusive_usual { template static void call(Archive& ar, T& t, unsigned) @@ -87,22 +87,15 @@ namespace hpx { namespace serialization typedef typename boost::mpl::eval_if< hpx::traits::is_intrusive_polymorphic, boost::mpl::identity, - boost::mpl::eval_if< - hpx::traits::is_nonintrusive_polymorphic, - boost::mpl::identity, - boost::mpl::eval_if< - boost::mpl::and_< - boost::mpl::not_< - hpx::traits::has_serialize - >, - boost::is_empty - >, - boost::mpl::identity, - boost::mpl::identity - > - - - > + boost::mpl::eval_if< + hpx::traits::has_serialize, + boost::mpl::identity, + boost::mpl::eval_if< + boost::is_empty, + boost::mpl::identity, + boost::mpl::identity + > + > >::type type; }; diff --git a/hpx/runtime/serialization/serialization_fwd.hpp b/hpx/runtime/serialization/serialization_fwd.hpp index c03ba122236d..2586522389fe 100644 --- a/hpx/runtime/serialization/serialization_fwd.hpp +++ b/hpx/runtime/serialization/serialization_fwd.hpp @@ -42,9 +42,6 @@ namespace hpx { namespace serialization template Helper & tracked_pointer(input_archive & ar, boost::uint64_t pos); - template - void serialize(Archive & ar, T & t, unsigned); - template output_archive & operator<<(output_archive & ar, T const & t); From 4eddfa2b8df4b2b0d8984d77b549df4d981f0885 Mon Sep 17 00:00:00 2001 From: AntonBikineev Date: Wed, 16 Sep 2015 21:19:31 -0500 Subject: [PATCH 2/7] Splitting serialize_force_adl by archive types --- hpx/runtime/serialization/access.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hpx/runtime/serialization/access.hpp b/hpx/runtime/serialization/access.hpp index 3ba23bbf8e25..bd967a6c1bcd 100644 --- a/hpx/runtime/serialization/access.hpp +++ b/hpx/runtime/serialization/access.hpp @@ -23,8 +23,14 @@ namespace hpx { namespace serialization { namespace detail { - template - BOOST_FORCEINLINE void serialize_force_adl(Archive& ar, T& t, unsigned) + template BOOST_FORCEINLINE + void serialize_force_adl(output_archive& ar, const T& t, unsigned) + { + serialize(ar, t, 0); + } + + template BOOST_FORCEINLINE + void serialize_force_adl(input_archive& ar, T& t, unsigned) { serialize(ar, t, 0); } From 26b5875cb6a0c0a5dbccc5dc5c949bd72bcd3b01 Mon Sep 17 00:00:00 2001 From: AntonBikineev Date: Fri, 18 Sep 2015 00:42:36 -0500 Subject: [PATCH 3/7] Making global serialize function worse candidate by adding sfinae --- hpx/runtime/serialization/access.hpp | 16 +++++++--------- hpx/runtime/serialization/serialize.hpp | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/hpx/runtime/serialization/access.hpp b/hpx/runtime/serialization/access.hpp index bd967a6c1bcd..67bf57562f69 100644 --- a/hpx/runtime/serialization/access.hpp +++ b/hpx/runtime/serialization/access.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -23,14 +24,8 @@ namespace hpx { namespace serialization { namespace detail { - template BOOST_FORCEINLINE - void serialize_force_adl(output_archive& ar, const T& t, unsigned) - { - serialize(ar, t, 0); - } - - template BOOST_FORCEINLINE - void serialize_force_adl(input_archive& ar, T& t, unsigned) + template BOOST_FORCEINLINE + void serialize_force_adl(Archive& ar, T& t, unsigned) { serialize(ar, t, 0); } @@ -85,7 +80,10 @@ namespace hpx { namespace serialization template static void call(Archive& ar, T& t, unsigned) { - t.serialize(ar, 0); + // cast it to let it be run for templated + // member functions + const_cast::type&>( + t).serialize(ar, 0); } }; diff --git a/hpx/runtime/serialization/serialize.hpp b/hpx/runtime/serialization/serialize.hpp index fce9e4bc9a5e..181537b0cd2f 100644 --- a/hpx/runtime/serialization/serialize.hpp +++ b/hpx/runtime/serialization/serialize.hpp @@ -13,10 +13,24 @@ #include #include +#include + namespace hpx { namespace serialization { + // use templated Archive parameter with sfinae + // to make these overloads less specialized than any else + template + typename boost::enable_if< + boost::is_same >::type + serialize(Archive & ar, const T & t, unsigned) + { + access::serialize(ar, t, 0); + } + template - void serialize(Archive & ar, T & t, unsigned) + typename boost::enable_if< + boost::is_same >::type + serialize(Archive & ar, T & t, unsigned) { access::serialize(ar, t, 0); } From 9e57d5cb039cb602098923a49c65d6cdd2625eb9 Mon Sep 17 00:00:00 2001 From: AntonBikineev Date: Fri, 18 Sep 2015 00:43:24 -0500 Subject: [PATCH 4/7] Deleting useless const_cast --- hpx/runtime/serialization/output_archive.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hpx/runtime/serialization/output_archive.hpp b/hpx/runtime/serialization/output_archive.hpp index b310a237301a..7420357d0da5 100644 --- a/hpx/runtime/serialization/output_archive.hpp +++ b/hpx/runtime/serialization/output_archive.hpp @@ -125,7 +125,7 @@ namespace hpx { namespace serialization "Can not bitwise serialize a class that is abstract"); if(disable_array_optimization()) { - serialize(*this, const_cast(t), 0); + serialize(*this, t, 0); } else { From 48903a8d65cfca8047dccb83960d6cd3a6b5a104 Mon Sep 17 00:00:00 2001 From: AntonBikineev Date: Fri, 18 Sep 2015 00:54:21 -0500 Subject: [PATCH 5/7] Deleting allocator serialization --- hpx/include/serialization.hpp | 1 - hpx/runtime/serialization/allocator.hpp | 24 ------------------- .../serialization/serialize_buffer.hpp | 1 - 3 files changed, 26 deletions(-) delete mode 100644 hpx/runtime/serialization/allocator.hpp diff --git a/hpx/include/serialization.hpp b/hpx/include/serialization.hpp index 29bf6389db8a..63378dd8ca59 100644 --- a/hpx/include/serialization.hpp +++ b/hpx/include/serialization.hpp @@ -9,7 +9,6 @@ #include #include -#include #include #include #include diff --git a/hpx/runtime/serialization/allocator.hpp b/hpx/runtime/serialization/allocator.hpp deleted file mode 100644 index a87246e34db6..000000000000 --- a/hpx/runtime/serialization/allocator.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2007-2014 Hartmut Kaiser -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#if !defined(HPX_SERIALIZATION_ALLOCATOR_FEB_19_2014_0711PM) -#define HPX_SERIALIZATION_ALLOCATOR_FEB_19_2014_0711PM - -#include -#include - -/////////////////////////////////////////////////////////////////////////////// -namespace hpx { namespace serialization -{ - /////////////////////////////////////////////////////////////////////////// - template - void save(Archive&, std::allocator const&, unsigned int) {} - - /////////////////////////////////////////////////////////////////////////// - template - void load(Archive&, std::allocator&, unsigned int) {} -}} - -#endif diff --git a/hpx/runtime/serialization/serialize_buffer.hpp b/hpx/runtime/serialization/serialize_buffer.hpp index 2f7b36437945..192b5e63c8c0 100644 --- a/hpx/runtime/serialization/serialize_buffer.hpp +++ b/hpx/runtime/serialization/serialize_buffer.hpp @@ -12,7 +12,6 @@ #include #include -#include #include #include From e2248a8a4fa7fb140463e13953bdb1045e17dc07 Mon Sep 17 00:00:00 2001 From: AntonBikineev Date: Fri, 18 Sep 2015 01:09:14 -0500 Subject: [PATCH 6/7] Making serialization for types supported in HPX const-correct --- hpx/runtime/serialization/complex.hpp | 2 +- hpx/runtime/serialization/list.hpp | 2 +- hpx/runtime/serialization/map.hpp | 10 +++++----- hpx/runtime/serialization/set.hpp | 2 +- hpx/runtime/serialization/string.hpp | 2 +- hpx/runtime/serialization/vector.hpp | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/hpx/runtime/serialization/complex.hpp b/hpx/runtime/serialization/complex.hpp index 7281b664736a..9825bb241ff7 100644 --- a/hpx/runtime/serialization/complex.hpp +++ b/hpx/runtime/serialization/complex.hpp @@ -23,7 +23,7 @@ namespace hpx { namespace serialization } template - void serialize(output_archive& ar, std::complex& c, unsigned) + void serialize(output_archive& ar, const std::complex& c, unsigned) { ar << c.real() << c.imag(); } diff --git a/hpx/runtime/serialization/list.hpp b/hpx/runtime/serialization/list.hpp index 97460eb15346..16f9ca0254b0 100644 --- a/hpx/runtime/serialization/list.hpp +++ b/hpx/runtime/serialization/list.hpp @@ -29,7 +29,7 @@ namespace hpx { namespace serialization } template - void serialize(output_archive & ar, std::list & ls, unsigned) + void serialize(output_archive & ar, const std::list & ls, unsigned) { // normal save ... ar << ls.size(); //-V128 diff --git a/hpx/runtime/serialization/map.hpp b/hpx/runtime/serialization/map.hpp index f365df2d1ba5..bf5bded02607 100644 --- a/hpx/runtime/serialization/map.hpp +++ b/hpx/runtime/serialization/map.hpp @@ -55,7 +55,7 @@ namespace hpx } template - void save_pair_impl(output_archive& ar, std::pair& t, + void save_pair_impl(output_archive& ar, const std::pair& t, boost::mpl::false_) { ar << t.first; @@ -63,7 +63,7 @@ namespace hpx } template - void save_pair_impl(output_archive& ar, std::pair& t, + void save_pair_impl(output_archive& ar, const std::pair& t, boost::mpl::true_) { if (!has_array_optimization(ar)) @@ -84,7 +84,7 @@ namespace hpx } template - void serialize(output_archive& ar, std::pair& t, unsigned) + void serialize(output_archive& ar, const std::pair& t, unsigned) { typedef std::pair pair_type; typedef typename traits::is_bitwise_serializable optimized; @@ -110,12 +110,12 @@ namespace hpx template void serialize(output_archive& ar, - std::map& t, unsigned) + const std::map& t, unsigned) { typedef typename std::map::value_type value_type; ar << t.size(); //-V128 - for(value_type& val : t) + for(const value_type& val : t) { ar << val; } diff --git a/hpx/runtime/serialization/set.hpp b/hpx/runtime/serialization/set.hpp index 90c83e58ef84..32cd95deef06 100644 --- a/hpx/runtime/serialization/set.hpp +++ b/hpx/runtime/serialization/set.hpp @@ -27,7 +27,7 @@ namespace hpx { namespace serialization } template - void serialize(output_archive & ar, std::set & set, unsigned) + void serialize(output_archive & ar, const std::set & set, unsigned) { boost::uint64_t size = set.size(); ar << size; diff --git a/hpx/runtime/serialization/string.hpp b/hpx/runtime/serialization/string.hpp index 6904ba1edeaf..0829ec02f630 100644 --- a/hpx/runtime/serialization/string.hpp +++ b/hpx/runtime/serialization/string.hpp @@ -31,7 +31,7 @@ namespace hpx { namespace serialization // save string template - void serialize(output_archive & ar, std::basic_string & s, unsigned) { ar << s.size(); //-V128 diff --git a/hpx/runtime/serialization/vector.hpp b/hpx/runtime/serialization/vector.hpp index 64643e4e5a76..847182529f37 100644 --- a/hpx/runtime/serialization/vector.hpp +++ b/hpx/runtime/serialization/vector.hpp @@ -86,7 +86,7 @@ namespace hpx { namespace serialization // save vector template - void save_impl(output_archive & ar, std::vector & vs, + void save_impl(output_archive & ar, const std::vector & vs, boost::mpl::false_) { // normal save ... @@ -98,7 +98,7 @@ namespace hpx { namespace serialization } template - void save_impl(output_archive & ar, std::vector & v, boost::mpl::true_) + void save_impl(output_archive & ar, const std::vector & v, boost::mpl::true_) { if(!has_array_optimization(ar)) { @@ -113,7 +113,7 @@ namespace hpx { namespace serialization } template - void serialize(output_archive & ar, std::vector & v, unsigned) + void serialize(output_archive & ar, const std::vector & v, unsigned) { typedef typename std::vector::size_type size_type; ar << v.size(); //-V128 @@ -127,7 +127,7 @@ namespace hpx { namespace serialization } template - void serialize(output_archive & ar, std::vector & v, unsigned) + void serialize(output_archive & ar, const std::vector & v, unsigned) { ar << v.size(); //-V128 if(v.empty()) return; From de3612889bbac5fb9abcde71c07a34ba5457556c Mon Sep 17 00:00:00 2001 From: AntonBikineev Date: Fri, 18 Sep 2015 09:13:12 -0500 Subject: [PATCH 7/7] Adding line breaks after const-correctness change --- hpx/runtime/serialization/set.hpp | 3 ++- hpx/runtime/serialization/vector.hpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hpx/runtime/serialization/set.hpp b/hpx/runtime/serialization/set.hpp index 32cd95deef06..59d11e802562 100644 --- a/hpx/runtime/serialization/set.hpp +++ b/hpx/runtime/serialization/set.hpp @@ -27,7 +27,8 @@ namespace hpx { namespace serialization } template - void serialize(output_archive & ar, const std::set & set, unsigned) + void serialize(output_archive & ar,const std::set & set, + unsigned) { boost::uint64_t size = set.size(); ar << size; diff --git a/hpx/runtime/serialization/vector.hpp b/hpx/runtime/serialization/vector.hpp index 847182529f37..8e4c6e201854 100644 --- a/hpx/runtime/serialization/vector.hpp +++ b/hpx/runtime/serialization/vector.hpp @@ -98,7 +98,8 @@ namespace hpx { namespace serialization } template - void save_impl(output_archive & ar, const std::vector & v, boost::mpl::true_) + void save_impl(output_archive & ar, const std::vector & v, + boost::mpl::true_) { if(!has_array_optimization(ar)) {