content_oarchive.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // (C) Copyright 2005 Matthias Troyer
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Authors: Matthias Troyer
  6. #ifndef BOOST_MPI_DETAIL_CONTENT_OARCHIVE_HPP
  7. #define BOOST_MPI_DETAIL_CONTENT_OARCHIVE_HPP
  8. #include <boost/archive/detail/auto_link_archive.hpp>
  9. #include <boost/archive/basic_archive.hpp>
  10. #include <boost/mpi/detail/ignore_skeleton_oarchive.hpp>
  11. #include <boost/mpi/detail/mpi_datatype_primitive.hpp>
  12. #include <boost/mpi/datatype.hpp>
  13. #include <boost/archive/detail/register_archive.hpp>
  14. namespace boost { namespace mpi {
  15. namespace detail {
  16. // an archive wrapper that stores only the data members but not the
  17. // special types defined by the serialization library
  18. // to define the data skeletons (classes, pointers, container sizes, ...)
  19. class BOOST_MPI_DECL content_oarchive
  20. : public mpi_datatype_primitive,
  21. public ignore_skeleton_oarchive<content_oarchive>
  22. {
  23. public:
  24. content_oarchive()
  25. : committed(false)
  26. {}
  27. content get_content()
  28. {
  29. if (!committed)
  30. {
  31. // create the content holder only once
  32. c=this->get_mpi_datatype();
  33. committed=true;
  34. }
  35. return c;
  36. }
  37. private:
  38. bool committed;
  39. content c;
  40. };
  41. } // end namespace detail
  42. template <class T>
  43. const content get_content(const T& x)
  44. {
  45. detail::content_oarchive ar;
  46. ar << x;
  47. return ar.get_content();
  48. }
  49. } } // end namespace boost::mpi
  50. // required by export
  51. BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::mpi::detail::content_oarchive)
  52. BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::mpi::detail::ignore_skeleton_oarchive<boost::mpi::detail::content_oarchive>)
  53. BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(boost::mpi::detail::content_oarchive)
  54. #endif // BOOST_MPI_DETAIL_CONTENT_OARCHIVE_HPP