version.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef BOOST_SERIALIZATION_VERSION_HPP
  2. #define BOOST_SERIALIZATION_VERSION_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. // 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/assert.hpp>
  16. #include <boost/mpl/int.hpp>
  17. #include <boost/mpl/eval_if.hpp>
  18. #include <boost/mpl/identity.hpp>
  19. #include <boost/mpl/integral_c_tag.hpp>
  20. #include <boost/type_traits/is_base_and_derived.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 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. 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(int, value = version::type::value);
  43. };
  44. #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
  45. template<class T>
  46. const int version<T>::value;
  47. #endif
  48. } // namespace serialization
  49. } // namespace boost
  50. /* note: at first it seemed that this would be a good place to trap
  51. * as an error an attempt to set a version # for a class which doesn't
  52. * save its class information (including version #) in the archive.
  53. * However, this imposes a requirement that the version be set after
  54. * the implemention level which would be pretty confusing. If this
  55. * is to be done, do this check in the input or output operators when
  56. * ALL the serialization traits are available. Included the implementation
  57. * here with this comment as a reminder not to do this!
  58. */
  59. //#include <boost/serialization/level.hpp>
  60. //#include <boost/mpl/equal_to.hpp>
  61. #include <boost/mpl/less.hpp>
  62. #include <boost/mpl/comparison.hpp>
  63. // specify the current version number for the class
  64. // version numbers limited to 8 bits !!!
  65. #define BOOST_CLASS_VERSION(T, N) \
  66. namespace boost { \
  67. namespace serialization { \
  68. template<> \
  69. struct version<T > \
  70. { \
  71. typedef mpl::int_<N> type; \
  72. typedef mpl::integral_c_tag tag; \
  73. BOOST_STATIC_CONSTANT(int, value = version::type::value); \
  74. BOOST_MPL_ASSERT(( \
  75. boost::mpl::less< \
  76. boost::mpl::int_<N>, \
  77. boost::mpl::int_<256> \
  78. > \
  79. )); \
  80. /* \
  81. BOOST_MPL_ASSERT(( \
  82. mpl::equal_to< \
  83. :implementation_level<T >, \
  84. mpl::int_<object_class_info> \
  85. >::value \
  86. )); \
  87. */ \
  88. }; \
  89. } \
  90. }
  91. #endif // BOOST_SERIALIZATION_VERSION_HPP