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
35namespace boost {
36namespace serialization {
37
38////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
39// implementation of serialization for map and mult-map STL containers
40
41template<class Archive, class Container>
42inline 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// map
69template<class Archive, class Type, class Key, class Compare, class Allocator >
70inline void save(
71 Archive & ar,
72 const std::map<Key, Type, Compare, Allocator> &t,
73 const unsigned int /* file_version */
74){
75 boost::serialization::stl::save_collection<
76 Archive,
77 std::map<Key, Type, Compare, Allocator>
78 >(ar, t);
79}
80
81template<class Archive, class Type, class Key, class Compare, class Allocator >
82inline void load(
83 Archive & ar,
84 std::map<Key, Type, Compare, Allocator> &t,
85 const unsigned int /* file_version */
86){
87 load_map_collection(ar, t);
88}
89
90// split non-intrusive serialization function member into separate
91// non intrusive save/load member functions
92template<class Archive, class Type, class Key, class Compare, class Allocator >
93inline void serialize(
94 Archive & ar,
95 std::map<Key, Type, Compare, Allocator> &t,
96 const unsigned int file_version
97){
98 boost::serialization::split_free(ar, t, file_version);
99}
100
101// multimap
102template<class Archive, class Type, class Key, class Compare, class Allocator >
103inline void save(
104 Archive & ar,
105 const std::multimap<Key, Type, Compare, Allocator> &t,
106 const unsigned int /* file_version */
107){
108 boost::serialization::stl::save_collection<
109 Archive,
110 std::multimap<Key, Type, Compare, Allocator>
111 >(ar, t);
112}
113
114template<class Archive, class Type, class Key, class Compare, class Allocator >
115inline void load(
116 Archive & ar,
117 std::multimap<Key, Type, Compare, Allocator> &t,
118 const unsigned int /* file_version */
119){
120 load_map_collection(ar, t);
121}
122
123// split non-intrusive serialization function member into separate
124// non intrusive save/load member functions
125template<class Archive, class Type, class Key, class Compare, class Allocator >
126inline void serialize(
127 Archive & ar,
128 std::multimap<Key, Type, Compare, Allocator> &t,
129 const unsigned int file_version
130){
131 boost::serialization::split_free(ar, t, file_version);
132}
133
134} // serialization
135} // namespace boost
136
137#endif // BOOST_SERIALIZATION_MAP_HPP
138

source code of boost/boost/serialization/map.hpp