예제 #1
0
inline
void CEREAL_SAVE_FUNCTION_NAME(Archive &ar, boost::variant<VariantTypes...> const &variant) {
    int32_t which = variant.which();
    ar(CEREAL_NVP_("which", which));
    variant_detail::variant_save_visitor<Archive> visitor(ar);
    variant.apply_visitor(visitor);
}
예제 #2
0
    void serialize_vc6(
        SF::Archive &                                       ar, 
        boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) > &    v,
        const unsigned int)
    {
        if (ar.isWrite())
        {
            ar & int(v.which());
            VariantSerializer variantSerializer(ar);
            v.apply_visitor(variantSerializer);
        }
        else
        {
            int which = 0;
            ar & which;
            
            typedef BOOST_DEDUCED_TYPENAME 
                boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types types;

            if(which >=  boost::mpl::size<types>::value)
            {
                RCF::Exception e( 
                    RCF::_RcfError_VariantDeserialization(
                        which, 
                        boost::mpl::size<types>::value), 
                    "boost::variant mismatch");

                RCF_THROW(e);
            }

            VariantDeserializer<types>::load(ar, which, v);
        }
    }
예제 #3
0
 //! Saving for boost::variant
 template <class Archive, typename... VariantTypes> inline
 void save( Archive & ar, boost::variant<VariantTypes...> const & variant )
 {
   int32_t which = variant.which();
   ar( _CEREAL_NVP("which", which) );
   binary_detail::variant_save_visitor<Archive> visitor(ar);
   variant.apply_visitor(visitor);
 }
예제 #4
0
파일: variant.hpp 프로젝트: imos/icfpc2015
void save(
    Archive & ar,
    boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const & v,
    unsigned int /*version*/
){
    int which = v.which();
    ar << BOOST_SERIALIZATION_NVP(which);
    typedef typename  boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types types;
    variant_save_visitor<Archive> visitor(ar);
    v.apply_visitor(visitor);
}
예제 #5
0
void serialize(Archive& ar, boost::variant<int*, std::string*>& g, const unsigned int version)
{
    if (Archive::is_loading::value)
    {
        std::cout << "Deserialize variant..." << std::endl;
        int which;
        ar& which;

        if (which == 0)
        {
            if (g.which() != which)
            {
                std::cout << "input is not int, make new!" << std::endl;
                g = new int();
            }
            int* ptr = boost::get<int*>(g);
            ar&* ptr;
        }
        else if (which == 1)
        {
            if (g.which() != which)
            {
                std::cout << "input is not string, make new!" << std::endl;
                g = new std::string();
            }
            std::string* ptr = boost::get<std::string*>(g);
            ar&* ptr;
        }
    }
    else
    {
        std::cout << "Serialize variant..." << std::endl;
        int a = g.which();
        ar& a;
        if (g.which() == 0)
        {
            int* ptr = boost::get<int*>(g);
            ar&* ptr;
        }
        else if (g.which() == 1)
        {
            std::string* ptr = boost::get<std::string*>(g);
            ar&* ptr;
        }
    }
    // serialize(ar, *g);
}
예제 #6
0
 void operator ()(Shuttler& shuttle,
     const boost::variant<Arg, Args...>& value, unsigned int version) const {
   typedef typename IntegerSequenceGenerator<boost::mpl::size<
     typename boost::variant<Arg, Args...>::types>::value>::type Sequence;
   int which = value.which();
   shuttle.Shuttle("which", which);
   Details::Send(shuttle, Sequence(), which, value);
 }