split_member.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef BOOST_SERIALIZATION_SPLIT_MEMBER_HPP
  2. #define BOOST_SERIALIZATION_SPLIT_MEMBER_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // split_member.hpp:
  9. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  10. // Use, modification and distribution is subject to the Boost Software
  11. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. // See http://www.boost.org for updates, documentation, and revision history.
  14. #include <boost/config.hpp>
  15. #include <boost/mpl/eval_if.hpp>
  16. #include <boost/mpl/identity.hpp>
  17. #include <boost/serialization/access.hpp>
  18. namespace boost {
  19. namespace archive {
  20. namespace detail {
  21. template<class Archive> class interface_oarchive;
  22. template<class Archive> class interface_iarchive;
  23. } // namespace detail
  24. } // namespace archive
  25. namespace serialization {
  26. namespace detail {
  27. template<class Archive, class T>
  28. struct member_saver {
  29. static void invoke(
  30. Archive & ar,
  31. const T & t,
  32. const unsigned int file_version
  33. ){
  34. access::member_save(ar, t, file_version);
  35. }
  36. };
  37. template<class Archive, class T>
  38. struct member_loader {
  39. static void invoke(
  40. Archive & ar,
  41. T & t,
  42. const unsigned int file_version
  43. ){
  44. access::member_load(ar, t, file_version);
  45. }
  46. };
  47. } // detail
  48. template<class Archive, class T>
  49. inline void split_member(
  50. Archive & ar, T & t, const unsigned int file_version
  51. ){
  52. typedef typename mpl::eval_if<
  53. typename Archive::is_saving,
  54. mpl::identity<detail::member_saver<Archive, T> >,
  55. mpl::identity<detail::member_loader<Archive, T> >
  56. >::type typex;
  57. typex::invoke(ar, t, file_version);
  58. }
  59. } // namespace serialization
  60. } // namespace boost
  61. // split member function serialize funcition into save/load
  62. #define BOOST_SERIALIZATION_SPLIT_MEMBER() \
  63. template<class Archive> \
  64. void serialize( \
  65. Archive &ar, \
  66. const unsigned int file_version \
  67. ){ \
  68. boost::serialization::split_member(ar, *this, file_version); \
  69. } \
  70. /**/
  71. #endif // BOOST_SERIALIZATION_SPLIT_MEMBER_HPP