split_free.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef BOOST_SERIALIZATION_SPLIT_FREE_HPP
  2. #define BOOST_SERIALIZATION_SPLIT_FREE_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_free.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/serialization.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 free_saver {
  29. static void invoke(
  30. Archive & ar,
  31. const T & t,
  32. const unsigned int file_version
  33. ){
  34. // use function overload (version_type) to workaround
  35. // two-phase lookup issue
  36. const version_type v(file_version);
  37. save(ar, t, v);
  38. }
  39. };
  40. template<class Archive, class T>
  41. struct free_loader {
  42. static void invoke(
  43. Archive & ar,
  44. T & t,
  45. const unsigned int file_version
  46. ){
  47. // use function overload (version_type) to workaround
  48. // two-phase lookup issue
  49. const version_type v(file_version);
  50. load(ar, t, v);
  51. }
  52. };
  53. //} // namespace detail
  54. template<class Archive, class T>
  55. inline void split_free(
  56. Archive & ar,
  57. T & t,
  58. const unsigned int file_version
  59. ){
  60. typedef typename mpl::eval_if<
  61. typename Archive::is_saving,
  62. mpl::identity</* detail:: */ free_saver<Archive, T> >,
  63. mpl::identity</* detail:: */ free_loader<Archive, T> >
  64. >::type typex;
  65. typex::invoke(ar, t, file_version);
  66. }
  67. } // namespace serialization
  68. } // namespace boost
  69. #define BOOST_SERIALIZATION_SPLIT_FREE(T) \
  70. namespace boost { namespace serialization { \
  71. template<class Archive> \
  72. inline void serialize( \
  73. Archive & ar, \
  74. T & t, \
  75. const unsigned int file_version \
  76. ){ \
  77. split_free(ar, t, file_version); \
  78. } \
  79. }}
  80. /**/
  81. #endif // BOOST_SERIALIZATION_SPLIT_FREE_HPP