Skip to content

Commit

Permalink
Merge pull request #1755 from STEllAR-GROUP/refining_serialize_function
Browse files Browse the repository at this point in the history
Making output serialization const-correct
  • Loading branch information
sithhell committed Sep 23, 2015
2 parents a30c15c + de36128 commit 45a676d
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 65 deletions.
1 change: 0 additions & 1 deletion hpx/include/serialization.hpp
Expand Up @@ -9,7 +9,6 @@
#include <hpx/runtime/serialization/serialization_fwd.hpp>
#include <hpx/runtime/serialization/serialize.hpp>

#include <hpx/runtime/serialization/allocator.hpp>
#include <hpx/runtime/serialization/array.hpp>
#include <hpx/runtime/serialization/intrusive_ptr.hpp>
#include <hpx/runtime/serialization/map.hpp>
Expand Down
39 changes: 18 additions & 21 deletions hpx/runtime/serialization/access.hpp
Expand Up @@ -10,6 +10,7 @@
#include <hpx/runtime/serialization/serialization_fwd.hpp>
#include <hpx/traits/polymorphic_traits.hpp>
#include <hpx/traits/has_serialize.hpp>
#include <hpx/util/decay.hpp>

#include <boost/type_traits/is_empty.hpp>
#include <boost/mpl/eval_if.hpp>
Expand All @@ -23,8 +24,8 @@ namespace hpx { namespace serialization
{
namespace detail
{
template <class Archive, class T>
BOOST_FORCEINLINE void serialize_force_adl(Archive& ar, T& t, unsigned)
template <class Archive, class T> BOOST_FORCEINLINE
void serialize_force_adl(Archive& ar, T& t, unsigned)
{
serialize(ar, t, 0);
}
Expand Down Expand Up @@ -52,7 +53,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.
Expand All @@ -74,35 +75,31 @@ namespace hpx { namespace serialization
}
};

struct usual
struct intrusive_usual
{
template <class Archive>
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<typename util::decay<T>::type&>(
t).serialize(ar, 0);
}
};

public:
typedef typename boost::mpl::eval_if<
hpx::traits::is_intrusive_polymorphic<T>,
boost::mpl::identity<intrusive_polymorphic>,
boost::mpl::eval_if<
hpx::traits::is_nonintrusive_polymorphic<T>,
boost::mpl::identity<non_intrusive_polymorphic>,
boost::mpl::eval_if<
boost::mpl::and_<
boost::mpl::not_<
hpx::traits::has_serialize<T>
>,
boost::is_empty<T>
>,
boost::mpl::identity<empty>,
boost::mpl::identity<usual>
>


>
boost::mpl::eval_if<
hpx::traits::has_serialize<T>,
boost::mpl::identity<intrusive_usual>,
boost::mpl::eval_if<
boost::is_empty<T>,
boost::mpl::identity<empty>,
boost::mpl::identity<non_intrusive>
>
>
>::type type;
};

Expand Down
24 changes: 0 additions & 24 deletions hpx/runtime/serialization/allocator.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion hpx/runtime/serialization/complex.hpp
Expand Up @@ -23,7 +23,7 @@ namespace hpx { namespace serialization
}

template <typename T>
void serialize(output_archive& ar, std::complex<T>& c, unsigned)
void serialize(output_archive& ar, const std::complex<T>& c, unsigned)
{
ar << c.real() << c.imag();
}
Expand Down
2 changes: 1 addition & 1 deletion hpx/runtime/serialization/list.hpp
Expand Up @@ -29,7 +29,7 @@ namespace hpx { namespace serialization
}

template <typename T, typename Allocator>
void serialize(output_archive & ar, std::list<T, Allocator> & ls, unsigned)
void serialize(output_archive & ar, const std::list<T, Allocator> & ls, unsigned)
{
// normal save ...
ar << ls.size(); //-V128
Expand Down
10 changes: 5 additions & 5 deletions hpx/runtime/serialization/map.hpp
Expand Up @@ -55,15 +55,15 @@ namespace hpx
}

