version.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef BOOST_SERIALIZATION_VERSION_HPP
  2. #define BOOST_SERIALIZATION_VERSION_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // version.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/int.hpp>
  16. #include <boost/mpl/eval_if.hpp>
  17. #include <boost/mpl/identity.hpp>
  18. #include <boost/mpl/integral_c_tag.hpp>
  19. #include <boost/type_traits/is_base_and_derived.hpp>
  20. //#include <boost/serialization/traits.hpp>
  21. namespace boost {
  22. namespace serialization {
  23. struct basic_traits;
  24. // default version number is 0. Override with higher version
  25. // when class definition changes.
  26. template<class T>
  27. struct version
  28. {
  29. template<class U>
  30. struct traits_class_version {
  31. typedef BOOST_DEDUCED_TYPENAME U::version type;
  32. };
  33. typedef mpl::integral_c_tag tag;
  34. // note: at least one compiler complained w/o the full qualification
  35. // on basic traits below
  36. typedef
  37. BOOST_DEDUCED_TYPENAME mpl::eval_if<
  38. is_base_and_derived<boost::serialization::basic_traits,T>,
  39. traits_class_version<T>,
  40. mpl::int_<0>
  41. >::type type;
  42. BOOST_STATIC_CONSTANT(unsigned int, value = version::type::value);
  43. };
  44. } // namespace serialization
  45. } // namespace boost
  46. // specify the current version number for the class
  47. #define BOOST_CLASS_VERSION(T, N) \
  48. namespace boost { \
  49. namespace serialization { \
  50. template<> \
  51. struct version<T > \
  52. { \
  53. typedef mpl::int_<N> type; \
  54. typedef mpl::integral_c_tag tag; \
  55. BOOST_STATIC_CONSTANT(unsigned int, value = version::type::value); \
  56. /* require that class info saved when versioning is used */ \
  57. /* \
  58. BOOST_STATIC_ASSERT(( \
  59. mpl::or_< \
  60. mpl::equal_to< \
  61. mpl::int_<0>, \
  62. mpl::int_<N> \
  63. >, \
  64. mpl::equal_to< \
  65. implementation_level<T>, \
  66. mpl::int_<object_class_info> \
  67. > \
  68. >::value \
  69. )); \
  70. */ \
  71. }; \
  72. } \
  73. }
  74. #endif // BOOST_SERIALIZATION_VERSION_HPP