iserializer.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 551 行 · 第 1/2 页
HPP
551 行
} BOOST_CATCH(...){ ap.release(); BOOST_RETHROW; } BOOST_CATCH_END ar_impl >> boost::serialization::make_nvp(NULL, * t); ap.release();}template<class Archive, class T>pointer_iserializer<Archive, T>::pointer_iserializer() : archive_pointer_iserializer<Archive>( boost::serialization::type_info_implementation<T>::type ::get_const_instance() ){ boost::serialization::singleton< iserializer<Archive, T> >::get_mutable_instance().set_bpis(this);}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_standard { static void invoke(Archive &ar, T &t){ //BOOST_STATIC_ASSERT(! boost::is_const<T>::value); // borland - for some reason T is const here - even though // its not called that way - so fix it her typedef BOOST_DEDUCED_TYPENAME boost::remove_const<T>::type typex; void * x = & const_cast<typex &>(t); ar.load_object( x, boost::serialization::singleton< iserializer<Archive, T> >::get_const_instance() ); } }; struct load_conditional { static void invoke(Archive &ar, T &t){ //if(0 == (ar.get_flags() & no_tracking)) load_standard::invoke(ar, t); //else // load_only::invoke(ar, t); } }; 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< // class info / version mpl::greater_equal< boost::serialization::implementation_level<T>, mpl::int_<boost::serialization::object_class_info> >, // do standard load mpl::identity<load_standard>, // else BOOST_DEDUCED_TYPENAME mpl::eval_if< // 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 a fast load only tracking is turned off mpl::identity<load_conditional> > > >::type typex; static void invoke(Archive & ar, 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 )); 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 */){ // it has? to be polymorphic BOOST_STATIC_ASSERT(boost::is_polymorphic<T>::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*/){ // 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< boost::serialization::is_abstract<const 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_const_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->get_eti(), 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){ typedef BOOST_DEDUCED_TYPENAME remove_extent<T>::type value_type; // 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::serialization::throw_exception(archive::archive_exception( boost::archive::archive_exception::array_size_too_short )); ar >> serialization::make_array(static_cast<value_type*>(&t[0]),count); }};} // detailtemplate<class Archive, class T>inline void load(Archive &ar, T &t){ // if this assertion trips. It means we're trying to load a // const object with a compiler that doesn't have correct // funtion template ordering. On other compilers, this is // handled below. BOOST_STATIC_ASSERT(! boost::is_const<T>::value); 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);}// BORLAND#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x560))// borland has a couple of problems// a) if function is partiall specialized - see below// const paramters are transformed to non-const ones// b) implementation of base_object can't be made to work// correctly which results in all base_object s being const.// So, strip off the const for borland. This breaks the trap// for loading const objects - but I see no alternativetemplate<class Archive, class T>inline void load(Archive &ar, const T & t){ load(ar, const_cast<T &>(t));}#endif// let wrappers through.#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERINGtemplate<class Archive, class T>inline void load_wrapper(Archive &ar, const T&t, mpl::true_){ boost::archive::load(ar, const_cast<T&>(t));}#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x560))template<class Archive, class T>inline void load(Archive &ar, const T&t){ load_wrapper(ar,t,serialization::is_wrapper<T>());}#endif #endif} // namespace archive} // namespace boost#endif // BOOST_ARCHIVE_DETAIL_ISERIALIZER_HPP
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?