forward_oprimitive.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_FORWARD_OPRIMITIVE_HPP
  7. #define BOOST_MPI_DETAIL_FORWARD_OPRIMITIVE_HPP
  8. #include <boost/config.hpp>
  9. #include <boost/serialization/array.hpp>
  10. namespace boost { namespace mpi { namespace detail {
  11. /// @brief a minimal output archive, which forwards saving to another archive
  12. ///
  13. /// This class template is designed to use the saving facilities of another
  14. /// output archive (the "implementation archive", whose type is specified by
  15. /// the template argument, to handle serialization of primitive types,
  16. /// while serialization for specific types can be overriden independently
  17. /// of that archive.
  18. template <class ImplementationArchive>
  19. class forward_oprimitive
  20. {
  21. public:
  22. /// the type of the archive to which the saving of primitive types will be forwarded
  23. typedef ImplementationArchive implementation_archive_type;
  24. /// the constructor takes a reference to the implementation archive used for saving primitve types
  25. forward_oprimitive(implementation_archive_type& ar)
  26. : implementation_archive(ar)
  27. {}
  28. /// binary saving is forwarded to the implementation archive
  29. void save_binary(const void * address, std::size_t count)
  30. {
  31. implementation_archive.save_binary(address,count);
  32. }
  33. /// saving of arrays is forwarded to the implementation archive
  34. template<class T>
  35. void save_array(serialization::array_wrapper<T> const& x, unsigned int file_version )
  36. {
  37. implementation_archive.save_array(x,file_version);
  38. }
  39. typedef typename ImplementationArchive::use_array_optimization use_array_optimization;
  40. #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
  41. friend class archive::save_access;
  42. protected:
  43. #else
  44. public:
  45. #endif
  46. /// saving of primitives is forwarded to the implementation archive
  47. template<class T>
  48. void save(const T & t)
  49. {
  50. implementation_archive << t;
  51. }
  52. private:
  53. implementation_archive_type& implementation_archive;
  54. };
  55. } } } // end namespace boost::mpi::detail
  56. #endif // BOOST_MPI_DETAIL_FORWARD_OPRIMITIVE_HPP