level.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef BOOST_SERIALIZATION_LEVEL_HPP
  2. #define BOOST_SERIALIZATION_LEVEL_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. // level.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/detail/workaround.hpp>
  16. #include <boost/type_traits/is_fundamental.hpp>
  17. #include <boost/type_traits/is_enum.hpp>
  18. #include <boost/type_traits/is_array.hpp>
  19. #include <boost/type_traits/is_class.hpp>
  20. #include <boost/type_traits/is_base_and_derived.hpp>
  21. #include <boost/mpl/eval_if.hpp>
  22. #include <boost/mpl/int.hpp>
  23. #include <boost/mpl/integral_c.hpp>
  24. #include <boost/mpl/integral_c_tag.hpp>
  25. #include <boost/serialization/level_enum.hpp>
  26. namespace boost {
  27. namespace serialization {
  28. struct basic_traits;
  29. // default serialization implementation level
  30. template<class T>
  31. struct implementation_level_impl {
  32. template<class U>
  33. struct traits_class_level {
  34. typedef typename U::level type;
  35. };
  36. typedef mpl::integral_c_tag tag;
  37. // note: at least one compiler complained w/o the full qualification
  38. // on basic traits below
  39. typedef
  40. typename mpl::eval_if<
  41. is_base_and_derived<boost::serialization::basic_traits, T>,
  42. traits_class_level< T >,
  43. //else
  44. typename mpl::eval_if<
  45. is_fundamental< T >,
  46. mpl::int_<primitive_type>,
  47. //else
  48. typename mpl::eval_if<
  49. is_class< T >,
  50. mpl::int_<object_class_info>,
  51. //else
  52. typename mpl::eval_if<
  53. is_array< T >,
  54. mpl::int_<object_serializable>,
  55. //else
  56. typename mpl::eval_if<
  57. is_enum< T >,
  58. mpl::int_<primitive_type>,
  59. //else
  60. mpl::int_<not_serializable>
  61. >
  62. >
  63. >
  64. >
  65. >::type type;
  66. // vc 7.1 doesn't like enums here
  67. BOOST_STATIC_CONSTANT(int, value = type::value);
  68. };
  69. template<class T>
  70. struct implementation_level :
  71. public implementation_level_impl<const T>
  72. {
  73. };
  74. template<class T, int L>
  75. inline bool operator>=(implementation_level< T > t, enum level_type l)
  76. {
  77. return t.value >= (int)l;
  78. }
  79. } // namespace serialization
  80. } // namespace boost
  81. // specify the level of serialization implementation for the class
  82. // require that class info saved when versioning is used
  83. #define BOOST_CLASS_IMPLEMENTATION(T, E) \
  84. namespace boost { \
  85. namespace serialization { \
  86. template <> \
  87. struct implementation_level_impl< const T > \
  88. { \
  89. typedef mpl::integral_c_tag tag; \
  90. typedef mpl::int_< E > type; \
  91. BOOST_STATIC_CONSTANT( \
  92. int, \
  93. value = implementation_level_impl::type::value \
  94. ); \
  95. }; \
  96. } \
  97. }
  98. /**/
  99. #endif // BOOST_SERIALIZATION_LEVEL_HPP