1 #ifndef BOOST_SERIALIZATION_SET_HPP
2 #define BOOST_SERIALIZATION_SET_HPP
4 // MS compatible compilers support #pragma once
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // set.hpp: serialization for stl set templates
12 // (C) Copyright 2002-2014 Robert Ramey - http://www.rrsd.com .
13 // Use, modification and distribution is subject to the Boost Software
14 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
17 // See http://www.boost.org for updates, documentation, and revision history.
21 #include <boost/config.hpp>
23 #include <boost/archive/detail/basic_iarchive.hpp>
24 #include <boost/serialization/access.hpp>
25 #include <boost/serialization/nvp.hpp>
26 #include <boost/serialization/detail/stack_constructor.hpp>
27 #include <boost/serialization/collection_size_type.hpp>
28 #include <boost/serialization/item_version_type.hpp>
30 #include <boost/serialization/collections_save_imp.hpp>
31 #include <boost/serialization/split_free.hpp>
34 namespace serialization {
36 template<class Archive, class Container>
37 inline void load_set_collection(Archive & ar, Container &s)
40 const boost::archive::library_version_type library_version(
41 ar.get_library_version()
43 // retrieve number of elements
44 item_version_type item_version(0);
45 collection_size_type count;
46 ar >> BOOST_SERIALIZATION_NVP(count);
47 if(boost::archive::library_version_type(3) < library_version){
48 ar >> BOOST_SERIALIZATION_NVP(item_version);
50 typename Container::iterator hint;
53 typedef typename Container::value_type type;
54 detail::stack_construct<Archive, type> t(ar, item_version);
55 // borland fails silently w/o full namespace
56 ar >> boost::serialization::make_nvp("item", t.reference());
57 typename Container::iterator result =
58 #ifdef BOOST_NO_CXX11_HDR_UNORDERED_SET
59 s.insert(hint, t.reference());
61 s.emplace_hint(hint, t.reference());
63 ar.reset_object_address(& (* result), & t.reference());
68 template<class Archive, class Key, class Compare, class Allocator >
71 const std::set<Key, Compare, Allocator> &t,
72 const unsigned int /* file_version */
74 boost::serialization::stl::save_collection<
75 Archive, std::set<Key, Compare, Allocator>
79 template<class Archive, class Key, class Compare, class Allocator >
82 std::set<Key, Compare, Allocator> &t,
83 const unsigned int /* file_version */
85 load_set_collection(ar, t);
88 // split non-intrusive serialization function member into separate
89 // non intrusive save/load member functions
90 template<class Archive, class Key, class Compare, class Allocator >
91 inline void serialize(
93 std::set<Key, Compare, Allocator> & t,
94 const unsigned int file_version
96 boost::serialization::split_free(ar, t, file_version);
100 template<class Archive, class Key, class Compare, class Allocator >
103 const std::multiset<Key, Compare, Allocator> &t,
104 const unsigned int /* file_version */
106 boost::serialization::stl::save_collection<
108 std::multiset<Key, Compare, Allocator>
112 template<class Archive, class Key, class Compare, class Allocator >
115 std::multiset<Key, Compare, Allocator> &t,
116 const unsigned int /* file_version */
118 load_set_collection(ar, t);
121 // split non-intrusive serialization function member into separate
122 // non intrusive save/load member functions
123 template<class Archive, class Key, class Compare, class Allocator >
124 inline void serialize(
126 std::multiset<Key, Compare, Allocator> & t,
127 const unsigned int file_version
129 boost::serialization::split_free(ar, t, file_version);
132 } // namespace serialization
135 #include <boost/serialization/collection_traits.hpp>
137 BOOST_SERIALIZATION_COLLECTION_TRAITS(std::set)
138 BOOST_SERIALIZATION_COLLECTION_TRAITS(std::multiset)
140 #endif // BOOST_SERIALIZATION_SET_HPP