Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /* Copyright 2006-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 http://www.boost.org/libs/flyweight for library home page.
0007  */
0008 
0009 #ifndef BOOST_FLYWEIGHT_SERIALIZE_HPP
0010 #define BOOST_FLYWEIGHT_SERIALIZE_HPP
0011 
0012 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
0013 #pragma once
0014 #endif
0015 
0016 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
0017 #include <boost/flyweight/flyweight_fwd.hpp>
0018 #include <boost/flyweight/detail/archive_constructed.hpp>
0019 #include <boost/flyweight/detail/serialization_helper.hpp>
0020 #include <boost/core/serialization.hpp>
0021 #include <boost/throw_exception.hpp>
0022 #include <memory>
0023 #include <stdexcept>
0024 
0025 /* Serialization routines for flyweight<T>. 
0026  */
0027 
0028 namespace boost{
0029 
0030 namespace flyweights{
0031 
0032 template<
0033   class Archive,
0034   typename T,typename Arg1,typename Arg2,typename Arg3
0035 >
0036 inline void serialize(
0037   Archive& ar,::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3>& f,
0038   const unsigned int version)
0039 {
0040   core::split_free(ar,f,version);
0041 }                                               
0042 
0043 template<
0044   class Archive,
0045   typename T,typename Arg1,typename Arg2,typename Arg3
0046 >
0047 void save(
0048   Archive& ar,const ::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3>& f,
0049   const unsigned int /*version*/)
0050 {
0051   typedef ::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3>    flyweight;
0052   typedef ::boost::flyweights::detail::save_helper<flyweight> helper;
0053   typedef typename helper::size_type                          size_type;
0054 
0055   helper& hlp=ar.template get_helper<helper>();
0056 
0057   size_type n=hlp.find(f);
0058   ar<<make_nvp("item",n);
0059   if(n==hlp.size()){
0060     ar<<make_nvp("key",f.get_key());
0061     hlp.push_back(f);
0062   }
0063 }
0064 
0065 template<
0066   class Archive,
0067   typename T,typename Arg1,typename Arg2,typename Arg3
0068 >
0069 void load(
0070   Archive& ar,::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3>& f,
0071   const unsigned int version)
0072 {
0073   typedef ::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3>    flyweight;
0074   typedef typename flyweight::key_type                        key_type;
0075   typedef ::boost::flyweights::detail::load_helper<flyweight> helper;
0076   typedef typename helper::size_type                          size_type;
0077 
0078   helper& hlp=ar.template get_helper<helper>();
0079 
0080   size_type n=0;
0081   ar>>make_nvp("item",n);
0082   if(n>hlp.size()){
0083     throw_exception(std::runtime_error("Invalid or corrupted archive"));
0084   }
0085   else if(n==hlp.size()){
0086     ::boost::flyweights::detail::archive_constructed<key_type> k(
0087       "key",ar,version);
0088     hlp.push_back(flyweight(k.get()));
0089   }
0090   f=hlp[n];
0091 }
0092 
0093 } /* namespace flyweights */
0094 
0095 } /* namespace boost */
0096 
0097 #endif