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_CONTENT_OARCHIVE_HPP
10 #define BOOST_MPI_DETAIL_CONTENT_OARCHIVE_HPP
11 
12 #include <boost/archive/detail/auto_link_archive.hpp>
13 #include <boost/archive/basic_archive.hpp>
14 #include <boost/mpi/detail/ignore_skeleton_oarchive.hpp>
15 #include <boost/mpi/detail/mpi_datatype_primitive.hpp>
16 #include <boost/mpi/datatype.hpp>
17 #include <boost/archive/detail/register_archive.hpp>
18 
19 namespace boost { namespace mpi {
20 
21 namespace detail {
22   // an archive wrapper that stores only the data members but not the
23   // special types defined by the serialization library
24   // to define the data skeletons (classes, pointers, container sizes, ...)
25 
26   class BOOST_MPI_DECL content_oarchive
27     : public mpi_datatype_primitive,
28       public ignore_skeleton_oarchive<content_oarchive>
29   {
30   public:
content_oarchive()31       content_oarchive()
32        : committed(false)
33           {}
34 
get_content()35       content get_content()
36       {
37         if (!committed)
38         {
39           // create the content holder only once
40           c=this->get_mpi_datatype();
41           committed=true;
42         }
43         return c;
44       }
45 
46   private:
47     bool committed;
48     content c;
49   };
50 } // end namespace detail
51 
52 template <class T>
get_content(const T & x)53 const content get_content(const T& x)
54 {
55   detail::content_oarchive ar;
56   ar << x;
57   return ar.get_content();
58 }
59 
60 } } // end namespace boost::mpi
61 
62 // required by export
63 BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::mpi::detail::content_oarchive)
64 BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::mpi::detail::ignore_skeleton_oarchive<boost::mpi::detail::content_oarchive>)
65 BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(boost::mpi::detail::content_oarchive)
66 #endif // BOOST_MPI_DETAIL_CONTENT_OARCHIVE_HPP
67