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/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>
|
---|
30 |
|
---|
31 | #include <boost/serialization/utility.hpp>
|
---|
32 | #include <boost/serialization/collections_save_imp.hpp>
|
---|
33 | #include <boost/serialization/split_free.hpp>
|
---|
34 |
|
---|
35 | namespace boost {
|
---|
36 | namespace serialization {
|
---|
37 |
|
---|
38 | ////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
---|
39 | // implementation of serialization for map and mult-map STL containers
|
---|
40 |
|
---|
41 | template<class Archive, class Container>
|
---|
42 | inline void load_map_collection(Archive & ar, Container &s)
|
---|
43 | {
|
---|
44 | s.clear();
|
---|
45 | const boost::archive::library_version_type library_version(
|
---|
46 | ar.get_library_version()
|
---|
47 | );
|
---|
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);
|
---|
54 | }
|
---|
55 | typename Container::iterator hint;
|
---|
56 | hint = s.begin();
|
---|
57 | while(count-- > 0){
|
---|
58 | typedef typename Container::value_type type;
|
---|
59 | detail::stack_construct<Archive, type> t(ar, item_version);
|
---|
60 | // borland fails silently w/o full namespace
|
---|
61 | ar >> boost::serialization::make_nvp("item", t.reference());
|
---|
62 | typename Container::iterator result = s.insert(hint, t.reference());
|
---|
63 | ar.reset_object_address(& (result->second), & t.reference().second);
|
---|
64 | hint = result;
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | template<class Archive, class Container>
|
---|
69 | inline void load_multimap_collection(Archive & ar, Container &s)
|
---|
70 | {
|
---|
71 | s.clear();
|
---|
72 | const boost::archive::library_version_type library_version(
|
---|
73 | ar.get_library_version()
|
---|
74 | );
|
---|
75 | // retrieve number of elements
|
---|
76 | item_version_type item_version(0);
|
---|
77 | collection_size_type count;
|
---|
78 | ar >> BOOST_SERIALIZATION_NVP(count);
|
---|
79 | if(boost::archive::library_version_type(3) < library_version){
|
---|
80 | ar >> BOOST_SERIALIZATION_NVP(item_version);
|
---|
81 | }
|
---|
82 | while(count-- > 0){
|
---|
83 | typedef typename Container::value_type type;
|
---|
84 | detail::stack_construct<Archive, type> t(ar, item_version);
|
---|
85 | // borland fails silently w/o full namespace
|
---|
86 | ar >> boost::serialization::make_nvp("item", t.reference());
|
---|
87 | typename Container::iterator result = s.insert(t.reference());
|
---|
88 | ar.reset_object_address(& (result->second), & t.reference().second);
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | // map
|
---|
93 | template<class Archive, class Type, class Key, class Compare, class Allocator >
|
---|
94 | inline void save(
|
---|
95 | Archive & ar,
|
---|
96 | const std::map<Key, Type, Compare, Allocator> &t,
|
---|
97 | const unsigned int /* file_version */
|
---|
98 | ){
|
---|
99 | boost::serialization::stl::save_collection<
|
---|
100 | Archive,
|
---|
101 | std::map<Key, Type, Compare, Allocator>
|
---|
102 | >(ar, t);
|
---|
103 | }
|
---|
104 |
|
---|
105 | template<class Archive, class Type, class Key, class Compare, class Allocator >
|
---|
106 | inline void load(
|
---|
107 | Archive & ar,
|
---|
108 | std::map<Key, Type, Compare, Allocator> &t,
|
---|
109 | const unsigned int /* file_version */
|
---|
110 | ){
|
---|
111 | load_map_collection(ar, t);
|
---|
112 | }
|
---|
113 |
|
---|
114 | // split non-intrusive serialization function member into separate
|
---|
115 | // non intrusive save/load member functions
|
---|
116 | template<class Archive, class Type, class Key, class Compare, class Allocator >
|
---|
117 | inline void serialize(
|
---|
118 | Archive & ar,
|
---|
119 | std::map<Key, Type, Compare, Allocator> &t,
|
---|
120 | const unsigned int file_version
|
---|
121 | ){
|
---|
122 | boost::serialization::split_free(ar, t, file_version);
|
---|
123 | }
|
---|
124 |
|
---|
125 | // multimap
|
---|
126 | template<class Archive, class Type, class Key, class Compare, class Allocator >
|
---|
127 | inline void save(
|
---|
128 | Archive & ar,
|
---|
129 | const std::multimap<Key, Type, Compare, Allocator> &t,
|
---|
130 | const unsigned int /* file_version */
|
---|
131 | ){
|
---|
132 | boost::serialization::stl::save_collection<
|
---|
133 | Archive,
|
---|
134 | std::multimap<Key, Type, Compare, Allocator>
|
---|
135 | >(ar, t);
|
---|
136 | }
|
---|
137 |
|
---|
138 | template<class Archive, class Type, class Key, class Compare, class Allocator >
|
---|
139 | inline void load(
|
---|
140 | Archive & ar,
|
---|
141 | std::multimap<Key, Type, Compare, Allocator> &t,
|
---|
142 | const unsigned int /* file_version */
|
---|
143 | ){
|
---|
144 | load_multimap_collection(ar, t);
|
---|
145 | }
|
---|
146 |
|
---|
147 | // split non-intrusive serialization function member into separate
|
---|
148 | // non intrusive save/load member functions
|
---|
149 | template<class Archive, class Type, class Key, class Compare, class Allocator >
|
---|
150 | inline void serialize(
|
---|
151 | Archive & ar,
|
---|
152 | std::multimap<Key, Type, Compare, Allocator> &t,
|
---|
153 | const unsigned int file_version
|
---|
154 | ){
|
---|
155 | boost::serialization::split_free(ar, t, file_version);
|
---|
156 | }
|
---|
157 |
|
---|
158 | } // serialization
|
---|
159 | } // namespace boost
|
---|
160 |
|
---|
161 | #endif // BOOST_SERIALIZATION_MAP_HPP
|
---|