1 | #ifndef BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP |
---|
2 | #define BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP |
---|
3 | |
---|
4 | // MS compatible compilers support #pragma once |
---|
5 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
---|
6 | # pragma once |
---|
7 | #endif |
---|
8 | |
---|
9 | #if defined(_MSC_VER) && (_MSC_VER <= 1020) |
---|
10 | # pragma warning (disable : 4786) // too long name, harmless warning |
---|
11 | #endif |
---|
12 | |
---|
13 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
---|
14 | // collections_load_imp.hpp: serialization for loading stl collections |
---|
15 | |
---|
16 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
---|
17 | // Use, modification and distribution is subject to the Boost Software |
---|
18 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
---|
19 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
20 | |
---|
21 | // See http://www.boost.org for updates, documentation, and revision history. |
---|
22 | |
---|
23 | // helper function templates for serialization of collections |
---|
24 | |
---|
25 | #include <cassert> |
---|
26 | #include <boost/config.hpp> |
---|
27 | #include <boost/detail/workaround.hpp> |
---|
28 | |
---|
29 | #include <boost/aligned_storage.hpp> |
---|
30 | |
---|
31 | #include <boost/serialization/access.hpp> |
---|
32 | #include <boost/serialization/nvp.hpp> |
---|
33 | #include <boost/serialization/detail/stack_constructor.hpp> |
---|
34 | |
---|
35 | namespace boost{ |
---|
36 | namespace serialization { |
---|
37 | namespace stl { |
---|
38 | |
---|
39 | ////////////////////////////////////////////////////////////////////// |
---|
40 | // implementation of serialization for STL containers |
---|
41 | // |
---|
42 | |
---|
43 | // sequential container input |
---|
44 | template<class Archive, class Container> |
---|
45 | struct archive_input_seq |
---|
46 | { |
---|
47 | inline void operator()( |
---|
48 | Archive &ar, |
---|
49 | Container &s, |
---|
50 | const unsigned int v |
---|
51 | ){ |
---|
52 | typedef BOOST_DEDUCED_TYPENAME Container::value_type type; |
---|
53 | detail::stack_construct<Archive, type> t(ar, v); |
---|
54 | // borland fails silently w/o full namespace |
---|
55 | ar >> boost::serialization::make_nvp("item", t.reference()); |
---|
56 | s.push_back(t.reference()); |
---|
57 | ar.reset_object_address(& s.back() , & t.reference()); |
---|
58 | } |
---|
59 | }; |
---|
60 | |
---|
61 | // map and set input |
---|
62 | template<class Archive, class Container> |
---|
63 | struct archive_input_unique |
---|
64 | { |
---|
65 | inline void operator()( |
---|
66 | Archive &ar, |
---|
67 | Container &s, |
---|
68 | const unsigned int v |
---|
69 | ){ |
---|
70 | typedef BOOST_DEDUCED_TYPENAME Container::value_type type; |
---|
71 | detail::stack_construct<Archive, type>t(ar, v); |
---|
72 | // borland fails silently w/o full namespace |
---|
73 | ar >> boost::serialization::make_nvp("item", t.reference()); |
---|
74 | std::pair<BOOST_DEDUCED_TYPENAME Container::const_iterator, bool> result = |
---|
75 | s.insert(t.reference()); |
---|
76 | if(result.second) |
---|
77 | ar.reset_object_address(& (* result.first), & t.reference()); |
---|
78 | } |
---|
79 | }; |
---|
80 | |
---|
81 | // multiset and multimap input |
---|
82 | template<class Archive, class Container> |
---|
83 | struct archive_input_multi |
---|
84 | { |
---|
85 | inline void operator()( |
---|
86 | Archive &ar, |
---|
87 | Container &s, |
---|
88 | const unsigned int v |
---|
89 | ){ |
---|
90 | typedef BOOST_DEDUCED_TYPENAME Container::value_type type; |
---|
91 | detail::stack_construct<Archive, type> t(ar, v); |
---|
92 | // borland fails silently w/o full namespace |
---|
93 | ar >> boost::serialization::make_nvp("item", t.reference()); |
---|
94 | BOOST_DEDUCED_TYPENAME Container::const_iterator result |
---|
95 | = s.insert(t.reference()); |
---|
96 | ar.reset_object_address(& (* result), & t.reference()); |
---|
97 | } |
---|
98 | }; |
---|
99 | |
---|
100 | template<class Container> |
---|
101 | class reserve_imp |
---|
102 | { |
---|
103 | public: |
---|
104 | void operator()(Container &s, unsigned int count) const { |
---|
105 | s.reserve(count); |
---|
106 | } |
---|
107 | }; |
---|
108 | |
---|
109 | template<class Container> |
---|
110 | class no_reserve_imp |
---|
111 | { |
---|
112 | public: |
---|
113 | void operator()(Container & /* s */, unsigned int /* count */) const{} |
---|
114 | }; |
---|
115 | |
---|
116 | template<class Archive, class Container, class InputFunction, class R> |
---|
117 | inline void load_collection(Archive & ar, Container &s) |
---|
118 | { |
---|
119 | s.clear(); |
---|
120 | // retrieve number of elements |
---|
121 | unsigned int count; |
---|
122 | unsigned int item_version(0); |
---|
123 | ar >> BOOST_SERIALIZATION_NVP(count); |
---|
124 | if(3 < ar.get_library_version()){ |
---|
125 | ar >> BOOST_SERIALIZATION_NVP(item_version); |
---|
126 | } |
---|
127 | R rx; |
---|
128 | rx(s, count); |
---|
129 | InputFunction ifunc; |
---|
130 | while(count-- > 0){ |
---|
131 | ifunc(ar, s, item_version); |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | } // namespace stl |
---|
136 | } // namespace serialization |
---|
137 | } // namespace boost |
---|
138 | |
---|
139 | #endif //BOOST_SERIALIZATION_COLLECTIONS_LOAD_IMP_HPP |
---|