Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/serialization/optional.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
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) && (_MSC_VER >= 1020) | |
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/serialization/item_version_type.hpp> | |
23 #include <boost/serialization/split_free.hpp> | |
24 #include <boost/serialization/level.hpp> | |
25 #include <boost/serialization/nvp.hpp> | |
26 #include <boost/serialization/version.hpp> | |
27 #include <boost/serialization/detail/stack_constructor.hpp> | |
28 | |
29 // function specializations must be defined in the appropriate | |
30 // namespace - boost::serialization | |
31 namespace boost { | |
32 namespace serialization { | |
33 | |
34 template<class Archive, class T> | |
35 void save( | |
36 Archive & ar, | |
37 const boost::optional< T > & t, | |
38 const unsigned int /*version*/ | |
39 ){ | |
40 const bool tflag = t.is_initialized(); | |
41 ar << boost::serialization::make_nvp("initialized", tflag); | |
42 if (tflag){ | |
43 const boost::serialization::item_version_type item_version(version< T >::value); | |
44 #if 0 | |
45 const boost::archive::library_version_type library_version( | |
46 ar.get_library_version() | |
47 }; | |
48 if(boost::archive::library_version_type(3) < library_version){ | |
49 ar << BOOST_SERIALIZATION_NVP(item_version); | |
50 } | |
51 #else | |
52 ar << BOOST_SERIALIZATION_NVP(item_version); | |
53 #endif | |
54 ar << boost::serialization::make_nvp("value", *t); | |
55 } | |
56 } | |
57 | |
58 template<class Archive, class T> | |
59 void load( | |
60 Archive & ar, | |
61 boost::optional< T > & t, | |
62 const unsigned int /*version*/ | |
63 ){ | |
64 bool tflag; | |
65 ar >> boost::serialization::make_nvp("initialized", tflag); | |
66 if (tflag){ | |
67 boost::serialization::item_version_type item_version(0); | |
68 boost::archive::library_version_type library_version( | |
69 ar.get_library_version() | |
70 ); | |
71 if(boost::archive::library_version_type(3) < library_version){ | |
72 // item_version is handled as an attribute so it doesnt need an NVP | |
73 ar >> BOOST_SERIALIZATION_NVP(item_version); | |
74 } | |
75 detail::stack_construct<Archive, T> aux(ar, item_version); | |
76 ar >> boost::serialization::make_nvp("value", aux.reference()); | |
77 t.reset(aux.reference()); | |
78 } | |
79 else { | |
80 t.reset(); | |
81 } | |
82 } | |
83 | |
84 template<class Archive, class T> | |
85 void serialize( | |
86 Archive & ar, | |
87 boost::optional< T > & t, | |
88 const unsigned int version | |
89 ){ | |
90 boost::serialization::split_free(ar, t, version); | |
91 } | |
92 | |
93 // the following would be slightly more efficient. But it | |
94 // would mean that archives created with programs that support | |
95 // TPS wouldn't be readable by programs that don't support TPS. | |
96 // Hence we decline to support this otherwise convenient optimization. | |
97 //#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION | |
98 #if 0 | |
99 | |
100 template <class T> | |
101 struct implementation_level<optional< T > > | |
102 { | |
103 typedef mpl::integral_c_tag tag; | |
104 typedef mpl::int_<boost::serialization::object_serializable> type; | |
105 BOOST_STATIC_CONSTANT( | |
106 int , | |
107 value = boost::serialization::implementation_level::type::value | |
108 ); | |
109 }; | |
110 | |
111 template<class T> | |
112 struct tracking_level<optional< T > > | |
113 { | |
114 typedef mpl::integral_c_tag tag; | |
115 typedef mpl::int_<boost::serialization::track_never> type; | |
116 BOOST_STATIC_CONSTANT( | |
117 int , | |
118 value = boost::serialization::tracking_level::type::value | |
119 ); | |
120 }; | |
121 | |
122 #endif | |
123 | |
124 } // serialization | |
125 } // namespace boost | |
126 | |
127 #endif // BOOST_SERIALIZATION_OPTIONAL_HPP_ |