| 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/core/serialization.hpp> |
| 12 | |
| 13 | namespace boost |
| 14 | { |
| 15 | |
| 16 | namespace ptr_container_detail |
| 17 | { |
| 18 | |
| 19 | template<class Archive, class Config, class CloneAllocator> |
| 20 | void save_helper(Archive& ar, const ptr_container_detail::reversible_ptr_container<Config, CloneAllocator>& c) |
| 21 | { |
| 22 | typedef ptr_container_detail::reversible_ptr_container<Config, CloneAllocator> container_type; |
| 23 | typedef BOOST_DEDUCED_TYPENAME container_type::const_iterator const_iterator; |
| 24 | typedef BOOST_DEDUCED_TYPENAME container_type::value_type value_type; |
| 25 | |
| 26 | const_iterator i = c.begin(), e = c.end(); |
| 27 | for(; i != e; ++i) |
| 28 | ar << boost::serialization::make_nvp( ptr_container_detail::item(), |
| 29 | ptr_container_detail::serialize_as_const(static_cast<value_type>(*i.base()))); |
| 30 | } |
| 31 | |
| 32 | template<class Archive, class Config, class CloneAllocator> |
| 33 | void load_helper(Archive& ar, ptr_container_detail::reversible_ptr_container<Config, CloneAllocator>& c, |
| 34 | BOOST_DEDUCED_TYPENAME ptr_container_detail::reversible_ptr_container<Config, CloneAllocator>::size_type n) |
| 35 | { |
| 36 | typedef ptr_container_detail::reversible_ptr_container<Config, CloneAllocator> container_type; |
| 37 | typedef BOOST_DEDUCED_TYPENAME container_type::size_type size_type; |
| 38 | typedef BOOST_DEDUCED_TYPENAME container_type::value_type value_type; |
| 39 | |
| 40 | // |
| 41 | // Called after an appropriate reserve on c. |
| 42 | // |
| 43 | |
| 44 | c.clear(); |
| 45 | for(size_type i = 0u; i != n; ++i) |
| 46 | { |
| 47 | // |
| 48 | // Remark: pointers are not tracked, |
| 49 | // so we need not call ar.reset_object_address(v, u) |
| 50 | // |
| 51 | value_type ptr; |
| 52 | ar >> boost::serialization::make_nvp( ptr_container_detail::item(), ptr ); |
| 53 | c.insert(c.end(), ptr); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | } // namespace ptr_container_detail |
| 58 | |
| 59 | namespace serialization |
| 60 | { |
| 61 | |
| 62 | template<class Archive, class Config, class CloneAllocator> |
| 63 | void save(Archive& ar, const ptr_container_detail::reversible_ptr_container<Config, CloneAllocator>& c, unsigned int /*version*/) |
| 64 | { |
| 65 | ar << boost::serialization::make_nvp( ptr_container_detail::count(), |
| 66 | ptr_container_detail::serialize_as_const(c.size()) ); |
| 67 | ptr_container_detail::save_helper(ar, c); |
| 68 | } |
| 69 | |
| 70 | template<class Archive, class Config, class CloneAllocator> |
| 71 | void load(Archive& ar, ptr_container_detail::reversible_ptr_container<Config, CloneAllocator>& c, unsigned int /*version*/) |
| 72 | { |
| 73 | typedef ptr_container_detail::reversible_ptr_container<Config, CloneAllocator> container_type; |
| 74 | typedef BOOST_DEDUCED_TYPENAME container_type::size_type size_type; |
| 75 | |
| 76 | size_type n; |
| 77 | ar >> boost::serialization::make_nvp( ptr_container_detail::count(), n ); |
| 78 | ptr_container_detail::load_helper(ar, c, n); |
| 79 | |
| 80 | } |
| 81 | |
| 82 | } // namespace serialization |
| 83 | } // namespace boost |
| 84 | |
| 85 | #endif |
| 86 | |