template <class Key, class Value>
void save_pair_impl(output_archive& ar, std::pair<Key, Value>& t,
void save_pair_impl(output_archive& ar, const std::pair<Key, Value>& t,
boost::mpl::false_)
{
ar << t.first;
ar << t.second;
}

template <class Key, class Value>
void save_pair_impl(output_archive& ar, std::pair<Key, Value>& t,
void save_pair_impl(output_archive& ar, const std::pair<Key, Value>& t,
boost::mpl::true_)
{
if (ar.disable_array_optimization())
Expand All @@ -84,7 +84,7 @@ namespace hpx
}

template <class Key, class Value>
void serialize(output_archive& ar, std::pair<Key, Value>& t, unsigned)
void serialize(output_archive& ar, const std::pair<Key, Value>& t, unsigned)
{
typedef std::pair<Key, Value> pair_type;
typedef typename traits::is_bitwise_serializable<pair_type> optimized;
Expand All @@ -110,12 +110,12 @@ namespace hpx

template <class Key, class Value, class Comp, class Alloc>
void serialize(output_archive& ar,
std::map<Key, Value, Comp, Alloc>& t, unsigned)
const std::map<Key, Value, Comp, Alloc>& t, unsigned)
{
typedef typename std::map<Key, Value, Comp, Alloc>::value_type value_type;

ar << t.size(); //-V128
for(value_type& val : t)
for(const value_type& val : t)
{
ar << val;
}
Expand Down
2 changes: 1 addition & 1 deletion hpx/runtime/serialization/output_archive.hpp
Expand Up @@ -177,7 +177,7 @@ namespace hpx { namespace serialization
"Can not bitwise serialize a class that is abstract");
if(disable_array_optimization())
{
serialize(*this, const_cast<T &>(t), 0);
serialize(*this, t, 0);
}
else
{
Expand Down
3 changes: 0 additions & 3 deletions hpx/runtime/serialization/serialization_fwd.hpp
Expand Up @@ -42,9 +42,6 @@ namespace hpx { namespace serialization
template <typename Helper>
Helper & tracked_pointer(input_archive & ar, boost::uint64_t pos);

template <typename Archive, typename T>
void serialize(Archive & ar, T & t, unsigned);

template <typename T>
output_archive & operator<<(output_archive & ar, T const & t);

Expand Down
16 changes: 15 additions & 1 deletion hpx/runtime/serialization/serialize.hpp
Expand Up @@ -13,10 +13,24 @@
#include <hpx/runtime/serialization/output_archive.hpp>
#include <hpx/runtime/serialization/detail/size_gatherer_container.hpp>

#include <boost/type_traits/is_same.hpp>

namespace hpx { namespace serialization
{
// use templated Archive parameter with sfinae
// to make these overloads less specialized than any else
template <typename Archive, typename T>
typename boost::enable_if<
boost::is_same<Archive, output_archive> >::type
serialize(Archive & ar, const T & t, unsigned)
{
access::serialize(ar, t, 0);
}

template <typename Archive, typename T>
void serialize(Archive & ar, T & t, unsigned)
typename boost::enable_if<
boost::is_same<Archive, input_archive> >::type
serialize(Archive & ar, T & t, unsigned)
{
access::serialize(ar, t, 0);
}
Expand Down
1 change: 0 additions & 1 deletion hpx/runtime/serialization/serialize_buffer.hpp
Expand Up @@ -12,7 +12,6 @@

#include <hpx/runtime/serialization/serialize.hpp>
#include <hpx/runtime/serialization/array.hpp>
#include <hpx/runtime/serialization/allocator.hpp>

#include <boost/shared_array.hpp>
#include <boost/mpl/bool.hpp>
Expand Down
3 changes: 2 additions & 1 deletion hpx/runtime/serialization/set.hpp
Expand Up @@ -27,7 +27,8 @@ namespace hpx { namespace serialization
}

template <class T, class Compare, class Allocator>
void serialize(output_archive & ar, std::set<T, Compare, Allocator> & set, unsigned)
void serialize(output_archive & ar,const std::set<T, Compare, Allocator> & set,
unsigned)
{
boost::uint64_t size = set.size();
ar << size;
Expand Down
2 changes: 1 addition & 1 deletion hpx/runtime/serialization/string.hpp
Expand Up @@ -31,7 +31,7 @@ namespace hpx { namespace serialization

// save string
template <typename Char, typename CharTraits, typename Allocator>
void serialize(output_archive & ar, std::basic_string<Char, CharTraits,
void serialize(output_archive & ar, const std::basic_string<Char, CharTraits,
Allocator> & s, unsigned)
{
ar << s.size(); //-V128
Expand Down
9 changes: 5 additions & 4 deletions hpx/runtime/serialization/vector.hpp
Expand Up @@ -86,7 +86,7 @@ namespace hpx { namespace serialization

// save vector<T>
template <typename T, typename Allocator>
void save_impl(output_archive & ar, std::vector<T, Allocator> & vs,
void save_impl(output_archive & ar, const std::vector<T, Allocator> & vs,
boost::mpl::false_)
{
// normal save ...
Expand All @@ -98,7 +98,8 @@ namespace hpx { namespace serialization
}

template <typename T, typename Allocator>
void save_impl(output_archive & ar, std::vector<T, Allocator> & v, boost::mpl::true_)
void save_impl(output_archive & ar, const std::vector<T, Allocator> & v,
boost::mpl::true_)
{
if(ar.disable_array_optimization())
{
Expand All @@ -113,7 +114,7 @@ namespace hpx { namespace serialization
}

template <typename Allocator>
void serialize(output_archive & ar, std::vector<bool, Allocator> & v, unsigned)
void serialize(output_archive & ar, const std::vector<bool, Allocator> & v, unsigned)
{
typedef typename std::vector<bool, Allocator>::size_type size_type;
ar << v.size(); //-V128
Expand All @@ -127,7 +128,7 @@ namespace hpx { namespace serialization
}

template <typename T, typename Allocator>
void serialize(output_archive & ar, std::vector<T, Allocator> & v, unsigned)
void serialize(output_archive & ar, const std::vector<T, Allocator> & v, unsigned)
{
ar << v.size(); //-V128
if(v.empty()) return;
Expand Down

0 comments on commit 45a676d

Please sign in to comment.