iserializer.hpp

来自「CGAL is a collaborative effort of severa」· HPP 代码 · 共 536 行 · 第 1/2 页

HPP
536
字号
void load_ptr(    Archive & ar,     T * & t,     const BOOST_PFTO unsigned int file_version){}template<class T, class Archive>BOOST_DLLEXPORT void pointer_iserializer<T, Archive>::load_object_ptr(    basic_iarchive & ar,     void * & x,    const unsigned int file_version) const {    auto_ptr_with_deleter<T> ap(heap_allocator<T>::invoke());    if(NULL == ap.get())        boost::throw_exception(std::bad_alloc()) ;    T * t = ap.get();    x = t;    // this addresses an obscure situtation that occurs when load_constructor    // de-serializes something through and a pointer.    ar.next_object_pointer(t);    Archive & ar_impl = boost::smart_cast_reference<Archive &>(ar);    boost::serialization::load_construct_data_adl<Archive, T>(        ar_impl,        t,         file_version    );    ar_impl >> boost::serialization::make_nvp(NULL, * t);    ap.release();}template<class Archive, class T>struct load_non_pointer_type {    // note this bounces the call right back to the archive    // with no runtime overhead    struct load_primitive {        static void invoke(Archive & ar, T & t){            load_access::load_primitive(ar, t);        }    };    // note this bounces the call right back to the archive    // with no runtime overhead    struct load_only {        static void invoke(Archive & ar, T & t){            // short cut to user's serializer            // make sure call is routed through the higest interface that might            // be specialized by the user.            boost::serialization::serialize_adl(                ar, t, boost::serialization::version<T>::value            );        }    };    // note this save class information including version    // and serialization level to the archive    struct load {        static void invoke(Archive &ar, T &t){            const void * x = &t;            ar.load_object(const_cast<void *>(x), iserializer<Archive, T>::instantiate());        }    };    static void invoke(Archive & ar, T &t){        BOOST_STATIC_ASSERT((            mpl::greater_equal<                boost::serialization::implementation_level<T>,                 mpl::int_<boost::serialization::primitive_type>            >::value        ));        typedef BOOST_DEDUCED_TYPENAME mpl::eval_if<                // if its primitive                mpl::equal_to<                    boost::serialization::implementation_level<T>,                    mpl::int_<boost::serialization::primitive_type>                >,                mpl::identity<load_primitive>,            // else            BOOST_DEDUCED_TYPENAME mpl::eval_if<                mpl::and_<                    // no class info / version                    mpl::less<                        boost::serialization::implementation_level<T>,                        mpl::int_<boost::serialization::object_class_info>                    >,                    // and no tracking                    mpl::equal_to<                        boost::serialization::tracking_level<T>,                        mpl::int_<boost::serialization::track_never>                    >                >,                // do a fast load                mpl::identity<load_only>,            // else                // do standard load                mpl::identity<load>            >        >::type typex;        typex::invoke(ar, t);    }};template<class Archive, class Tptr>struct load_pointer_type {    template<class T>    struct abstract    {        static const basic_pointer_iserializer * register_type(Archive & /* ar */){            typedef BOOST_DEDUCED_TYPENAME                 boost::serialization::type_info_implementation<T>::type::is_polymorphic typex;            // it has? to be polymorphic            BOOST_STATIC_ASSERT(typex::value);            return static_cast<basic_pointer_iserializer *>(NULL);         }    };    template<class T>    struct non_abstract    {        static const basic_pointer_iserializer * register_type(Archive & ar){            return ar.register_type(static_cast<T *>(NULL));        }    };    template<class T>    static const basic_pointer_iserializer * register_type(Archive &ar, T & /*t*/){        #if defined(BOOST_MSVC)        // note: if you program traps here its because        // a) your serializing through a base class pointer        // b) to an archive not in the known list.          // This will usually occur when one makes a custom archive and         // forgets to add it to the list of known archive.  If the derived        // class is explictly registered or if no derived pointer is used        // there won't be a problem - that's why its a warning.  However        // if you export the derived type and the archive used isn't on the        // known list it will fail below at execution time and one will have        // a hell of time figuring out why.  Hence this warning.        BOOST_STATIC_WARNING((            mpl::not_<                mpl::and_<                    BOOST_DEDUCED_TYPENAME serialization::type_info_implementation<T>::type::is_polymorphic,                    mpl::not_<mpl::empty<known_archive_types<false>::type > >,                    is_same<                        mpl::end<known_archive_types<false>::type >::type,                        BOOST_DEDUCED_TYPENAME mpl::find<known_archive_types<false>::type, Archive>::type                    >                >            >            ::value        ));        #endif        // there should never be any need to load an abstract polymorphic         // class pointer.  Inhibiting code generation for this        // permits abstract base classes to be used - note: exception        // virtual serialize functions used for plug-ins        typedef BOOST_DEDUCED_TYPENAME            mpl::eval_if<                is_abstract<T>,                mpl::identity<abstract<T> >,                mpl::identity<non_abstract<T> >                >::type typex;        return typex::register_type(ar);    }    template<class T>    static T * pointer_tweak(        const boost::serialization::extended_type_info & eti,        void * t,        T &    ) {        // tweak the pointer back to the base class        return static_cast<T *>(            boost::serialization::void_upcast(                eti,                * boost::serialization::type_info_implementation<T>::type::get_instance(),                t            )        );    }    static void invoke(Archive & ar, Tptr & t){        const basic_pointer_iserializer * bpis_ptr = register_type(ar, *t);        const basic_pointer_iserializer * newbpis_ptr = ar.load_pointer(            * reinterpret_cast<void **>(&t),            bpis_ptr,            archive_pointer_iserializer<Archive>::find        );        // if the pointer isn't that of the base class        if(newbpis_ptr != bpis_ptr){            t = pointer_tweak(newbpis_ptr->type, t, *t);        }    }};template<class Archive, class T>struct load_enum_type {    static void invoke(Archive &ar, T &t){        // convert integers to correct enum to load        int i;        ar >> boost::serialization::make_nvp(NULL, i);        t = static_cast<T>(i);    }};template<class Archive, class T>struct load_array_type {    static void invoke(Archive &ar, T &t){        // convert integers to correct enum to load        int current_count = sizeof(t) / (            static_cast<char *>(static_cast<void *>(&t[1]))             - static_cast<char *>(static_cast<void *>(&t[0]))        );        int count;        ar >> BOOST_SERIALIZATION_NVP(count);        if(count > current_count)            boost::throw_exception(archive::archive_exception(                boost::archive::archive_exception::array_size_too_short            ));        int i;        for(i = 0; i < count; ++i)            ar >> boost::serialization::make_nvp("item", t[i]);    }};// note bogus arguments to workaround msvc 6 silent runtime failuretemplate<class Archive, class T>BOOST_DLLEXPORT inline const basic_pointer_iserializer &instantiate_pointer_iserializer(    Archive * /* ar = NULL */,    T * /* t = NULL */) BOOST_USED;template<class Archive, class T>BOOST_DLLEXPORT inline const basic_pointer_iserializer &instantiate_pointer_iserializer(    Archive * /* ar = NULL */,    T * /* t = NULL */){    // note: reversal of order of arguments to work around msvc 6.0 bug    // that manifests itself while trying to link.    return pointer_iserializer<T, Archive>::instance;}} // detailtemplate<class Archive, class T>inline void load(Archive &ar, T &t){    typedef        BOOST_DEDUCED_TYPENAME mpl::eval_if<is_pointer<T>,            mpl::identity<detail::load_pointer_type<Archive, T> >        ,//else        BOOST_DEDUCED_TYPENAME mpl::eval_if<is_array<T>,            mpl::identity<detail::load_array_type<Archive, T> >        ,//else        BOOST_DEDUCED_TYPENAME mpl::eval_if<is_enum<T>,            mpl::identity<detail::load_enum_type<Archive, T> >        ,//else            mpl::identity<detail::load_non_pointer_type<Archive, T> >        >        >        >::type typex;    typex::invoke(ar, t);}} // namespace archive} // namespace boost#endif // BOOST_ARCHIVE_DETAIL_ISERIALIZER_HPP

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?