Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:22

0001 /* Copyright 2023 Joaquin M Lopez Munoz.
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * See https://www.boost.org/libs/unordered for library home page.
0007  */
0008 
0009 #ifndef BOOST_UNORDERED_DETAIL_SERIALIZE_FCA_CONTAINER_HPP
0010 #define BOOST_UNORDERED_DETAIL_SERIALIZE_FCA_CONTAINER_HPP
0011 
0012 #include <boost/unordered/detail/serialize_container.hpp>
0013 
0014 #if defined(BOOST_UNORDERED_ENABLE_SERIALIZATION_COMPATIBILITY_V0)
0015 
0016 #define BOOST_UNORDERED_BLOCK_BOOSTDEP_HEADER \
0017   <boost/serialization/archive_input_unordered_map.hpp>
0018 #include BOOST_UNORDERED_BLOCK_BOOSTDEP_HEADER
0019 #undef BOOST_UNORDERED_BLOCK_BOOSTDEP_HEADER
0020 #define BOOST_UNORDERED_BLOCK_BOOSTDEP_HEADER \
0021   <boost/serialization/archive_input_unordered_set.hpp>
0022 #include BOOST_UNORDERED_BLOCK_BOOSTDEP_HEADER
0023 #undef BOOST_UNORDERED_BLOCK_BOOSTDEP_HEADER
0024 #define BOOST_UNORDERED_BLOCK_BOOSTDEP_HEADER \
0025   <boost/serialization/unordered_collections_load_imp.hpp>
0026 #include BOOST_UNORDERED_BLOCK_BOOSTDEP_HEADER
0027 #undef BOOST_UNORDERED_BLOCK_BOOSTDEP_HEADER
0028 #define BOOST_UNORDERED_BLOCK_BOOSTDEP_HEADER \
0029   <boost/serialization/utility.hpp>
0030 #include BOOST_UNORDERED_BLOCK_BOOSTDEP_HEADER
0031 #undef BOOST_UNORDERED_BLOCK_BOOSTDEP_HEADER
0032 
0033 #include <boost/unordered/unordered_map_fwd.hpp>
0034 #include <boost/unordered/unordered_set_fwd.hpp>
0035 
0036 #else
0037 
0038 #include <boost/throw_exception.hpp>
0039 #include <stdexcept>
0040 
0041 #endif
0042 
0043 namespace boost{
0044 namespace unordered{
0045 namespace detail{
0046 
0047 /* Support for boost::unordered_[multi](map|set) loading from legacy archives.
0048  * Until Boost 1.84, serialization of these containers was provided from
0049  * Boost.Serialization via boost/serialization/boost_unordered_(map|set).hpp,
0050  * from that release on support is native in Boost.Unordered. To enable legacy
0051  * archive loading, BOOST_UNORDERED_ENABLE_SERIALIZATION_COMPATIBILITY_V0
0052  * must be defined (it implies header dependency from Boost.Serialization).
0053  */
0054 
0055 #if defined(BOOST_UNORDERED_ENABLE_SERIALIZATION_COMPATIBILITY_V0)
0056 
0057 template<typename Archive,typename Container>
0058 struct archive_input;
0059 
0060 template<
0061   typename Archive,typename K,typename T,typename H,typename P,typename A
0062 >
0063 struct archive_input<Archive,boost::unordered_map<K,T,H,P,A> >:
0064   boost::serialization::stl::archive_input_unordered_map<
0065     Archive,
0066     boost::unordered_map<K,T,H,P,A>
0067   >
0068 {};
0069 
0070 template<
0071   typename Archive,typename K,typename T,typename H,typename P,typename A
0072 >
0073 struct archive_input<Archive,boost::unordered_multimap<K,T,H,P,A> >:
0074   boost::serialization::stl::archive_input_unordered_multimap<
0075     Archive,
0076     boost::unordered_multimap<K,T,H,P,A>
0077   >
0078 {};
0079 
0080 template<
0081   typename Archive,typename K,typename H,typename P,typename A
0082 >
0083 struct archive_input<Archive,boost::unordered_set<K,H,P,A> >:
0084   boost::serialization::stl::archive_input_unordered_set<
0085     Archive,
0086     boost::unordered_set<K,H,P,A>
0087   >
0088 {};
0089 
0090 template<
0091   typename Archive,typename K,typename H,typename P,typename A
0092 >
0093 struct archive_input<Archive,boost::unordered_multiset<K,H,P,A> >:
0094   boost::serialization::stl::archive_input_unordered_multiset<
0095     Archive,
0096     boost::unordered_multiset<K,H,P,A>
0097   >
0098 {};
0099 
0100 #else
0101 
0102 struct legacy_archive_exception:std::runtime_error
0103 {
0104   legacy_archive_exception():std::runtime_error(
0105     "Legacy archive detected, define "
0106     "BOOST_UNORDERED_ENABLE_SERIALIZATION_COMPATIBILITY_V0 to load"){}
0107 };
0108 
0109 #endif
0110 
0111 template<typename Container,bool IsSaving>
0112 struct load_or_save_fca_container;
0113 
0114 template<typename Container>
0115 struct load_or_save_fca_container<Container,true> /* save */
0116 {
0117   template<typename Archive>
0118   void operator()(Archive& ar,Container& x,unsigned int version)const
0119   {
0120     serialize_container(ar,x,version);
0121   }
0122 };
0123 
0124 template<typename Container>
0125 struct load_or_save_fca_container<Container,false> /* load */
0126 {
0127   template<typename Archive>
0128   void operator()(Archive& ar,Container& x,unsigned int version)const
0129   {
0130     if(version==0){
0131 #if defined(BOOST_UNORDERED_ENABLE_SERIALIZATION_COMPATIBILITY_V0)
0132       boost::serialization::stl::load_unordered_collection<
0133         Archive,Container,archive_input<Archive,Container>
0134       >(ar,x);
0135 #else
0136       throw_exception(legacy_archive_exception());
0137 #endif
0138     }
0139     else{
0140       serialize_container(ar,x,version);
0141     }
0142   }
0143 };
0144 
0145 template<typename Archive,typename Container>
0146 void serialize_fca_container(Archive& ar,Container& x,unsigned int version)
0147 {
0148   load_or_save_fca_container<Container,Archive::is_saving::value>()(
0149     ar,x,version);
0150 }
0151 
0152 } /* namespace detail */
0153 } /* namespace unordered */
0154 } /* namespace boost */
0155 
0156 #endif