serialization_version.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Copyright 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 https://www.boost.org/libs/unordered for library home page.
  7. */
  8. #ifndef BOOST_UNORDERED_DETAIL_SERIALIZATION_VERSION_HPP
  9. #define BOOST_UNORDERED_DETAIL_SERIALIZATION_VERSION_HPP
  10. #include <boost/config.hpp>
  11. #include <boost/core/serialization.hpp>
  12. namespace boost{
  13. namespace unordered{
  14. namespace detail{
  15. /* boost::serialization::load_construct_adl(ar,t,version) requires user code
  16. * to pass the serialization version for t, when this information is really
  17. * stored in the archive. serialization_version<T> circumvents this design
  18. * error by acting as a regular serializable type with the same serialization
  19. * version as T; loading/saving serialization_version<T> does nothing with
  20. * the archive data itself but captures the stored serialization version
  21. * at load() time.
  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,unsigned int version)
  34. {
  35. core::split_member(ar,*this,version);
  36. }
  37. template<class Archive>
  38. void save(Archive&,unsigned int)const{}
  39. template<class Archive>
  40. void load(Archive&,unsigned int version)
  41. {
  42. this->value=version;
  43. }
  44. unsigned int value;
  45. };
  46. } /* namespace detail */
  47. } /* namespace unordered */
  48. namespace serialization{
  49. template<typename T>
  50. struct version<boost::unordered::detail::serialization_version<T> >
  51. {
  52. BOOST_STATIC_CONSTANT(int,value=version<T>::value);
  53. };
  54. } /* namespace serialization */
  55. } /* namespace boost */
  56. #endif