/Src/Dependencies/Boost/boost/graph/distributed/unsafe_serialize.hpp

http://hadesmem.googlecode.com/ · C++ Header · 85 lines · 59 code · 16 blank · 10 comment · 2 complexity · 535528380f3361328981a31b2cb8758f MD5 · raw file

  1. // Copyright (C) 2006 The Trustees of Indiana University.
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Authors: Douglas Gregor
  6. // Andrew Lumsdaine
  7. // This file contains the "unsafe_serialize" routine, which transforms
  8. // types they may not be serializable (such as void*) into
  9. // serializable equivalents.
  10. #ifndef PBGL_UNSAFE_SERIALIZE_HPP
  11. #define PBGL_UNSAFE_SERIALIZE_HPP
  12. #ifndef BOOST_GRAPH_USE_MPI
  13. #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
  14. #endif
  15. #include <boost/mpi/datatype.hpp>
  16. #include <boost/serialization/is_bitwise_serializable.hpp>
  17. #include <boost/mpl/bool.hpp>
  18. #include <boost/mpl/if.hpp>
  19. #include <boost/cstdint.hpp>
  20. #include <boost/static_assert.hpp>
  21. #include <boost/type_traits.hpp>
  22. #include <utility>
  23. BOOST_IS_BITWISE_SERIALIZABLE(void*)
  24. namespace boost { namespace mpi {
  25. template<> struct is_mpi_datatype<void*> : mpl::true_ { };
  26. } } // end namespace boost::mpi
  27. namespace boost {
  28. typedef mpl::if_c<(sizeof(int) == sizeof(void*)),
  29. int,
  30. mpl::if_c<(sizeof(long) == sizeof(void*)),
  31. long,
  32. mpl::if_c<(sizeof(void*) <= sizeof(boost::intmax_t)),
  33. boost::intmax_t,
  34. void>::type
  35. >::type
  36. >::type ptr_serialize_type;
  37. BOOST_STATIC_ASSERT ((!boost::is_void<ptr_serialize_type>::value));
  38. template<typename T> inline T& unsafe_serialize(T& x) { return x; }
  39. inline ptr_serialize_type& unsafe_serialize(void*& x)
  40. { return reinterpret_cast<ptr_serialize_type&>(x); }
  41. // Force Boost.MPI to serialize a void* like a ptr_serialize_type
  42. namespace mpi {
  43. template<> inline MPI_Datatype get_mpi_datatype<void*>(void* const& x)
  44. {
  45. return get_mpi_datatype<ptr_serialize_type>();
  46. }
  47. }
  48. template<typename T, typename U>
  49. struct unsafe_pair
  50. {
  51. unsafe_pair() { }
  52. unsafe_pair(const T& t, const U& u) : first(t), second(u) { }
  53. unsafe_pair(const std::pair<T, U>& p) : first(p.first), second(p.second) { }
  54. T first;
  55. U second;
  56. template<typename Archiver>
  57. void serialize(Archiver& ar, const unsigned /*version*/)
  58. {
  59. ar & unsafe_serialize(first) & unsafe_serialize(second);
  60. }
  61. };
  62. template<typename T, typename U>
  63. bool operator<(unsafe_pair<T,U> const& x, unsafe_pair<T,U> const& y)
  64. {
  65. return std::make_pair(x.first, x.second) <
  66. std::make_pair(y.first, y.second);
  67. }
  68. } // end namespace boost
  69. #endif // PBGL_UNSAFE_SERIALIZE_HPP