fix doc example typo
[boost.git] / boost / mpi / packed_oarchive.hpp
blob274b1f04a665e7194363c07af8e0e628c8f7107c
1 // (C) Copyright 2005 Matthias Troyer
2 // (C) Copyright 2006 Douglas Gregor <doug.gregor -at- gmail.com>
4 // Use, modification and distribution is subject to the Boost Software
5 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // Authors: Matthias Troyer
9 // Douglas Gregor
11 /** @file packed_oarchive.hpp
13 * This header provides the facilities for unpacking Serializable
14 * data types from a buffer using @c MPI_Unpack. The buffers are
15 * typically received via MPI and have been packed either by via the
16 * facilities in @c packed_iarchive.hpp or @c MPI_Pack.
18 #ifndef BOOST_MPI_PACKED_OARCHIVE_HPP
19 #define BOOST_MPI_PACKED_OARCHIVE_HPP
21 #include <boost/mpi/datatype.hpp>
22 #include <boost/archive/detail/auto_link_archive.hpp>
23 #include <boost/archive/basic_binary_oarchive.hpp>
24 #include <boost/mpi/detail/packed_oprimitive.hpp>
25 #include <boost/mpi/detail/binary_buffer_oprimitive.hpp>
27 namespace boost { namespace mpi {
29 #ifdef BOOST_MPI_HOMOGENEOUS
30 typedef binary_buffer_oprimitive oprimitive;
31 #else
32 typedef packed_oprimitive oprimitive;
33 #endif
35 /** @brief An archive that unpacks binary data from an MPI buffer.
37 * The @c packed_oarchive class is an Archiver (as in the
38 * Boost.Serialization library) that unpacks binary data from a
39 * buffer received via MPI. It can operate on any Serializable data
40 * type and will use the @c MPI_Unpack function of the underlying MPI
41 * implementation to perform deserialization.
44 class BOOST_MPI_DECL packed_oarchive
45 : public oprimitive,
46 public archive::basic_binary_oarchive<packed_oarchive>
48 public:
49 /**
50 * Construct a @c packed_oarchive to receive data over the given
51 * MPI communicator and with an initial buffer.
53 * @param comm The communicator over which this archive will be
54 * received.
56 * @param b A user-defined buffer that contains the binary
57 * representation of serialized objects.
59 * @param flags Control the serialization of the data types. Refer
60 * to the Boost.Serialization documentation before changing the
61 * default flags.
63 packed_oarchive( MPI_Comm const & comm, buffer_type & b, unsigned int flags = boost::archive::no_header)
64 : oprimitive(b,comm),
65 archive::basic_binary_oarchive<packed_oarchive>(flags)
68 /**
69 * Construct a @c packed_oarchive to receive data over the given
70 * MPI communicator.
72 * @param comm The communicator over which this archive will be
73 * received.
75 * @param flags Control the serialization of the data types. Refer
76 * to the Boost.Serialization documentation before changing the
77 * default flags.
79 packed_oarchive ( MPI_Comm const & comm, unsigned int flags = boost::archive::no_header)
80 : oprimitive(internal_buffer_,comm),
81 archive::basic_binary_oarchive<packed_oarchive>(flags)
84 // Save everything else in the usual way, forwarding on to the Base class
85 template<class T>
86 void save_override(T const& x, int version, mpl::false_)
88 archive::basic_binary_oarchive<packed_oarchive>::save_override(x,version);
91 // Save it directly using the primnivites
92 template<class T>
93 void save_override(T const& x, int /*version*/, mpl::true_)
95 oprimitive::save(x);
98 // Save all supported datatypes directly
99 template<class T>
100 void save_override(T const& x, int version)
102 typedef typename mpl::apply1<use_array_optimization,T>::type use_optimized;
103 save_override(x, version, use_optimized());
106 private:
107 /// An internal buffer to be used when the user does not supply his
108 /// own buffer.
109 buffer_type internal_buffer_;
112 } } // end namespace boost::mpi
114 // required by export
115 BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::mpi::packed_oarchive)
116 BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(boost::mpi::packed_oarchive)
120 #endif // BOOST_MPI_PACKED_OARCHIVE_HPP