PageRenderTime 23ms CodeModel.GetById 11ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/mpi/detail/mpi_datatype_oarchive.hpp

http://hadesmem.googlecode.com/
C++ Header | 78 lines | 50 code | 15 blank | 13 comment | 0 complexity | 9c8529bebbb9ebda5f1318503c4e1c74 MD5 | raw file
 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
25namespace 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
32class mpi_datatype_oarchive
33  : public mpi_datatype_primitive,
34    public ignore_skeleton_oarchive<mpi_datatype_oarchive>
35{
36public:
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    // intermediate level to support override of operators
46    // for templates in the absence of partial function 
47    // template ordering
48    template<class T>
49    void save_override(T const& t, BOOST_PFTO int)
50    {
51      save_enum(t,boost::is_enum<T>());
52    }
53
54    template<class T>
55    void save_enum(T const& t, mpl::false_)
56    {
57      ignore_skeleton_oarchive<mpi_datatype_oarchive>::save_override(t, 0);
58    }
59
60    template<class T>
61    void save_enum(T const& t, mpl::true_)
62    {
63      // select the right sized integer for the enum
64      typedef typename boost::uint_t<8*sizeof(T)>::least int_type;
65      BOOST_STATIC_ASSERT((sizeof(T)==sizeof(int_type)));
66      this->save(*reinterpret_cast<int_type const*>(&t));
67    }
68
69};
70
71} } } // end namespace boost::mpi::detail
72
73// required by export
74BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::mpi::detail::mpi_datatype_oarchive)
75BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::mpi::detail::ignore_skeleton_oarchive<boost::mpi::detail::mpi_datatype_oarchive>)
76BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(boost::mpi::detail::mpi_datatype_oarchive)
77
78#endif // BOOST_MPI_DETAIL_MPI_DATATYPE_OARCHIVE_HPP