forward_iprimitive.hpp 2.2 KB

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