sl@0: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 sl@0: sl@0: // (C) Copyright 2002-4 Pavel Vozenilek . sl@0: // Use, modification and distribution is subject to the Boost Software sl@0: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: // Provides non-intrusive serialization for boost::optional. sl@0: sl@0: #ifndef BOOST_SERIALIZATION_OPTIONAL_HPP_ sl@0: #define BOOST_SERIALIZATION_OPTIONAL_HPP_ sl@0: sl@0: #if defined(_MSC_VER) && (_MSC_VER >= 1020) sl@0: # pragma once sl@0: #endif sl@0: sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: // function specializations must be defined in the appropriate sl@0: // namespace - boost::serialization sl@0: namespace boost { sl@0: namespace serialization { sl@0: sl@0: template sl@0: void save( sl@0: Archive & ar, sl@0: const boost::optional & t, sl@0: const unsigned int /*version*/ sl@0: ){ sl@0: const bool tflag = t.is_initialized(); sl@0: ar << boost::serialization::make_nvp("initialized", tflag); sl@0: if (tflag){ sl@0: if(3 < ar.get_library_version()){ sl@0: const int v = version::value; sl@0: ar << make_nvp("item_version", v); sl@0: } sl@0: ar << boost::serialization::make_nvp("value", *t); sl@0: } sl@0: } sl@0: sl@0: template sl@0: void load( sl@0: Archive & ar, sl@0: boost::optional & t, sl@0: const unsigned int /*version*/ sl@0: ){ sl@0: bool tflag; sl@0: ar >> boost::serialization::make_nvp("initialized", tflag); sl@0: if (tflag){ sl@0: unsigned int v; sl@0: if(3 < ar.get_library_version()){ sl@0: ar >> make_nvp("item_version", v); sl@0: } sl@0: detail::stack_construct aux(ar, v); sl@0: ar >> boost::serialization::make_nvp("value", aux.reference()); sl@0: t.reset(aux.reference()); sl@0: } sl@0: else { sl@0: t.reset(); sl@0: } sl@0: } sl@0: sl@0: template sl@0: void serialize( sl@0: Archive & ar, sl@0: boost::optional & t, sl@0: const unsigned int version sl@0: ){ sl@0: boost::serialization::split_free(ar, t, version); sl@0: } sl@0: sl@0: // the following would be slightly more efficient. But it sl@0: // would mean that archives created with programs that support sl@0: // TPS wouldn't be readable by programs that don't support TPS. sl@0: // Hence we decline to support this otherwise convenient optimization. sl@0: //#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION sl@0: #if 0 sl@0: sl@0: template sl@0: struct implementation_level > sl@0: { sl@0: typedef mpl::integral_c_tag tag; sl@0: typedef mpl::int_ type; sl@0: BOOST_STATIC_CONSTANT( sl@0: int , sl@0: value = boost::serialization::implementation_level::type::value sl@0: ); sl@0: }; sl@0: sl@0: template sl@0: struct tracking_level > sl@0: { sl@0: typedef mpl::integral_c_tag tag; sl@0: typedef mpl::int_ type; sl@0: BOOST_STATIC_CONSTANT( sl@0: int , sl@0: value = boost::serialization::tracking_level::type::value sl@0: ); sl@0: }; sl@0: sl@0: #endif sl@0: sl@0: } // serialization sl@0: } // namespace boost sl@0: sl@0: #endif // BOOST_SERIALIZATION_OPTIONAL_HPP_