1 #ifndef BOOST_SERIALIZATION_MAP_HPP
2 #define BOOST_SERIALIZATION_MAP_HPP
3
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER)
6 # pragma once
7 #endif
8
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // serialization/map.hpp:
11 // serialization for stl map templates
12
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)
17
18 // See http://www.boost.org for updates, documentation, and revision history.
19
20 #include <map>
21
22 #include <boost/config.hpp>
23
24 #include <boost/serialization/access.hpp>
25 #include <boost/serialization/nvp.hpp>
26 #include <boost/serialization/collection_size_type.hpp>
27 #include <boost/serialization/item_version_type.hpp>
28 #include <boost/serialization/library_version_type.hpp>
29 #include <boost/serialization/detail/stack_constructor.hpp>
30
31 #include <boost/serialization/utility.hpp>
32 #include <boost/serialization/collections_save_imp.hpp>
33 #include <boost/serialization/split_free.hpp>
34 #include <boost/move/utility_core.hpp>
35
36 namespace boost {
37 namespace serialization {
38
39 ////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
40 // implementation of serialization for map and mult-map STL containers
41
42 template<class Archive, class Container>
load_map_collection(Archive & ar,Container & s)43 inline void load_map_collection(Archive & ar, Container &s)
44 {
45 s.clear();
46 const boost::serialization::library_version_type library_version(
47 ar.get_library_version()
48 );
49 // retrieve number of elements
50 item_version_type item_version(0);
51 collection_size_type count;
52 ar >> BOOST_SERIALIZATION_NVP(count);
53 if(boost::serialization::library_version_type(3) < library_version){
54 ar >> BOOST_SERIALIZATION_NVP(item_version);
55 }
56 typename Container::iterator hint;
57 hint = s.begin();
58 while(count-- > 0){
59 typedef typename Container::value_type type;
60 detail::stack_construct<Archive, type> t(ar, item_version);
61 ar >> boost::serialization::make_nvp("item", t.reference());
62 typename Container::iterator result =
63 s.insert(hint, boost::move(t.reference()));
64 ar.reset_object_address(& (result->second), & t.reference().second);
65 hint = result;
66 ++hint;
67 }
68 }
69
70 // map
71 template<class Archive, class Type, class Key, class Compare, class Allocator >
save(Archive & ar,const std::map<Key,Type,Compare,Allocator> & t,const unsigned int)72 inline void save(
73 Archive & ar,
74 const std::map<Key, Type, Compare, Allocator> &t,
75 const unsigned int /* file_version */
76 ){
77 boost::serialization::stl::save_collection<
78 Archive,
79 std::map<Key, Type, Compare, Allocator>
80 >(ar, t);
81 }
82
83 template<class Archive, class Type, class Key, class Compare, class Allocator >
load(Archive & ar,std::map<Key,Type,Compare,Allocator> & t,const unsigned int)84 inline void load(
85 Archive & ar,
86 std::map<Key, Type, Compare, Allocator> &t,
87 const unsigned int /* file_version */
88 ){
89 load_map_collection(ar, t);
90 }
91
92 // split non-intrusive serialization function member into separate
93 // non intrusive save/load member functions
94 template<class Archive, class Type, class Key, class Compare, class Allocator >
serialize(Archive & ar,std::map<Key,Type,Compare,Allocator> & t,const unsigned int file_version)95 inline void serialize(
96 Archive & ar,
97 std::map<Key, Type, Compare, Allocator> &t,
98 const unsigned int file_version
99 ){
100 boost::serialization::split_free(ar, t, file_version);
101 }
102
103 // multimap
104 template<class Archive, class Type, class Key, class Compare, class Allocator >
save(Archive & ar,const std::multimap<Key,Type,Compare,Allocator> & t,const unsigned int)105 inline void save(
106 Archive & ar,
107 const std::multimap<Key, Type, Compare, Allocator> &t,
108 const unsigned int /* file_version */
109 ){
110 boost::serialization::stl::save_collection<
111 Archive,
112 std::multimap<Key, Type, Compare, Allocator>
113 >(ar, t);
114 }
115
116 template<class Archive, class Type, class Key, class Compare, class Allocator >
load(Archive & ar,std::multimap<Key,Type,Compare,Allocator> & t,const unsigned int)117 inline void load(
118 Archive & ar,
119 std::multimap<Key, Type, Compare, Allocator> &t,
120 const unsigned int /* file_version */
121 ){
122 load_map_collection(ar, t);
123 }
124
125 // split non-intrusive serialization function member into separate
126 // non intrusive save/load member functions
127 template<class Archive, class Type, class Key, class Compare, class Allocator >
serialize(Archive & ar,std::multimap<Key,Type,Compare,Allocator> & t,const unsigned int file_version)128 inline void serialize(
129 Archive & ar,
130 std::multimap<Key, Type, Compare, Allocator> &t,
131 const unsigned int file_version
132 ){
133 boost::serialization::split_free(ar, t, file_version);
134 }
135
136 } // serialization
137 } // namespace boost
138
139 #endif // BOOST_SERIALIZATION_MAP_HPP
140