]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mpi/include/boost/mpi/detail/mpi_datatype_cache.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / mpi / include / boost / mpi / detail / mpi_datatype_cache.hpp
1 // (C) Copyright 2005 Matthias Troyer
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: Matthias Troyer
8
9 #ifndef BOOST_MPI_DETAIL_TYPE_MPI_DATATYPE_CACHE_HPP
10 #define BOOST_MPI_DETAIL_TYPE_MPI_DATATYPE_CACHE_HPP
11
12 #include <boost/mpi/datatype_fwd.hpp>
13 #include <boost/mpi/detail/mpi_datatype_oarchive.hpp>
14 #include <boost/mpi/exception.hpp>
15 #include <boost/utility/enable_if.hpp>
16 #include <boost/mpl/assert.hpp>
17 #include <boost/noncopyable.hpp>
18 #include <typeinfo>
19
20 // The std::type_info::before function in Visual C++ 8.0 (and probably earlier)
21 // incorrectly returns an "int" instead of a "bool". Then the compiler has the
22 // audacity to complain when that "int" is converted to a "bool". Silence
23 // this warning.
24 #ifdef BOOST_MSVC
25 # pragma warning(push)
26 # pragma warning(disable : 4800)
27 #endif
28
29 namespace boost { namespace mpi { namespace detail {
30
31 /// @brief comparison function object for two std::type_info pointers
32 ///
33 /// is implemented using the before() member function of the std::type_info
34 /// class
35
36 struct type_info_compare
37 {
38 bool operator()(std::type_info const* lhs, std::type_info const* rhs) const
39 {
40 return lhs->before(*rhs);
41 }
42 };
43
44
45 /// @brief a map of MPI data types, indexed by their type_info
46 ///
47 ///
48 class BOOST_MPI_DECL mpi_datatype_map
49 : public boost::noncopyable
50 {
51 struct implementation;
52
53 implementation *impl;
54
55 public:
56 mpi_datatype_map();
57 ~mpi_datatype_map();
58
59 template <class T>
60 MPI_Datatype datatype(const T& x = T(), typename boost::enable_if<is_mpi_builtin_datatype<T> >::type* =0)
61 {
62 return get_mpi_datatype<T>(x);
63 }
64
65 template <class T>
66 MPI_Datatype datatype(const T& x =T(), typename boost::disable_if<is_mpi_builtin_datatype<T> >::type* =0 )
67 {
68 BOOST_MPL_ASSERT((is_mpi_datatype<T>));
69
70 // check whether the type already exists
71 std::type_info const* t = &typeid(T);
72 MPI_Datatype datatype = get(t);
73 if (datatype == MPI_DATATYPE_NULL) {
74 // need to create a type
75 mpi_datatype_oarchive ar(x);
76 datatype = ar.get_mpi_datatype();
77 set(t, datatype);
78 }
79
80 return datatype;
81 }
82
83 void clear();
84
85 private:
86 MPI_Datatype get(const std::type_info* t);
87 void set(const std::type_info* t, MPI_Datatype datatype);
88 };
89
90 /// Retrieve the MPI datatype cache
91 BOOST_MPI_DECL mpi_datatype_map& mpi_datatype_cache();
92
93 } } } // end namespace boost::mpi::detail
94
95 #ifdef BOOST_MSVC
96 # pragma warning(pop)
97 #endif
98
99 #endif // BOOST_MPI_DETAIL_TYPE_MPI_DATATYPE_CACHE_HPP