1#ifndef BOOST_SERIALIZATION_SET_HPP
2#define BOOST_SERIALIZATION_SET_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// set.hpp: serialization for stl set templates
11
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)
16
17// See http://www.boost.org for updates, documentation, and revision history.
18
19#include <set>
20
21#include <boost/config.hpp>
22
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>
29
30#include <boost/serialization/collections_save_imp.hpp>
31#include <boost/serialization/split_free.hpp>
32
33namespace boost {
34namespace serialization {
35
36template<class Archive, class Container>
37inline void load_set_collection(Archive & ar, Container &s)
38{
39 s.clear();
40 const boost::archive::library_version_type library_version(
41 ar.get_library_version()
42 );
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);
49 }
50 typename Container::iterator hint;
51 hint = s.begin();
52 while(count-- > 0){
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 = s.insert(hint, t.reference());
58 ar.reset_object_address(& (* result), & t.reference());
59 hint = result;
60 }
61}
62
63template<class Archive, class Key, class Compare, class Allocator >
64inline void save(
65 Archive & ar,
66 const std::set<Key, Compare, Allocator> &t,
67 const unsigned int /* file_version */
68){
69 boost::serialization::stl::save_collection<
70 Archive, std::set<Key, Compare, Allocator>
71 >(ar, t);
72}
73
74template<class Archive, class Key, class Compare, class Allocator >
75inline void load(
76 Archive & ar,
77 std::set<Key, Compare, Allocator> &t,
78 const unsigned int /* file_version */
79){
80 load_set_collection(ar, t);
81}
82
83// split non-intrusive serialization function member into separate
84// non intrusive save/load member functions
85template<class Archive, class Key, class Compare, class Allocator >
86inline void serialize(
87 Archive & ar,
88 std::set<Key, Compare, Allocator> & t,
89 const unsigned int file_version
90){
91 boost::serialization::split_free(ar, t, file_version);
92}
93
94// multiset
95template<class Archive, class Key, class Compare, class Allocator >
96inline void save(
97 Archive & ar,
98 const std::multiset<Key, Compare, Allocator> &t,
99 const unsigned int /* file_version */
100){
101 boost::serialization::stl::save_collection<
102 Archive,
103 std::multiset<Key, Compare, Allocator>
104 >(ar, t);
105}
106
107template<class Archive, class Key, class Compare, class Allocator >
108inline void load(
109 Archive & ar,
110 std::multiset<Key, Compare, Allocator> &t,
111 const unsigned int /* file_version */
112){
113 load_set_collection(ar, t);
114}
115
116// split non-intrusive serialization function member into separate
117// non intrusive save/load member functions
118template<class Archive, class Key, class Compare, class Allocator >
119inline void serialize(
120 Archive & ar,
121 std::multiset<Key, Compare, Allocator> & t,
122 const unsigned int file_version
123){
124 boost::serialization::split_free(ar, t, file_version);
125}
126
127} // namespace serialization
128} // namespace boost
129
130#include <boost/serialization/collection_traits.hpp>
131
132BOOST_SERIALIZATION_COLLECTION_TRAITS(std::set)
133BOOST_SERIALIZATION_COLLECTION_TRAITS(std::multiset)
134
135#endif // BOOST_SERIALIZATION_SET_HPP
136

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