]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright Sebastian Ramacher, 2007. |
2 | // Distributed under the Boost Software License, Version 1.0. (See | |
3 | // accompanying file LICENSE_1_0.txt or copy at | |
4 | // http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | #ifndef BOOST_PTR_CONTAINER_DETAIL_SERIALIZE_REVERSIBLE_PTR_CONTAINER_HPP | |
7 | #define BOOST_PTR_CONTAINER_DETAIL_SERIALIZE_REVERSIBLE_PTR_CONTAINER_HPP | |
8 | ||
9 | #include <boost/ptr_container/detail/reversible_ptr_container.hpp> | |
10 | #include <boost/ptr_container/detail/serialize_xml_names.hpp> | |
11 | #include <boost/serialization/split_free.hpp> | |
12 | #include <boost/serialization/nvp.hpp> | |
13 | ||
14 | namespace boost | |
15 | { | |
16 | ||
17 | namespace ptr_container_detail | |
18 | { | |
19 | ||
20 | template<class Archive, class Config, class CloneAllocator> | |
21 | void save_helper(Archive& ar, const ptr_container_detail::reversible_ptr_container<Config, CloneAllocator>& c) | |
22 | { | |
23 | typedef ptr_container_detail::reversible_ptr_container<Config, CloneAllocator> container_type; | |
24 | typedef BOOST_DEDUCED_TYPENAME container_type::const_iterator const_iterator; | |
25 | typedef BOOST_DEDUCED_TYPENAME container_type::value_type value_type; | |
26 | ||
27 | const_iterator i = c.begin(), e = c.end(); | |
28 | for(; i != e; ++i) | |
29 | ar << boost::serialization::make_nvp( ptr_container_detail::item(), | |
30 | ptr_container_detail::serialize_as_const(static_cast<value_type>(*i.base()))); | |
31 | } | |
32 | ||
33 | template<class Archive, class Config, class CloneAllocator> | |
34 | void load_helper(Archive& ar, ptr_container_detail::reversible_ptr_container<Config, CloneAllocator>& c, | |
35 | BOOST_DEDUCED_TYPENAME ptr_container_detail::reversible_ptr_container<Config, CloneAllocator>::size_type n) | |
36 | { | |
37 | typedef ptr_container_detail::reversible_ptr_container<Config, CloneAllocator> container_type; | |
38 | typedef BOOST_DEDUCED_TYPENAME container_type::size_type size_type; | |
39 | typedef BOOST_DEDUCED_TYPENAME container_type::value_type value_type; | |
40 | ||
41 | // | |
42 | // Called after an appropriate reserve on c. | |
43 | // | |
44 | ||
45 | c.clear(); | |
46 | for(size_type i = 0u; i != n; ++i) | |
47 | { | |
48 | // | |
49 | // Remark: pointers are not tracked, | |
50 | // so we need not call ar.reset_object_address(v, u) | |
51 | // | |
52 | value_type ptr; | |
53 | ar >> boost::serialization::make_nvp( ptr_container_detail::item(), ptr ); | |
54 | c.insert(c.end(), ptr); | |
55 | } | |
56 | } | |
57 | ||
58 | } // namespace ptr_container_detail | |
59 | ||
60 | namespace serialization | |
61 | { | |
62 | ||
63 | template<class Archive, class Config, class CloneAllocator> | |
64 | void save(Archive& ar, const ptr_container_detail::reversible_ptr_container<Config, CloneAllocator>& c, unsigned int /*version*/) | |
65 | { | |
66 | ar << boost::serialization::make_nvp( ptr_container_detail::count(), | |
67 | ptr_container_detail::serialize_as_const(c.size()) ); | |
68 | ptr_container_detail::save_helper(ar, c); | |
69 | } | |
70 | ||
71 | template<class Archive, class Config, class CloneAllocator> | |
72 | void load(Archive& ar, ptr_container_detail::reversible_ptr_container<Config, CloneAllocator>& c, unsigned int /*version*/) | |
73 | { | |
74 | typedef ptr_container_detail::reversible_ptr_container<Config, CloneAllocator> container_type; | |
75 | typedef BOOST_DEDUCED_TYPENAME container_type::size_type size_type; | |
76 | ||
77 | size_type n; | |
78 | ar >> boost::serialization::make_nvp( ptr_container_detail::count(), n ); | |
79 | ptr_container_detail::load_helper(ar, c, n); | |
80 | ||
81 | } | |
82 | ||
83 | } // namespace serialization | |
84 | } // namespace boost | |
85 | ||
86 | #endif |