split_free.hpp 2.6 KB

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