1 #ifndef BOOST_SERIALIZATION_MAP_HPP
2 #define BOOST_SERIALIZATION_MAP_HPP
4 // MS compatible compilers support #pragma once
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // serialization/map.hpp:
11 // serialization for stl map templates
13 // (C) Copyright 2002-2014 Robert Ramey - http://www.rrsd.com .
14 // Use, modification and distribution is subject to the Boost Software
15 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
16 // http://www.boost.org/LICENSE_1_0.txt)
18 // See http://www.boost.org for updates, documentation, and revision history.
22 #include <boost/config.hpp>
24 #include <boost/archive/detail/basic_iarchive.hpp>
25 #include <boost/serialization/access.hpp>
26 #include <boost/serialization/nvp.hpp>
27 #include <boost/serialization/collection_size_type.hpp>
28 #include <boost/serialization/item_version_type.hpp>
29 #include <boost/serialization/detail/stack_constructor.hpp>
31 #include <boost/serialization/utility.hpp>
32 #include <boost/serialization/collections_save_imp.hpp>
33 #include <boost/serialization/split_free.hpp>
36 namespace serialization {
38 ////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
39 // implementation of serialization for map and mult-map STL containers
41 template<class Archive, class Container>
42 inline void load_map_collection(Archive & ar, Container &s)
45 const boost::archive::library_version_type library_version(
46 ar.get_library_version()
48 // retrieve number of elements
49 item_version_type item_version(0);
50 collection_size_type count;
51 ar >> BOOST_SERIALIZATION_NVP(count);
52 if(boost::archive::library_version_type(3) < library_version){
53 ar >> BOOST_SERIALIZATION_NVP(item_version);
55 typename Container::iterator hint;
58 typedef typename Container::value_type type;
59 detail::stack_construct<Archive, type> t(ar, item_version);
60 ar >> boost::serialization::make_nvp("item", t.reference());
61 typename Container::iterator result =
62 #ifdef BOOST_NO_CXX11_HDR_UNORDERED_MAP
63 s.insert(hint, t.reference());
65 s.emplace_hint(hint, t.reference());
67 ar.reset_object_address(& (result->second), & t.reference().second);
74 template<class Archive, class Type, class Key, class Compare, class Allocator >
77 const std::map<Key, Type, Compare, Allocator> &t,
78 const unsigned int /* file_version */
80 boost::serialization::stl::save_collection<
82 std::map<Key, Type, Compare, Allocator>
86 template<class Archive, class Type, class Key, class Compare, class Allocator >
89 std::map<Key, Type, Compare, Allocator> &t,
90 const unsigned int /* file_version */
92 load_map_collection(ar, t);
95 // split non-intrusive serialization function member into separate
96 // non intrusive save/load member functions
97 template<class Archive, class Type, class Key, class Compare, class Allocator >
98 inline void serialize(
100 std::map<Key, Type, Compare, Allocator> &t,
101 const unsigned int file_version
103 boost::serialization::split_free(ar, t, file_version);
107 template<class Archive, class Type, class Key, class Compare, class Allocator >
110 const std::multimap<Key, Type, Compare, Allocator> &t,
111 const unsigned int /* file_version */
113 boost::serialization::stl::save_collection<
115 std::multimap<Key, Type, Compare, Allocator>
119 template<class Archive, class Type, class Key, class Compare, class Allocator >
122 std::multimap<Key, Type, Compare, Allocator> &t,
123 const unsigned int /* file_version */
125 load_map_collection(ar, t);
128 // split non-intrusive serialization function member into separate
129 // non intrusive save/load member functions
130 template<class Archive, class Type, class Key, class Compare, class Allocator >
131 inline void serialize(
133 std::multimap<Key, Type, Compare, Allocator> &t,
134 const unsigned int file_version
136 boost::serialization::split_free(ar, t, file_version);
142 #endif // BOOST_SERIALIZATION_MAP_HPP