1 #ifndef BOOST_SERIALIZATION_ARRAY_HPP
2 #define BOOST_SERIALIZATION_ARRAY_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/serialization/nvp.hpp>
10 #include <boost/serialization/split_member.hpp>
11 #include <boost/serialization/wrapper.hpp>
12 #include <boost/mpl/always.hpp>
13 #include <boost/mpl/apply.hpp>
14 #include <boost/mpl/bool.hpp>
15 #include <boost/type_traits/remove_const.hpp>
16 #include <boost/array.hpp>
19 #include <cstddef> // std::size_t
21 #include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
22 #if defined(BOOST_NO_STDC_NAMESPACE)
28 namespace boost
{ namespace serialization
{
30 // traits to specify whether to use an optimized array serialization
33 // workaround for Borland compiler
34 template <class Archive
>
35 struct use_array_optimization
{
36 template <class T
> struct apply
: boost::mpl::false_
{};
40 template <class Archive
>
41 struct use_array_optimization
: boost::mpl::always
<boost::mpl::false_
> {};
46 : public wrapper_traits
<array
<T
> >
51 array(value_type
* t
, std::size_t s
) :
56 // default implementation
57 template<class Archive
>
58 void serialize_optimized(Archive
&ar
, const unsigned int, mpl::false_
) const
60 // default implemention does the loop
61 std::size_t c
= count();
62 value_type
* t
= address();
64 ar
& boost::serialization::make_nvp("item", *t
++);
67 // optimized implementation
68 template<class Archive
>
69 void serialize_optimized(Archive
&ar
, const unsigned int version
, mpl::true_
)
71 boost::serialization::split_member(ar
, *this, version
);
74 // default implementation
75 template<class Archive
>
76 void save(Archive
&ar
, const unsigned int version
) const
78 ar
.save_array(*this,version
);
81 // default implementation
82 template<class Archive
>
83 void load(Archive
&ar
, const unsigned int version
)
85 ar
.load_array(*this,version
);
88 // default implementation
89 template<class Archive
>
90 void serialize(Archive
&ar
, const unsigned int version
)
92 typedef BOOST_DEDUCED_TYPENAME
93 boost::serialization::use_array_optimization
<Archive
>::template apply
<
94 BOOST_DEDUCED_TYPENAME remove_const
<T
>::type
95 >::type use_optimized
;
96 serialize_optimized(ar
,version
,use_optimized());
99 value_type
* address() const
104 std::size_t count() const
106 return m_element_count
;
111 std::size_t const m_element_count
;
116 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
119 array
<T
> make_array( T
* t
, std::size_t s
){
120 return array
<T
>(t
, s
);
123 template <class Archive
, class T
, std::size_t N
>
124 void serialize(Archive
& ar
, boost::array
<T
,N
>& a
, const unsigned int /* version */)
126 ar
& boost::serialization::make_nvp("elems",a
.elems
);
131 } } // end namespace boost::serialization
134 // ignore optimizations for Borland
135 #define BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(Archive)
137 #define BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(Archive) \
138 namespace boost { namespace serialization { \
139 template <> struct use_array_optimization<Archive> { \
140 template <class ValueType> \
141 struct apply : boost::mpl::apply1<Archive::use_array_optimization \
142 , BOOST_DEDUCED_TYPENAME boost::remove_const<ValueType>::type \
145 #endif // __BORLANDC__
147 #endif //BOOST_SERIALIZATION_ARRAY_HPP