PageRenderTime 28ms CodeModel.GetById 12ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 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)
 6
 7//  Authors: Douglas Gregor
 8//           Andrew Lumsdaine
 9
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 PBGL_UNSAFE_SERIALIZE_HPP
14#define PBGL_UNSAFE_SERIALIZE_HPP
15
16#ifndef BOOST_GRAPH_USE_MPI
17#error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
18#endif
19
20#include <boost/mpi/datatype.hpp>
21#include <boost/serialization/is_bitwise_serializable.hpp>
22#include <boost/mpl/bool.hpp>
23#include <boost/mpl/if.hpp>
24#include <boost/cstdint.hpp>
25#include <boost/static_assert.hpp>
26#include <boost/type_traits.hpp>
27#include <utility>
28
29BOOST_IS_BITWISE_SERIALIZABLE(void*)
30namespace boost { namespace mpi {
31    template<> struct is_mpi_datatype<void*> : mpl::true_ { };
32} } // end namespace boost::mpi
33
34namespace boost {
35  typedef mpl::if_c<(sizeof(int) == sizeof(void*)), 
36                    int, 
37                    mpl::if_c<(sizeof(long) == sizeof(void*)),
38                              long,
39                              mpl::if_c<(sizeof(void*) <= sizeof(boost::intmax_t)),
40                                        boost::intmax_t,
41                                        void>::type
42                              >::type
43                    >::type ptr_serialize_type;
44
45  BOOST_STATIC_ASSERT ((!boost::is_void<ptr_serialize_type>::value));
46    
47  template<typename T> inline T& unsafe_serialize(T& x) { return x; }
48
49  inline ptr_serialize_type& unsafe_serialize(void*& x)
50  { return reinterpret_cast<ptr_serialize_type&>(x); }
51
52  // Force Boost.MPI to serialize a void* like a ptr_serialize_type
53  namespace mpi {
54    template<> inline MPI_Datatype get_mpi_datatype<void*>(void* const& x)
55    {
56      return get_mpi_datatype<ptr_serialize_type>();
57    }
58  }
59
60  template<typename T, typename U>
61  struct unsafe_pair
62  {
63    unsafe_pair() { }
64    unsafe_pair(const T& t, const U& u) : first(t), second(u) { }
65    unsafe_pair(const std::pair<T, U>& p) : first(p.first), second(p.second) { }
66    T first;
67    U second;
68
69    template<typename Archiver>
70    void serialize(Archiver& ar, const unsigned /*version*/)
71    {
72      ar & unsafe_serialize(first) & unsafe_serialize(second);
73    }
74  };
75
76  template<typename T, typename U>
77  bool operator<(unsafe_pair<T,U> const& x, unsafe_pair<T,U> const& y)
78  {
79    return std::make_pair(x.first, x.second) < 
80      std::make_pair(y.first, y.second);  
81  }
82
83} // end namespace boost
84
85#endif // PBGL_UNSAFE_SERIALIZE_HPP