| 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_PTR_MAP_ADAPTER_HPP |
| 7 | #define BOOST_PTR_CONTAINER_DETAIL_SERIALIZE_PTR_MAP_ADAPTER_HPP |
| 8 | |
| 9 | #include <boost/ptr_container/ptr_map_adapter.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 serialization |
| 17 | { |
| 18 | |
| 19 | template<class Archive, class T, class VoidPtrMap, class CloneAllocator, bool Ordered> |
| 20 | void save(Archive& ar, const ptr_container_detail::ptr_map_adapter_base<T, VoidPtrMap, CloneAllocator,Ordered>& c, unsigned int /*version*/) |
| 21 | { |
| 22 | typedef ptr_container_detail::ptr_map_adapter_base<T, VoidPtrMap, CloneAllocator,Ordered> container; |
| 23 | typedef BOOST_DEDUCED_TYPENAME container::const_iterator const_iterator; |
| 24 | |
| 25 | ar << boost::serialization::make_nvp( ptr_container_detail::count(), |
| 26 | ptr_container_detail::serialize_as_const(c.size()) ); |
| 27 | |
| 28 | const_iterator i = c.begin(), e = c.end(); |
| 29 | for(; i != e; ++i) |
| 30 | { |
| 31 | ar << boost::serialization::make_nvp( ptr_container_detail::first(), i->first ); |
| 32 | ar << boost::serialization::make_nvp( ptr_container_detail::second(), |
| 33 | ptr_container_detail::serialize_as_const(i->second) ); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | template<class Archive, class T, class VoidPtrMap, class CloneAllocator, bool Ordered> |
| 38 | void load(Archive& ar, ptr_map_adapter<T, VoidPtrMap, CloneAllocator,Ordered>& c, unsigned int /*version*/) |
| 39 | { |
| 40 | typedef ptr_map_adapter<T, VoidPtrMap, CloneAllocator,Ordered> container; |
| 41 | typedef BOOST_DEDUCED_TYPENAME container::key_type key_type; |
| 42 | typedef BOOST_DEDUCED_TYPENAME container::size_type size_type; |
| 43 | typedef BOOST_DEDUCED_TYPENAME container::iterator iterator; |
| 44 | |
| 45 | c.clear(); |
| 46 | size_type n; |
| 47 | ar >> boost::serialization::make_nvp( ptr_container_detail::count(), n ); |
| 48 | |
| 49 | for(size_type i = 0u; i != n; ++i) |
| 50 | { |
| 51 | key_type key; |
| 52 | T* value; |
| 53 | ar >> boost::serialization::make_nvp( ptr_container_detail::first(), key ); |
| 54 | ar >> boost::serialization::make_nvp( ptr_container_detail::second(), value ); |
| 55 | std::pair<iterator, bool> p = c.insert(key, value); |
| 56 | ar.reset_object_address(&p.first->first, &key); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | template<class Archive, class T, class VoidPtrMap, class CloneAllocator, bool Ordered> |
| 61 | void load(Archive& ar, ptr_multimap_adapter<T, VoidPtrMap, CloneAllocator,Ordered>& c, unsigned int /*version*/) |
| 62 | { |
| 63 | typedef ptr_multimap_adapter<T, VoidPtrMap, CloneAllocator,Ordered> container; |
| 64 | typedef BOOST_DEDUCED_TYPENAME container::key_type key_type; |
| 65 | typedef BOOST_DEDUCED_TYPENAME container::size_type size_type; |
| 66 | typedef BOOST_DEDUCED_TYPENAME container::iterator iterator; |
| 67 | |
| 68 | c.clear(); |
| 69 | size_type n; |
| 70 | ar >> boost::serialization::make_nvp( ptr_container_detail::count(), n ); |
| 71 | |
| 72 | for(size_type i = 0u; i != n; ++i) |
| 73 | { |
| 74 | key_type key; |
| 75 | T* value; |
| 76 | ar >> boost::serialization::make_nvp( ptr_container_detail::first(), key ); |
| 77 | ar >> boost::serialization::make_nvp( ptr_container_detail::second(), value ); |
| 78 | iterator p = c.insert(key, value); |
| 79 | ar.reset_object_address(&p->first, &key); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | } // namespace serialization |
| 84 | } // namespace boost |
| 85 | |
| 86 | #endif |
| 87 | |