serialization_version.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Copyright 2003-2013 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See http://www.boost.org/libs/multi_index for library home page.
  7. */
  8. #ifndef BOOST_MULTI_INDEX_DETAIL_SERIALIZATION_VERSION_HPP
  9. #define BOOST_MULTI_INDEX_DETAIL_SERIALIZATION_VERSION_HPP
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  14. #include <boost/serialization/split_member.hpp>
  15. #include <boost/serialization/version.hpp>
  16. namespace boost{
  17. namespace multi_index{
  18. namespace detail{
  19. /* Helper class for storing and retrieving a given type serialization class
  20. * version while avoiding saving the number multiple times in the same
  21. * archive.
  22. * Behavior undefined if template partial specialization is not supported.
  23. */
  24. template<typename T>
  25. struct serialization_version
  26. {
  27. serialization_version():
  28. value(boost::serialization::version<serialization_version>::value){}
  29. serialization_version& operator=(unsigned int x){value=x;return *this;};
  30. operator unsigned int()const{return value;}
  31. private:
  32. friend class boost::serialization::access;
  33. BOOST_SERIALIZATION_SPLIT_MEMBER()
  34. template<class Archive>
  35. void save(Archive&,const unsigned int)const{}
  36. template<class Archive>
  37. void load(Archive&,const unsigned int version)
  38. {
  39. this->value=version;
  40. }
  41. unsigned int value;
  42. };
  43. } /* namespace multi_index::detail */
  44. } /* namespace multi_index */
  45. namespace serialization {
  46. template<typename T>
  47. struct version<boost::multi_index::detail::serialization_version<T> >
  48. {
  49. BOOST_STATIC_CONSTANT(int,value=version<T>::value);
  50. };
  51. } /* namespace serialization */
  52. } /* namespace boost */
  53. #endif