nvp.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef BOOST_SERIALIZATION_NVP_HPP
  2. #define BOOST_SERIALIZATION_NVP_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. // nvp.hpp: interface for serialization system.
  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/core/nvp.hpp>
  15. #include <boost/preprocessor/stringize.hpp>
  16. #define BOOST_SERIALIZATION_NVP(name) \
  17. boost::serialization::make_nvp(BOOST_PP_STRINGIZE(name), name)
  18. /**/
  19. #define BOOST_SERIALIZATION_BASE_OBJECT_NVP(name) \
  20. boost::serialization::make_nvp( \
  21. BOOST_PP_STRINGIZE(name), \
  22. boost::serialization::base_object<name >(*this) \
  23. )
  24. /**/
  25. #include <boost/serialization/level.hpp>
  26. #include <boost/serialization/tracking.hpp>
  27. #include <boost/serialization/split_free.hpp>
  28. #include <boost/serialization/wrapper.hpp>
  29. #include <boost/serialization/base_object.hpp>
  30. namespace boost {
  31. namespace serialization {
  32. template<class Archive, class T>
  33. void save(
  34. Archive & ar,
  35. const nvp<T> & t,
  36. const unsigned int /* file_version */
  37. ){
  38. ar << t.const_value();
  39. }
  40. template<class Archive, class T>
  41. void load(
  42. Archive & ar,
  43. nvp<T> & t ,
  44. const unsigned int /* file_version */
  45. ){
  46. ar >> t.value();
  47. }
  48. template<class Archive, class T>
  49. inline void serialize(
  50. Archive & ar,
  51. nvp<T> & t,
  52. const unsigned int file_version
  53. ){
  54. split_free(ar, t, file_version);
  55. }
  56. template <class T>
  57. struct implementation_level<nvp< T > >
  58. {
  59. typedef mpl::integral_c_tag tag;
  60. typedef mpl::int_<object_serializable> type;
  61. BOOST_STATIC_CONSTANT(int, value = implementation_level::type::value);
  62. };
  63. template <class T>
  64. struct implementation_level<const nvp< T > >
  65. {
  66. typedef mpl::integral_c_tag tag;
  67. typedef mpl::int_<object_serializable> type;
  68. BOOST_STATIC_CONSTANT(int, value = implementation_level::type::value);
  69. };
  70. // nvp objects are generally created on the stack and are never tracked
  71. template<class T>
  72. struct tracking_level<nvp< T > >
  73. {
  74. typedef mpl::integral_c_tag tag;
  75. typedef mpl::int_<track_never> type;
  76. BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value);
  77. };
  78. template<class T>
  79. struct tracking_level<const nvp< T > >
  80. {
  81. typedef mpl::integral_c_tag tag;
  82. typedef mpl::int_<track_never> type;
  83. BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value);
  84. };
  85. // these traits aren't used by nvp so they don't need to be defined
  86. #if 0
  87. template<class T>
  88. struct version<const nvp< T > > {
  89. typedef mpl::integral_c_tag tag;
  90. typedef mpl::int_<0> type;
  91. BOOST_STATIC_CONSTANT(int, value = 0);
  92. };
  93. struct version<const nvp< T > > {
  94. typedef mpl::integral_c_tag tag;
  95. typedef mpl::int_<0> type;
  96. BOOST_STATIC_CONSTANT(int, value = 0);
  97. };
  98. template<class T>
  99. struct extended_type_info_impl<const nvp< T > > {
  100. typedef extended_type_info_impl< T > type;
  101. };
  102. #endif
  103. template<class T>
  104. struct is_wrapper<const nvp<T> > {
  105. typedef boost::mpl::true_ type;
  106. };
  107. template<class T>
  108. struct is_wrapper<nvp<T> > {
  109. typedef boost::mpl::true_ type;
  110. };
  111. } // serialization
  112. } // boost
  113. #endif // BOOST_SERIALIZATION_NVP_HPP