1 // Copyright (C) 2006 The Trustees of Indiana University.
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // Authors: Douglas Gregor
10 // This file contains the "unsafe_serialize" routine, which transforms
11 // types they may not be serializable (such as void*) into
12 // serializable equivalents.
13 #ifndef BOOST_PROPERTY_MAP_UNSAFE_SERIALIZE_HPP
14 #define BOOST_PROPERTY_MAP_UNSAFE_SERIALIZE_HPP
16 #include <boost/mpi/datatype.hpp>
17 #include <boost/serialization/is_bitwise_serializable.hpp>
18 #include <boost/mpl/bool.hpp>
19 #include <boost/mpl/if.hpp>
20 #include <boost/cstdint.hpp>
21 #include <boost/static_assert.hpp>
22 #include <boost/type_traits.hpp>
25 BOOST_IS_BITWISE_SERIALIZABLE(void*)
26 namespace boost { namespace mpi {
27 template<> struct is_mpi_datatype<void*> : mpl::true_ { };
28 } } // end namespace boost::mpi
31 typedef mpl::if_c<(sizeof(int) == sizeof(void*)),
33 mpl::if_c<(sizeof(long) == sizeof(void*)),
35 mpl::if_c<(sizeof(void*) <= sizeof(boost::intmax_t)),
39 >::type ptr_serialize_type;
41 BOOST_STATIC_ASSERT ((!boost::is_void<ptr_serialize_type>::value));
43 template<typename T> inline T& unsafe_serialize(T& x) { return x; }
45 inline ptr_serialize_type& unsafe_serialize(void*& x)
46 { return reinterpret_cast<ptr_serialize_type&>(x); }
48 // Force Boost.MPI to serialize a void* like a ptr_serialize_type
50 template<> inline MPI_Datatype get_mpi_datatype<void*>(void* const& x)
52 return get_mpi_datatype<ptr_serialize_type>();
56 template<typename T, typename U>
60 unsafe_pair(const T& t, const U& u) : first(t), second(u) { }
61 unsafe_pair(const std::pair<T, U>& p) : first(p.first), second(p.second) { }
65 template<typename Archiver>
66 void serialize(Archiver& ar, const unsigned /*version*/)
68 ar & unsafe_serialize(first) & unsafe_serialize(second);
72 template<typename T, typename U>
73 bool operator<(unsafe_pair<T,U> const& x, unsafe_pair<T,U> const& y)
75 return std::make_pair(x.first, x.second) <
76 std::make_pair(y.first, y.second);
79 } // end namespace boost
81 #endif // BOOST_PROPERTY_MAP_UNSAFE_SERIALIZE_HPP