1 #ifndef BOOST_SERIALIZATION_ARRAY_WRAPPER_HPP
2 #define BOOST_SERIALIZATION_ARRAY_WRAPPER_HPP
4 // (C) Copyright 2005 Matthias Troyer and Dave Abrahams
5 // Use, modification and distribution is subject to the Boost Software
6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 #include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
11 #if defined(BOOST_NO_STDC_NAMESPACE)
17 #include <boost/serialization/nvp.hpp>
18 #include <boost/serialization/split_member.hpp>
19 #include <boost/serialization/wrapper.hpp>
20 #include <boost/serialization/collection_size_type.hpp>
21 #include <boost/serialization/array_optimization.hpp>
22 #include <boost/mpl/always.hpp>
23 #include <boost/mpl/apply.hpp>
24 #include <boost/mpl/bool_fwd.hpp>
25 #include <boost/type_traits/remove_const.hpp>
27 namespace boost { namespace serialization {
31 public wrapper_traits<const array_wrapper< T > >
34 array_wrapper & operator=(const array_wrapper & rhs);
35 // note: I would like to make the copy constructor private but this breaks
36 // make_array. So I make make_array a friend
37 template<class Tx, class S>
38 friend const boost::serialization::array_wrapper<Tx> make_array(Tx * t, S s);
41 array_wrapper(const array_wrapper & rhs) :
43 m_element_count(rhs.m_element_count)
46 array_wrapper(T * t, std::size_t s) :
51 // default implementation
52 template<class Archive>
53 void serialize_optimized(Archive &ar, const unsigned int, mpl::false_ ) const
55 // default implemention does the loop
56 std::size_t c = count();
59 ar & boost::serialization::make_nvp("item", *t++);
62 // optimized implementation
63 template<class Archive>
64 void serialize_optimized(Archive &ar, const unsigned int version, mpl::true_ )
66 boost::serialization::split_member(ar, *this, version);
69 // default implementation
70 template<class Archive>
71 void save(Archive &ar, const unsigned int version) const
73 ar.save_array(*this,version);
76 // default implementation
77 template<class Archive>
78 void load(Archive &ar, const unsigned int version)
80 ar.load_array(*this,version);
83 // default implementation
84 template<class Archive>
85 void serialize(Archive &ar, const unsigned int version)
88 boost::serialization::use_array_optimization<Archive>::template apply<
89 typename remove_const< T >::type
90 >::type use_optimized;
91 serialize_optimized(ar,version,use_optimized());
99 std::size_t count() const
101 return m_element_count;
106 const std::size_t m_element_count;
109 template<class T, class S>
111 const array_wrapper< T > make_array(T* t, S s){
112 const array_wrapper< T > a(t, s);
116 } } // end namespace boost::serialization
119 #endif //BOOST_SERIALIZATION_ARRAY_WRAPPER_HPP