1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
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)
8 // Provides non-intrusive serialization for boost::optional.
10 #ifndef BOOST_SERIALIZATION_OPTIONAL_HPP_
11 #define BOOST_SERIALIZATION_OPTIONAL_HPP_
13 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
17 #include <boost/config.hpp>
19 #include <boost/optional.hpp>
20 #include <boost/serialization/split_free.hpp>
21 #include <boost/serialization/level.hpp>
22 #include <boost/serialization/nvp.hpp>
23 #include <boost/serialization/version.hpp>
24 #include <boost/serialization/detail/stack_constructor.hpp>
26 // function specializations must be defined in the appropriate
27 // namespace - boost::serialization
29 namespace serialization
{
31 template<class Archive
, class T
>
34 const boost::optional
<T
> & t
,
35 const unsigned int /*version*/
37 const bool tflag
= t
.is_initialized();
38 ar
<< boost::serialization::make_nvp("initialized", tflag
);
40 if(3 < ar
.get_library_version()){
41 const int v
= version
<T
>::value
;
42 ar
<< boost::serialization::make_nvp("item_version", v
);
44 ar
<< boost::serialization::make_nvp("value", *t
);
48 template<class Archive
, class T
>
51 boost::optional
<T
> & t
,
52 const unsigned int /*version*/
55 ar
>> boost::serialization::make_nvp("initialized", tflag
);
58 if(3 < ar
.get_library_version()){
59 ar
>> boost::serialization::make_nvp("item_version", v
);
61 detail::stack_construct
<Archive
, T
> aux(ar
, v
);
62 ar
>> boost::serialization::make_nvp("value", aux
.reference());
63 t
.reset(aux
.reference());
70 template<class Archive
, class T
>
73 boost::optional
<T
> & t
,
74 const unsigned int version
76 boost::serialization::split_free(ar
, t
, version
);
79 // the following would be slightly more efficient. But it
80 // would mean that archives created with programs that support
81 // TPS wouldn't be readable by programs that don't support TPS.
82 // Hence we decline to support this otherwise convenient optimization.
83 //#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
87 struct implementation_level
<optional
<T
> >
89 typedef mpl::integral_c_tag tag
;
90 typedef mpl::int_
<boost::serialization::object_serializable
> type
;
91 BOOST_STATIC_CONSTANT(
93 value
= boost::serialization::implementation_level::type::value
98 struct tracking_level
<optional
<T
> >
100 typedef mpl::integral_c_tag tag
;
101 typedef mpl::int_
<boost::serialization::track_never
> type
;
102 BOOST_STATIC_CONSTANT(
104 value
= boost::serialization::tracking_level::type::value
113 #endif // BOOST_SERIALIZATION_OPTIONAL_HPP_