123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- #ifndef BOOST_SERIALIZATION_VARIANT_HPP
- #define BOOST_SERIALIZATION_VARIANT_HPP
- #if defined(_MSC_VER)
- # pragma once
- #endif
- #include <boost/mpl/front.hpp>
- #include <boost/mpl/pop_front.hpp>
- #include <boost/mpl/eval_if.hpp>
- #include <boost/mpl/identity.hpp>
- #include <boost/mpl/size.hpp>
- #include <boost/mpl/empty.hpp>
- #include <boost/serialization/throw_exception.hpp>
- #include <boost/variant/variant.hpp>
- #include <boost/variant/get.hpp>
- #if BOOST_CXX_VERSION >= 201103L
- #include <boost/variant2/variant.hpp>
- #include <type_traits>
- #endif
- #ifndef BOOST_NO_CXX17_HDR_VARIANT
- #include <variant>
- #endif
- #include <boost/archive/archive_exception.hpp>
- #include <boost/serialization/split_free.hpp>
- #include <boost/serialization/serialization.hpp>
- #include <boost/serialization/nvp.hpp>
- template<class Visitor, BOOST_VARIANT_ENUM_PARAMS(class T)>
- typename Visitor::result_type visit(
- Visitor visitor,
- const boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> & t
- ){
- return boost::apply_visitor(visitor, t);
- }
- template<class Visitor, BOOST_VARIANT_ENUM_PARAMS(class T)>
- typename Visitor::result_type visit(
- Visitor visitor,
- const boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> & t,
- const boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> & u
- ){
- return boost::apply_visitor(visitor, t, u);
- }
- namespace boost {
- namespace serialization {
- template<class Archive>
- struct variant_save_visitor :
- boost::static_visitor<void>
- {
- variant_save_visitor(Archive& ar) :
- m_ar(ar)
- {}
- template<class T>
- void operator()(T const & value) const {
- m_ar << BOOST_SERIALIZATION_NVP(value);
- }
- private:
- Archive & m_ar;
- };
- template<class Archive, BOOST_VARIANT_ENUM_PARAMS(/* typename */ class T)>
- void save(
- Archive & ar,
- boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const & v,
- unsigned int
- ){
- int which = v.which();
- ar << BOOST_SERIALIZATION_NVP(which);
- variant_save_visitor<Archive> visitor(ar);
- visit(visitor, v);
- }
- #if BOOST_CXX_VERSION >= 201103L
- template<class Archive, class ...Types>
- void save(
- Archive & ar,
- boost::variant2::variant<Types...> const & v,
- unsigned int
- ){
- int which = v.index();
- ar << BOOST_SERIALIZATION_NVP(which);
- const variant_save_visitor<Archive> visitor(ar);
- visit(visitor, v);
- }
- #endif
- #ifndef BOOST_NO_CXX17_HDR_VARIANT
- template<class Archive, class ...Types>
- void save(
- Archive & ar,
- std::variant<Types...> const & v,
- unsigned int
- ){
- int which = v.index();
- ar << BOOST_SERIALIZATION_NVP(which);
- const variant_save_visitor<Archive> visitor(ar);
- visit(visitor, v);
- }
- #endif
- template<class S>
- struct variant_impl {
- struct load_null {
- template<class Archive, class V>
- static void invoke(
- Archive & ,
- std::size_t ,
- V & ,
- const unsigned int
- ){}
- };
- struct load_member {
- template<class Archive, class V>
- static void invoke(
- Archive & ar,
- std::size_t which,
- V & v,
- const unsigned int version
- ){
- if(which == 0){
-
-
-
-
- typedef typename mpl::front<S>::type head_type;
- head_type value;
- ar >> BOOST_SERIALIZATION_NVP(value);
- v = std::move(value);;
- head_type * new_address = & get<head_type>(v);
- ar.reset_object_address(new_address, & value);
- return;
- }
- typedef typename mpl::pop_front<S>::type type;
- variant_impl<type>::load_impl(ar, which - 1, v, version);
- }
- };
- template<class Archive, class V>
- static void load_impl(
- Archive & ar,
- std::size_t which,
- V & v,
- const unsigned int version
- ){
- typedef typename mpl::eval_if<mpl::empty<S>,
- mpl::identity<load_null>,
- mpl::identity<load_member>
- >::type typex;
- typex::invoke(ar, which, v, version);
- }
- };
- template<class Archive, BOOST_VARIANT_ENUM_PARAMS(/* typename */ class T)>
- void load(
- Archive & ar,
- boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& v,
- const unsigned int version
- ){
- int which;
- typedef typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types types;
- ar >> BOOST_SERIALIZATION_NVP(which);
- if(which >= mpl::size<types>::value){
-
- boost::serialization::throw_exception(
- boost::archive::archive_exception(
- boost::archive::archive_exception::unsupported_version
- )
- );
- }
- variant_impl<types>::load_impl(ar, which, v, version);
- }
- #if BOOST_CXX_VERSION >= 201103L
- template<class Archive, class ... Types>
- void load(
- Archive & ar,
- boost::variant2::variant<Types...> & v,
- const unsigned int version
- ){
- int which;
- typedef typename boost::variant<Types...>::types types;
- ar >> BOOST_SERIALIZATION_NVP(which);
- if(which >= sizeof...(Types)){
-
- boost::serialization::throw_exception(
- boost::archive::archive_exception(
- boost::archive::archive_exception::unsupported_version
- )
- );
- }
- variant_impl<types>::load_impl(ar, which, v, version);
- }
- #endif
- #ifndef BOOST_NO_CXX17_HDR_VARIANT
- template<class Archive, class ... Types>
- void load(
- Archive & ar,
- std::variant<Types...> & v,
- const unsigned int version
- ){
- int which;
- typedef typename boost::variant<Types...>::types types;
- ar >> BOOST_SERIALIZATION_NVP(which);
- if(which >= sizeof...(Types)){
-
- boost::serialization::throw_exception(
- boost::archive::archive_exception(
- boost::archive::archive_exception::unsupported_version
- )
- );
- }
- variant_impl<types>::load_impl(ar, which, v, version);
- }
- #endif
- template<class Archive,BOOST_VARIANT_ENUM_PARAMS(/* typename */ class T)>
- inline void serialize(
- Archive & ar,
- boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> & v,
- const unsigned int file_version
- ){
- boost::serialization::split_free(ar,v,file_version);
- }
- #if BOOST_CXX_VERSION >= 201103L
- template<class Archive, class ... Types>
- inline void serialize(
- Archive & ar,
- boost::variant2::variant<Types...> & v,
- const unsigned int file_version
- ){
- boost::serialization::split_free(ar,v,file_version);
- }
- #endif
- #ifndef BOOST_NO_CXX17_HDR_VARIANT
- template<class Archive, class ... Types>
- inline void serialize(
- Archive & ar,
- std::variant<Types...> & v,
- const unsigned int file_version
- ){
- boost::serialization::split_free(ar,v,file_version);
- }
- #endif
- }
- }
- #include <boost/serialization/tracking.hpp>
- namespace boost {
- namespace serialization {
- template<BOOST_VARIANT_ENUM_PARAMS(/* typename */ class T)>
- struct tracking_level<
- variant<BOOST_VARIANT_ENUM_PARAMS(T)>
- >{
- typedef mpl::integral_c_tag tag;
- typedef mpl::int_< ::boost::serialization::track_always> type;
- BOOST_STATIC_CONSTANT(int, value = type::value);
- };
- #ifndef BOOST_NO_CXX17_HDR_VARIANT
- template<class... Types>
- struct tracking_level<
- std::variant<Types...>
- >{
- typedef mpl::integral_c_tag tag;
- typedef mpl::int_< ::boost::serialization::track_always> type;
- BOOST_STATIC_CONSTANT(int, value = type::value);
- };
- #endif
- }
- }
- #endif
|