]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/serialization/array_wrapper.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / serialization / array_wrapper.hpp
CommitLineData
b32b8144
FG
1#ifndef BOOST_SERIALIZATION_ARRAY_WRAPPER_HPP
2#define BOOST_SERIALIZATION_ARRAY_WRAPPER_HPP
7c673cae
FG
3
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)
8
7c673cae
FG
9#include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
10
11#if defined(BOOST_NO_STDC_NAMESPACE)
f67539c2
TL
12namespace std{
13 using ::size_t;
7c673cae
FG
14} // namespace std
15#endif
16
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>
b32b8144 21#include <boost/serialization/array_optimization.hpp>
7c673cae
FG
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>
7c673cae
FG
26
27namespace boost { namespace serialization {
28
7c673cae
FG
29template<class T>
30class array_wrapper :
31 public wrapper_traits<const array_wrapper< T > >
32{
33private:
34 array_wrapper & operator=(const array_wrapper & rhs);
7c673cae 35 // note: I would like to make the copy constructor private but this breaks
b32b8144
FG
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);
39public:
7c673cae
FG
40
41 array_wrapper(const array_wrapper & rhs) :
42 m_t(rhs.m_t),
43 m_element_count(rhs.m_element_count)
44 {}
45public:
46 array_wrapper(T * t, std::size_t s) :
47 m_t(t),
48 m_element_count(s)
49 {}
50
51 // default implementation
52 template<class Archive>
53 void serialize_optimized(Archive &ar, const unsigned int, mpl::false_ ) const
54 {
55 // default implemention does the loop
56 std::size_t c = count();
57 T * t = address();
58 while(0 < c--)
59 ar & boost::serialization::make_nvp("item", *t++);
60 }
61
62 // optimized implementation
63 template<class Archive>
64 void serialize_optimized(Archive &ar, const unsigned int version, mpl::true_ )
65 {
66 boost::serialization::split_member(ar, *this, version);
67 }
68
69 // default implementation
70 template<class Archive>
71 void save(Archive &ar, const unsigned int version) const
72 {
73 ar.save_array(*this,version);
74 }
75
76 // default implementation
77 template<class Archive>
78 void load(Archive &ar, const unsigned int version)
79 {
80 ar.load_array(*this,version);
81 }
f67539c2 82
7c673cae
FG
83 // default implementation
84 template<class Archive>
85 void serialize(Archive &ar, const unsigned int version)
86 {
f67539c2 87 typedef typename
7c673cae 88 boost::serialization::use_array_optimization<Archive>::template apply<
f67539c2 89 typename remove_const< T >::type
7c673cae
FG
90 >::type use_optimized;
91 serialize_optimized(ar,version,use_optimized());
92 }
f67539c2 93
7c673cae
FG
94 T * address() const
95 {
96 return m_t;
97 }
98
99 std::size_t count() const
100 {
101 return m_element_count;
102 }
103
104private:
105 T * const m_t;
106 const std::size_t m_element_count;
107};
108
109template<class T, class S>
110inline
b32b8144 111const array_wrapper< T > make_array(T* t, S s){
7c673cae
FG
112 const array_wrapper< T > a(t, s);
113 return a;
114}
115
116} } // end namespace boost::serialization
117
7c673cae 118
b32b8144 119#endif //BOOST_SERIALIZATION_ARRAY_WRAPPER_HPP