1 // (C) Copyright 2005 Matthias Troyer
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: Matthias Troyer
9 #ifndef BOOST_MPI_DETAIL_TYPE_MPI_DATATYPE_CACHE_HPP
10 #define BOOST_MPI_DETAIL_TYPE_MPI_DATATYPE_CACHE_HPP
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>
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
25 # pragma warning(push)
26 # pragma warning(disable : 4800)
29 namespace boost { namespace mpi { namespace detail {
31 /// @brief comparison function object for two std::type_info pointers
33 /// is implemented using the before() member function of the std::type_info
36 struct type_info_compare
38 bool operator()(std::type_info const* lhs, std::type_info const* rhs) const
40 return lhs->before(*rhs);
45 /// @brief a map of MPI data types, indexed by their type_info
48 class BOOST_MPI_DECL mpi_datatype_map
49 : public boost::noncopyable
51 struct implementation;
60 MPI_Datatype datatype(const T& x = T(), typename boost::enable_if<is_mpi_builtin_datatype<T> >::type* =0)
62 return get_mpi_datatype<T>(x);
66 MPI_Datatype datatype(const T& x =T(), typename boost::disable_if<is_mpi_builtin_datatype<T> >::type* =0 )
68 BOOST_MPL_ASSERT((is_mpi_datatype<T>));
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();
86 MPI_Datatype get(const std::type_info* t);
87 void set(const std::type_info* t, MPI_Datatype datatype);
90 /// Retrieve the MPI datatype cache
91 BOOST_MPI_DECL mpi_datatype_map& mpi_datatype_cache();
93 } } } // end namespace boost::mpi::detail
99 #endif // BOOST_MPI_DETAIL_TYPE_MPI_DATATYPE_CACHE_HPP