os/ossrv/ossrv_pub/boost_apis/boost/serialization/variant.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/serialization/variant.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,161 @@
     1.4 +#ifndef BOOST_SERIALIZATION_VARIANT_HPP
     1.5 +#define BOOST_SERIALIZATION_VARIANT_HPP
     1.6 +
     1.7 +// MS compatible compilers support #pragma once
     1.8 +#if defined(_MSC_VER) && (_MSC_VER >= 1020)
     1.9 +# pragma once
    1.10 +#endif
    1.11 +
    1.12 +#if defined(_MSC_VER) && (_MSC_VER <= 1020)
    1.13 +#  pragma warning (disable : 4786) // too long name, harmless warning
    1.14 +#endif
    1.15 +
    1.16 +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
    1.17 +// variant.hpp - non-intrusive serialization of variant types
    1.18 +//
    1.19 +// copyright (c) 2005   
    1.20 +// troy d. straszheim <troy@resophonic.com>
    1.21 +// http://www.resophonic.com
    1.22 +//
    1.23 +// Use, modification and distribution is subject to the Boost Software
    1.24 +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    1.25 +// http://www.boost.org/LICENSE_1_0.txt)
    1.26 +//
    1.27 +// See http://www.boost.org for updates, documentation, and revision history.
    1.28 +//
    1.29 +// thanks to Robert Ramey, Peter Dimov, and Richard Crossley.
    1.30 +//
    1.31 +
    1.32 +#include <boost/mpl/front.hpp>
    1.33 +#include <boost/mpl/pop_front.hpp>
    1.34 +#include <boost/mpl/eval_if.hpp>
    1.35 +#include <boost/mpl/identity.hpp>
    1.36 +#include <boost/mpl/size.hpp>
    1.37 +#include <boost/mpl/empty.hpp>
    1.38 +
    1.39 +#include <boost/throw_exception.hpp>
    1.40 +
    1.41 +#include <boost/variant.hpp>
    1.42 +
    1.43 +#include <boost/archive/archive_exception.hpp>
    1.44 +
    1.45 +#include <boost/serialization/split_free.hpp>
    1.46 +#include <boost/serialization/serialization.hpp>
    1.47 +
    1.48 +namespace boost {
    1.49 +namespace serialization {
    1.50 +
    1.51 +template<class Archive>
    1.52 +struct variant_save_visitor : boost::static_visitor<> {
    1.53 +    variant_save_visitor(Archive& ar) :
    1.54 +        m_ar(ar)
    1.55 +    {}
    1.56 +    template<class T>
    1.57 +    void operator()(T const & value) const
    1.58 +    {
    1.59 +        m_ar << BOOST_SERIALIZATION_NVP(value);
    1.60 +    }
    1.61 +private:
    1.62 +    Archive & m_ar;
    1.63 +};
    1.64 +
    1.65 +template<class Archive, BOOST_VARIANT_ENUM_PARAMS(/* typename */ class T)>
    1.66 +void save(
    1.67 +    Archive & ar,
    1.68 +    boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const & v,
    1.69 +    unsigned int version
    1.70 +){
    1.71 +    int which = v.which();
    1.72 +    ar << BOOST_SERIALIZATION_NVP(which);
    1.73 +    typedef BOOST_DEDUCED_TYPENAME  boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types types;
    1.74 +    variant_save_visitor<Archive> visitor(ar);
    1.75 +    v.apply_visitor(visitor);
    1.76 +}
    1.77 +
    1.78 +template<class S>
    1.79 +struct variant_impl {
    1.80 +
    1.81 +    struct load_null {
    1.82 +        template<class Archive, class V>
    1.83 +        static void invoke(
    1.84 +            Archive & ar,
    1.85 +            int which,
    1.86 +            V & v,
    1.87 +            unsigned int version
    1.88 +        ){}
    1.89 +    };
    1.90 +
    1.91 +    struct load_impl {
    1.92 +        template<class Archive, class V>
    1.93 +        static void invoke(
    1.94 +            Archive & ar,
    1.95 +            int which,
    1.96 +            V & v,
    1.97 +            unsigned int version
    1.98 +        ){
    1.99 +            if(which == 0){
   1.100 +                // note: A non-intrusive implementation (such as this one)
   1.101 +                // necessary has to copy the value.  This wouldn't be necessary
   1.102 +                // with an implementation that de-serialized to the address of the
   1.103 +                // aligned storage included in the variant.
   1.104 +                typedef BOOST_DEDUCED_TYPENAME mpl::front<S>::type head_type;
   1.105 +                head_type value;
   1.106 +                ar >> BOOST_SERIALIZATION_NVP(value);
   1.107 +                v = value;
   1.108 +                ar.reset_object_address(& boost::get<head_type>(v), & value);
   1.109 +                return;
   1.110 +            }
   1.111 +            typedef BOOST_DEDUCED_TYPENAME mpl::pop_front<S>::type type;
   1.112 +            variant_impl<type>::load(ar, which - 1, v, version);
   1.113 +        }
   1.114 +    };
   1.115 +
   1.116 +    template<class Archive, class V>
   1.117 +    static void load(
   1.118 +        Archive & ar,
   1.119 +        int which,
   1.120 +        V & v,
   1.121 +        unsigned int version
   1.122 +    ){
   1.123 +        typedef BOOST_DEDUCED_TYPENAME mpl::eval_if<mpl::empty<S>,
   1.124 +            mpl::identity<load_null>,
   1.125 +            mpl::identity<load_impl>
   1.126 +        >::type typex;
   1.127 +        typex::invoke(ar, which, v, version);
   1.128 +    }
   1.129 +
   1.130 +};
   1.131 +
   1.132 +template<class Archive, BOOST_VARIANT_ENUM_PARAMS(/* typename */ class T)>
   1.133 +void load(
   1.134 +    Archive & ar, 
   1.135 +    boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& v,
   1.136 +    unsigned int version
   1.137 +){
   1.138 +    int which;
   1.139 +    typedef BOOST_DEDUCED_TYPENAME boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types types;
   1.140 +    ar >> BOOST_SERIALIZATION_NVP(which);
   1.141 +    if(which >=  mpl::size<types>::value)
   1.142 +        // this might happen if a type was removed from the list of variant types
   1.143 +        boost::throw_exception(
   1.144 +            boost::archive::archive_exception(
   1.145 +                boost::archive::archive_exception::unsupported_version
   1.146 +            )
   1.147 +        );
   1.148 +    variant_impl<types>::load(ar, which, v, version);
   1.149 +}
   1.150 +
   1.151 +template<class Archive,BOOST_VARIANT_ENUM_PARAMS(/* typename */ class T)>
   1.152 +inline void serialize(
   1.153 +    Archive & ar,
   1.154 +    boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> & v,
   1.155 +    unsigned int file_version
   1.156 +){
   1.157 +    split_free(ar,v,file_version);
   1.158 +}
   1.159 +
   1.160 +} // namespace serialization
   1.161 +} // namespace boost
   1.162 +
   1.163 +#endif //BOOST_SERIALIZATION_VARIANT_HPP
   1.164 +