⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oserializer.hpp

📁 CGAL is a collaborative effort of several sites in Europe and Israel. The goal is to make the most i
💻 HPP
📖 第 1 页 / 共 2 页
字号:
#ifndef BOOST_ARCHIVE_OSERIALIZER_HPP#define BOOST_ARCHIVE_OSERIALIZER_HPP// MS compatible compilers support #pragma once#if defined(_MSC_VER) && (_MSC_VER >= 1020)# pragma once#pragma inline_depth(255)#pragma inline_recursion(on)#endif#if defined(__MWERKS__)#pragma inline_depth(255)#endif/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8// oserializer.hpp: interface for serialization system.// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . // Use, modification and distribution is subject to the Boost Software// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at// http://www.boost.org/LICENSE_1_0.txt)//  See http://www.boost.org for updates, documentation, and revision history.#include <cassert>#include <boost/config.hpp>#include <boost/detail/workaround.hpp>#include <boost/throw_exception.hpp>#include <boost/smart_cast.hpp>#include <boost/static_assert.hpp>#include <boost/static_warning.hpp>#include <boost/type_traits/is_pointer.hpp>#include <boost/type_traits/is_fundamental.hpp>#include <boost/type_traits/is_enum.hpp>#include <boost/type_traits/is_volatile.hpp>#include <boost/type_traits/is_const.hpp>#include <boost/type_traits/remove_const.hpp>#include <boost/type_traits/is_same.hpp>#include <boost/serialization/is_abstract.hpp>#include <boost/mpl/eval_if.hpp>#include <boost/mpl/and.hpp>#include <boost/mpl/less.hpp>#include <boost/mpl/greater_equal.hpp>#include <boost/mpl/equal_to.hpp>#include <boost/mpl/int.hpp>#include <boost/mpl/identity.hpp>#include <boost/mpl/list.hpp>#include <boost/mpl/empty.hpp>#include <boost/mpl/not.hpp>// the following is only used with VC for now and it crashes// at least one other compiler (Borland)#if defined(BOOST_MSVC)#include <boost/mpl/find.hpp>#endif// the following is need only for dynamic cast of polymorphic pointers#include <boost/archive/detail/basic_oarchive.hpp>#include <boost/archive/detail/basic_oserializer.hpp>#include <boost/archive/detail/archive_pointer_oserializer.hpp>#include <boost/serialization/force_include.hpp>#include <boost/serialization/extended_type_info.hpp>#include <boost/serialization/serialization.hpp>#include <boost/serialization/version.hpp>#include <boost/serialization/level.hpp>#include <boost/serialization/tracking.hpp>#include <boost/serialization/type_info_implementation.hpp>#include <boost/serialization/nvp.hpp>#include <boost/serialization/void_cast.hpp>#include <boost/serialization/force_include.hpp>#include <boost/archive/archive_exception.hpp>#include <boost/archive/detail/known_archive_types_fwd.hpp>namespace boost {namespace serialization {//    template<class Archive, class T>//    void serialize(Archive &ar, T & t, const unsigned int file_version);}namespace archive {// an accessor to permit friend access to archives.  Needed because// some compilers don't handle friend templates completelyclass save_access {public:    template<class Archive>    static void end_preamble(Archive & ar){        ar.end_preamble();    }    template<class Archive, class T>    static void save_primitive(Archive & ar, const  T & t){        ar.end_preamble();        ar.save(t);    }};namespace detail {template<class Archive, class T>class oserializer : public basic_oserializer{public:    explicit oserializer() :        basic_oserializer(            * boost::serialization::type_info_implementation<T>::type::get_instance()        )    {}    virtual BOOST_DLLEXPORT void save_object_data(        basic_oarchive & ar,            const void *x    ) const BOOST_USED ;    virtual bool class_info() const {        return boost::serialization::implementation_level<T>::value             >= boost::serialization::object_class_info;    }    virtual bool tracking() const {        return boost::serialization::tracking_level<T>::value == boost::serialization::track_always            || boost::serialization::tracking_level<T>::value == boost::serialization::track_selectivly            && serialized_as_pointer();    }    virtual unsigned int version() const {        return ::boost::serialization::version<T>::value;    }    virtual bool is_polymorphic() const {        typedef BOOST_DEDUCED_TYPENAME boost::serialization::type_info_implementation<            T        >::type::is_polymorphic::type typex;        return typex::value;    }    static oserializer & instantiate(){        static oserializer instance;        return instance;    }    virtual ~oserializer(){}};template<class Archive, class T>inline BOOST_DLLEXPORT void oserializer<Archive, T>::save_object_data(    basic_oarchive & ar,        const void *x) const {    // make sure call is routed through the highest interface that might    // be specialized by the user.    boost::serialization::serialize_adl<Archive, T>(        boost::smart_cast_reference<Archive &>(ar),        * static_cast<T *>(const_cast<void *>(x)),        version()    );}// instantiation of this template creates a static object.  Note inversion of// normal argument order to workaround bizarre error in MSVC 6.0 which only// manifests iftself during compiler time.template<class T, class Archive>class pointer_oserializer : public archive_pointer_oserializer<Archive> {private:    virtual const basic_oserializer & get_basic_serializer() const {        return oserializer<Archive, T>::instantiate();    }    virtual BOOST_DLLEXPORT void save_object_ptr(        basic_oarchive & ar,        const void * x    ) const BOOST_USED ;public:    static const pointer_oserializer instance;    explicit pointer_oserializer() :        archive_pointer_oserializer<Archive>(            * boost::serialization::type_info_implementation<T>::type::get_instance()        )    {        // make sure appropriate member function is instantiated        basic_oserializer & bos = oserializer<Archive, T>::instantiate();        bos.set_bpos(this);    }    //static const pointer_oserializer BOOST_FORCE_INCLUDE_DECL(& instantiate());    static BOOST_DLLEXPORT const pointer_oserializer & instantiate() BOOST_USED;    virtual ~pointer_oserializer(){}};// note: instances of this template to be constructed before the main// is called in order for things to be initialized properly.  For this// reason, hiding the instance in a static function as was done above// won't work here so we created a free instance here.template<class T, class Archive>const pointer_oserializer<T, Archive> pointer_oserializer<T, Archive>::instance;template<class T, class Archive>BOOST_DLLEXPORT void pointer_oserializer<T, Archive>::save_object_ptr(    basic_oarchive & ar,    const void * x) const {    assert(NULL != x);    // make sure call is routed through the highest interface that might    // be specialized by the user.    T * t = static_cast<T *>(const_cast<void *>(x));    const unsigned int file_version = boost::serialization::version<T>::value;    Archive & ar_impl = boost::smart_cast_reference<Archive &>(ar);    boost::serialization::save_construct_data_adl<Archive, T>(        ar_impl,         t,         file_version    );    ar_impl << boost::serialization::make_nvp(NULL, * t);}template<class Archive, class T>struct save_non_pointer_type {    // note this bounces the call right back to the archive    // with no runtime overhead    struct save_primitive {        static void invokex(Archive & ar, const T & t){            save_access::save_primitive(ar, t);        }    };    // same as above but passes through serialization    struct save_only {        static void invokex(Archive & ar, const T & t){            // make sure call is routed through the highest interface that might            // be specialized by the user.            boost::serialization::serialize_adl(                ar, const_cast<T &>(t), ::boost::serialization::version<T>::value            );        }    };    // adds class information to the archive. This includes    // serialization level and class version    struct save {        static void invokex(Archive &ar, const T & t){            ar.save_object(& t, oserializer<Archive, T>::instantiate());        }    };    static void invoke(Archive & ar, const T & t){        // check that we're not trying to serialize something that        // has been marked not to be serialized.  If this your program        // traps here, you've tried to serialize a class whose trait        // has been marked "non-serializable". Either reset the trait        // (see level.hpp) or change program not to serialize items of this class        BOOST_STATIC_ASSERT((            mpl::greater_equal<                boost::serialization::implementation_level<T>,                 mpl::int_<boost::serialization::primitive_type>            >::value        ));        #if defined(__BORLANDC__)            return mpl::eval_if<                    // if its primitive                    mpl::equal_to<                        boost::serialization::implementation_level<T>,                        mpl::int_<boost::serialization::primitive_type>                    >,                    mpl::identity<save_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 save                    mpl::identity<save_only>,                // else                    // do standard save                    mpl::identity<save>                >            >::type::invokex(ar, t);        #else            typedef 

⌨️ 快捷键说明

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