Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / common / boost / 1.64.0 / include / boost-1_64 / boost / mpi / detail / mpi_datatype_oarchive.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_MPI_DATATYPE_OARCHIVE_HPP
10 #define BOOST_MPI_DETAIL_MPI_DATATYPE_OARCHIVE_HPP
11
12 #include <boost/type_traits/is_enum.hpp>
13 #include <boost/mpl/bool.hpp>
14 #include <boost/archive/detail/oserializer.hpp>
15 #include <boost/archive/detail/auto_link_archive.hpp>
16 #include <boost/archive/basic_archive.hpp>
17 #include <boost/mpi/detail/ignore_skeleton_oarchive.hpp>
18 #include <boost/mpi/detail/mpi_datatype_primitive.hpp>
19 #include <boost/mpi/datatype_fwd.hpp>
20 #include <boost/mpl/assert.hpp>
21 #include <boost/static_assert.hpp>
22 #include <boost/integer.hpp>
23 #include <boost/archive/detail/register_archive.hpp>
24
25 namespace boost { namespace mpi { namespace detail {
26
27
28 // an archive wrapper that stores only the data members but not the
29 // special types defined by the serialization library
30 // to define the data skeletons (classes, pointers, container sizes, ...)
31
32 class mpi_datatype_oarchive
33   : public mpi_datatype_primitive,
34     public ignore_skeleton_oarchive<mpi_datatype_oarchive>
35 {
36 public:
37     template <class T>
38     mpi_datatype_oarchive(const T& x)
39          :  mpi_datatype_primitive(&x) // register address
40         {
41           BOOST_MPL_ASSERT((is_mpi_datatype<T>));
42           *this << x;                   // serialize the object
43         }
44
45     template<class T>
46     void save_override(T const& t)
47     {
48       save_enum(t,boost::is_enum<T>());
49     }
50
51     template<class T>
52     void save_enum(T const& t, mpl::false_)
53     {
54       ignore_skeleton_oarchive<mpi_datatype_oarchive>::save_override(t);
55     }
56
57     template<class T>
58     void save_enum(T const& t, mpl::true_)
59     {
60       // select the right sized integer for the enum
61       typedef typename boost::uint_t<8*sizeof(T)>::least int_type;
62       BOOST_STATIC_ASSERT((sizeof(T)==sizeof(int_type)));
63       this->save(*reinterpret_cast<int_type const*>(&t));
64     }
65
66 };
67
68 } } } // end namespace boost::mpi::detail
69
70 // required by export
71 BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::mpi::detail::mpi_datatype_oarchive)
72 BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::mpi::detail::ignore_skeleton_oarchive<boost::mpi::detail::mpi_datatype_oarchive>)
73 BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(boost::mpi::detail::mpi_datatype_oarchive)
74
75 #endif // BOOST_MPI_DETAIL_MPI_DATATYPE_OARCHIVE_HPP