Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:08:13

0001 #ifndef BOOST_SERIALIZATION_ARRAY_WRAPPER_HPP
0002 #define BOOST_SERIALIZATION_ARRAY_WRAPPER_HPP
0003 
0004 // (C) Copyright 2005 Matthias Troyer and Dave Abrahams
0005 // Use, modification and distribution is subject to the Boost Software
0006 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
0010 
0011 #if defined(BOOST_NO_STDC_NAMESPACE)
0012 namespace std{
0013     using ::size_t;
0014 } // namespace std
0015 #endif
0016 
0017 #include <boost/serialization/nvp.hpp>
0018 #include <boost/serialization/split_member.hpp>
0019 #include <boost/serialization/wrapper.hpp>
0020 #include <boost/serialization/collection_size_type.hpp>
0021 #include <boost/serialization/array_optimization.hpp>
0022 #include <boost/mpl/always.hpp>
0023 #include <boost/mpl/apply.hpp>
0024 #include <boost/mpl/bool_fwd.hpp>
0025 #include <boost/type_traits/remove_const.hpp>
0026 
0027 namespace boost { namespace serialization {
0028 
0029 template<class T>
0030 class array_wrapper :
0031     public wrapper_traits<const array_wrapper< T > >
0032 {
0033 private:
0034     array_wrapper & operator=(const array_wrapper & rhs);
0035     // note: I would like to make the copy constructor private but this breaks
0036     // make_array.  So I make make_array a friend
0037     template<class Tx, class S>
0038     friend const boost::serialization::array_wrapper<Tx> make_array(Tx * t, S s);
0039 public:
0040 
0041     array_wrapper(const array_wrapper & rhs) :
0042         m_t(rhs.m_t),
0043         m_element_count(rhs.m_element_count)
0044     {}
0045 public:
0046     array_wrapper(T * t, std::size_t s) :
0047         m_t(t),
0048         m_element_count(s)
0049     {}
0050 
0051     // default implementation
0052     template<class Archive>
0053     void serialize_optimized(Archive &ar, const unsigned int, mpl::false_ ) const
0054     {
0055       // default implementation does the loop
0056       std::size_t c = count();
0057       T * t = address();
0058       while(0 < c--)
0059             ar & boost::serialization::make_nvp("item", *t++);
0060     }
0061 
0062     // optimized implementation
0063     template<class Archive>
0064     void serialize_optimized(Archive &ar, const unsigned int version, mpl::true_ )
0065     {
0066       boost::serialization::split_member(ar, *this, version);
0067     }
0068 
0069     // default implementation
0070     template<class Archive>
0071     void save(Archive &ar, const unsigned int version) const
0072     {
0073       ar.save_array(*this,version);
0074     }
0075 
0076     // default implementation
0077     template<class Archive>
0078     void load(Archive &ar, const unsigned int version)
0079     {
0080       ar.load_array(*this,version);
0081     }
0082 
0083     // default implementation
0084     template<class Archive>
0085     void serialize(Archive &ar, const unsigned int version)
0086     {
0087       typedef typename
0088           boost::serialization::use_array_optimization<Archive>::template apply<
0089                     typename remove_const< T >::type
0090                 >::type use_optimized;
0091       serialize_optimized(ar,version,use_optimized());
0092     }
0093 
0094     T * address() const
0095     {
0096       return m_t;
0097     }
0098 
0099     std::size_t count() const
0100     {
0101       return m_element_count;
0102     }
0103 
0104 private:
0105     T * const m_t;
0106     const std::size_t m_element_count;
0107 };
0108 
0109 template<class T, class S>
0110 inline
0111 const array_wrapper< T > make_array(T* t, S s){
0112     const array_wrapper< T > a(t, s);
0113     return a;
0114 }
0115 
0116 } } // end namespace boost::serialization
0117 
0118 
0119 #endif //BOOST_SERIALIZATION_ARRAY_WRAPPER_HPP