1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/serialization/optional.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,112 @@
1.4 +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
1.5 +
1.6 +// (C) Copyright 2002-4 Pavel Vozenilek .
1.7 +// Use, modification and distribution is subject to the Boost Software
1.8 +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
1.9 +// http://www.boost.org/LICENSE_1_0.txt)
1.10 +
1.11 +// Provides non-intrusive serialization for boost::optional.
1.12 +
1.13 +#ifndef BOOST_SERIALIZATION_OPTIONAL_HPP_
1.14 +#define BOOST_SERIALIZATION_OPTIONAL_HPP_
1.15 +
1.16 +#if defined(_MSC_VER) && (_MSC_VER >= 1020)
1.17 +# pragma once
1.18 +#endif
1.19 +
1.20 +#include <boost/config.hpp>
1.21 +
1.22 +#include <boost/optional.hpp>
1.23 +#include <boost/serialization/split_free.hpp>
1.24 +#include <boost/serialization/level.hpp>
1.25 +#include <boost/serialization/nvp.hpp>
1.26 +#include <boost/serialization/detail/stack_constructor.hpp>
1.27 +
1.28 +// function specializations must be defined in the appropriate
1.29 +// namespace - boost::serialization
1.30 +namespace boost {
1.31 +namespace serialization {
1.32 +
1.33 +template<class Archive, class T>
1.34 +void save(
1.35 + Archive & ar,
1.36 + const boost::optional<T> & t,
1.37 + const unsigned int /*version*/
1.38 +){
1.39 + const bool tflag = t.is_initialized();
1.40 + ar << boost::serialization::make_nvp("initialized", tflag);
1.41 + if (tflag){
1.42 + if(3 < ar.get_library_version()){
1.43 + const int v = version<T>::value;
1.44 + ar << make_nvp("item_version", v);
1.45 + }
1.46 + ar << boost::serialization::make_nvp("value", *t);
1.47 + }
1.48 +}
1.49 +
1.50 +template<class Archive, class T>
1.51 +void load(
1.52 + Archive & ar,
1.53 + boost::optional<T> & t,
1.54 + const unsigned int /*version*/
1.55 +){
1.56 + bool tflag;
1.57 + ar >> boost::serialization::make_nvp("initialized", tflag);
1.58 + if (tflag){
1.59 + unsigned int v;
1.60 + if(3 < ar.get_library_version()){
1.61 + ar >> make_nvp("item_version", v);
1.62 + }
1.63 + detail::stack_construct<Archive, T> aux(ar, v);
1.64 + ar >> boost::serialization::make_nvp("value", aux.reference());
1.65 + t.reset(aux.reference());
1.66 + }
1.67 + else {
1.68 + t.reset();
1.69 + }
1.70 +}
1.71 +
1.72 +template<class Archive, class T>
1.73 +void serialize(
1.74 + Archive & ar,
1.75 + boost::optional<T> & t,
1.76 + const unsigned int version
1.77 +){
1.78 + boost::serialization::split_free(ar, t, version);
1.79 +}
1.80 +
1.81 +// the following would be slightly more efficient. But it
1.82 +// would mean that archives created with programs that support
1.83 +// TPS wouldn't be readable by programs that don't support TPS.
1.84 +// Hence we decline to support this otherwise convenient optimization.
1.85 +//#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.86 +#if 0
1.87 +
1.88 +template <class T>
1.89 +struct implementation_level<optional<T> >
1.90 +{
1.91 + typedef mpl::integral_c_tag tag;
1.92 + typedef mpl::int_<boost::serialization::object_serializable> type;
1.93 + BOOST_STATIC_CONSTANT(
1.94 + int ,
1.95 + value = boost::serialization::implementation_level::type::value
1.96 + );
1.97 +};
1.98 +
1.99 +template<class T>
1.100 +struct tracking_level<optional<T> >
1.101 +{
1.102 + typedef mpl::integral_c_tag tag;
1.103 + typedef mpl::int_<boost::serialization::track_never> type;
1.104 + BOOST_STATIC_CONSTANT(
1.105 + int ,
1.106 + value = boost::serialization::tracking_level::type::value
1.107 + );
1.108 +};
1.109 +
1.110 +#endif
1.111 +
1.112 +} // serialization
1.113 +} // namespace boost
1.114 +
1.115 +#endif // BOOST_SERIALIZATION_OPTIONAL_HPP_