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)
11 #include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
13 #if defined(BOOST_NO_STDC_NAMESPACE)
19 #include <boost/serialization/nvp.hpp>
20 #include <boost/serialization/split_member.hpp>
21 #include <boost/serialization/wrapper.hpp>
22 #include <boost/serialization/collection_size_type.hpp>
23 #include <boost/serialization/array_optimization.hpp>
24 #include <boost/mpl/always.hpp>
25 #include <boost/mpl/apply.hpp>
26 #include <boost/mpl/bool_fwd.hpp>
27 #include <boost/type_traits/remove_const.hpp>
29 namespace boost { namespace serialization {
33 public wrapper_traits<const array_wrapper< T > >
36 array_wrapper & operator=(const array_wrapper & rhs);
37 // note: I would like to make the copy constructor private but this breaks
38 // make_array. So I make make_array a friend
39 template<class Tx, class S>
40 friend const boost::serialization::array_wrapper<Tx> make_array(Tx * t, S s);
43 array_wrapper(const array_wrapper & rhs) :
45 m_element_count(rhs.m_element_count)
48 array_wrapper(T * t, std::size_t s) :
53 // default implementation
54 template<class Archive>
55 void serialize_optimized(Archive &ar, const unsigned int, mpl::false_ ) const
57 // default implemention does the loop
58 std::size_t c = count();
61 ar & boost::serialization::make_nvp("item", *t++);
64 // optimized implementation
65 template<class Archive>
66 void serialize_optimized(Archive &ar, const unsigned int version, mpl::true_ )
68 boost::serialization::split_member(ar, *this, version);
71 // default implementation
72 template<class Archive>
73 void save(Archive &ar, const unsigned int version) const
75 ar.save_array(*this,version);
78 // default implementation
79 template<class Archive>
80 void load(Archive &ar, const unsigned int version)
82 ar.load_array(*this,version);
85 // default implementation
86 template<class Archive>
87 void serialize(Archive &ar, const unsigned int version)
90 boost::serialization::use_array_optimization<Archive>::template apply<
91 typename remove_const< T >::type
92 >::type use_optimized;
93 serialize_optimized(ar,version,use_optimized());
101 std::size_t count() const
103 return m_element_count;
108 const std::size_t m_element_count;
111 template<class T, class S>
113 const array_wrapper< T > make_array(T* t, S s){
114 const array_wrapper< T > a(t, s);
118 } } // end namespace boost::serialization
121 #endif //BOOST_SERIALIZATION_ARRAY_WRAPPER_HPP