serialization_version.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright 2003-2023 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/core/serialization.hpp>
  15. namespace boost{
  16. namespace multi_index{
  17. namespace detail{
  18. /* Helper class for storing and retrieving a given type serialization class
  19. * version while avoiding saving the number multiple times in the same
  20. * archive.
  21. * Behavior undefined if template partial specialization is not supported.
  22. */
  23. template<typename T>
  24. struct serialization_version
  25. {
  26. serialization_version():
  27. value(boost::serialization::version<serialization_version>::value){}
  28. serialization_version& operator=(unsigned int x){value=x;return *this;};
  29. operator unsigned int()const{return value;}
  30. private:
  31. friend class boost::serialization::access;
  32. template<class Archive>
  33. void serialize(Archive& ar,const unsigned int version)
  34. {
  35. core::split_member(ar,*this,version);
  36. }
  37. template<class Archive>
  38. void save(Archive&,const unsigned int)const{}
  39. template<class Archive>
  40. void load(Archive&,const unsigned int version)
  41. {
  42. this->value=version;
  43. }
  44. unsigned int value;
  45. };
  46. } /* namespace multi_index::detail */
  47. } /* namespace multi_index */
  48. namespace serialization {
  49. template<typename T>
  50. struct version<boost::multi_index::detail::serialization_version<T> >
  51. {
  52. BOOST_STATIC_CONSTANT(int,value=version<T>::value);
  53. };
  54. } /* namespace serialization */
  55. } /* namespace boost */
  56. #endif