]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/serialization/optional.hpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / boost / serialization / optional.hpp
1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2
3 // (C) Copyright 2002-4 Pavel Vozenilek .
4 // Use, modification and distribution is subject to the Boost Software
5 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7
8 // Provides non-intrusive serialization for boost::optional.
9
10 #ifndef BOOST_SERIALIZATION_OPTIONAL_HPP_
11 #define BOOST_SERIALIZATION_OPTIONAL_HPP_
12
13 #if defined(_MSC_VER)
14 # pragma once
15 #endif
16
17 #include <boost/config.hpp>
18
19 #include <boost/archive/detail/basic_iarchive.hpp>
20
21 #include <boost/optional.hpp>
22 #include <boost/move/utility_core.hpp>
23
24 #include <boost/serialization/item_version_type.hpp>
25 #include <boost/serialization/split_free.hpp>
26 #include <boost/serialization/level.hpp>
27 #include <boost/serialization/nvp.hpp>
28 #include <boost/serialization/version.hpp>
29 #include <boost/type_traits/is_pointer.hpp>
30 #include <boost/serialization/detail/stack_constructor.hpp>
31 #include <boost/serialization/detail/is_default_constructible.hpp>
32 #include <boost/serialization/force_include.hpp>
33
34 // function specializations must be defined in the appropriate
35 // namespace - boost::serialization
36 namespace boost {
37 namespace serialization {
38
39 template<class Archive, class T>
40 void save(
41 Archive & ar,
42 const boost::optional< T > & t,
43 const unsigned int /*version*/
44 ){
45 // It is an inherent limitation to the serialization of optional.hpp
46 // that the underlying type must be either a pointer or must have a
47 // default constructor. It's possible that this could change sometime
48 // in the future, but for now, one will have to work around it. This can
49 // be done by serialization the optional<T> as optional<T *>
50 #if ! defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
51 BOOST_STATIC_ASSERT(
52 boost::serialization::detail::is_default_constructible<T>::value
53 || boost::is_pointer<T>::value
54 );
55 #endif
56 const bool tflag = t.is_initialized();
57 ar << boost::serialization::make_nvp("initialized", tflag);
58 if (tflag){
59 ar << boost::serialization::make_nvp("value", *t);
60 }
61 }
62
63 template<class Archive, class T>
64 void load(
65 Archive & ar,
66 boost::optional< T > & t,
67 const unsigned int version
68 ){
69 bool tflag;
70 ar >> boost::serialization::make_nvp("initialized", tflag);
71 if(! tflag){
72 t.reset();
73 return;
74 }
75
76 if(0 == version){
77 boost::serialization::item_version_type item_version(0);
78 boost::archive::library_version_type library_version(
79 ar.get_library_version()
80 );
81 if(boost::archive::library_version_type(3) < library_version){
82 ar >> BOOST_SERIALIZATION_NVP(item_version);
83 }
84 }
85 if(! t.is_initialized())
86 t = T();
87 ar >> boost::serialization::make_nvp("value", *t);
88 }
89
90 template<class Archive, class T>
91 void serialize(
92 Archive & ar,
93 boost::optional< T > & t,
94 const unsigned int version
95 ){
96 boost::serialization::split_free(ar, t, version);
97 }
98
99 template<class T>
100 struct version<boost::optional<T> > {
101 BOOST_STATIC_CONSTANT(int, value = 1);
102 };
103
104 } // serialization
105 } // boost
106
107 #endif // BOOST_SERIALIZATION_OPTIONAL_HPP_