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
9#ifndef BOOST_MULTI_INDEX_DETAIL_SERIALIZATION_VERSION_HPP
10#define BOOST_MULTI_INDEX_DETAIL_SERIALIZATION_VERSION_HPP
11
12#if defined(_MSC_VER)
13#pragma once
14#endif
15
16#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
17#include <boost/core/serialization.hpp>
18
19namespace boost{
20
21namespace multi_index{
22
23namespace detail{
24
25/* Helper class for storing and retrieving a given type serialization class
26 * version while avoiding saving the number multiple times in the same
27 * archive.
28 * Behavior undefined if template partial specialization is not supported.
29 */
30
31template<typename T>
32struct serialization_version
33{
34 serialization_version():
35 value(boost::serialization::version<serialization_version>::value){}
36
37 serialization_version& operator=(unsigned int x){value=x;return *this;};
38
39 operator unsigned int()const{return value;}
40
41private:
42 friend class boost::serialization::access;
43
44 template<class Archive>
45 void serialize(Archive& ar,const unsigned int version)
46 {
47 core::split_member(ar,*this,version);
48 }
49
50 template<class Archive>
51 void save(Archive&,const unsigned int)const{}
52
53 template<class Archive>
54 void load(Archive&,const unsigned int version)
55 {
56 this->value=version;
57 }
58
59 unsigned int value;
60};
61
62} /* namespace multi_index::detail */
63
64} /* namespace multi_index */
65
66namespace serialization {
67template<typename T>
68struct version<boost::multi_index::detail::serialization_version<T> >
69{
70 BOOST_STATIC_CONSTANT(int,value=version<T>::value);
71};
72} /* namespace serialization */
73
74} /* namespace boost */
75
76#endif
77