level.hpp 3.9 KB

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