Update contrib.
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/detail/stack_constructor.hpp>
25 // function specializations must be defined in the appropriate
26 // namespace - boost::serialization
28 namespace serialization {
30 template<class Archive, class T>
33 const boost::optional<T> & t,
34 const unsigned int /*version*/
36 const bool tflag = t.is_initialized();
37 ar << boost::serialization::make_nvp("initialized", tflag);
39 if(3 < ar.get_library_version()){
40 const int v = version<T>::value;
41 ar << make_nvp("item_version", v);
43 ar << boost::serialization::make_nvp("value", *t);
47 template<class Archive, class T>
50 boost::optional<T> & t,
51 const unsigned int /*version*/
54 ar >> boost::serialization::make_nvp("initialized", tflag);
57 if(3 < ar.get_library_version()){
58 ar >> make_nvp("item_version", v);
60 detail::stack_construct<Archive, T> aux(ar, v);
61 ar >> boost::serialization::make_nvp("value", aux.reference());
62 t.reset(aux.reference());
69 template<class Archive, class T>
72 boost::optional<T> & t,
73 const unsigned int version
75 boost::serialization::split_free(ar, t, version);
78 // the following would be slightly more efficient. But it
79 // would mean that archives created with programs that support
80 // TPS wouldn't be readable by programs that don't support TPS.
81 // Hence we decline to support this otherwise convenient optimization.
82 //#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
86 struct implementation_level<optional<T> >
88 typedef mpl::integral_c_tag tag;
89 typedef mpl::int_<boost::serialization::object_serializable> type;
90 BOOST_STATIC_CONSTANT(
92 value = boost::serialization::implementation_level::type::value
97 struct tracking_level<optional<T> >
99 typedef mpl::integral_c_tag tag;
100 typedef mpl::int_<boost::serialization::track_never> type;
101 BOOST_STATIC_CONSTANT(
103 value = boost::serialization::tracking_level::type::value
112 #endif // BOOST_SERIALIZATION_OPTIONAL_HPP_