Brian Silverman | 8867871 | 2018-08-04 23:56:48 -0700 | [diff] [blame^] | 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 | #include <boost/move/utility_core.hpp> |
| 33 | |
| 34 | namespace boost { |
| 35 | namespace serialization { |
| 36 | |
| 37 | template<class Archive, class Container> |
| 38 | inline void load_set_collection(Archive & ar, Container &s) |
| 39 | { |
| 40 | s.clear(); |
| 41 | const boost::archive::library_version_type library_version( |
| 42 | ar.get_library_version() |
| 43 | ); |
| 44 | // retrieve number of elements |
| 45 | item_version_type item_version(0); |
| 46 | collection_size_type count; |
| 47 | ar >> BOOST_SERIALIZATION_NVP(count); |
| 48 | if(boost::archive::library_version_type(3) < library_version){ |
| 49 | ar >> BOOST_SERIALIZATION_NVP(item_version); |
| 50 | } |
| 51 | typename Container::iterator hint; |
| 52 | hint = s.begin(); |
| 53 | while(count-- > 0){ |
| 54 | typedef typename Container::value_type type; |
| 55 | detail::stack_construct<Archive, type> t(ar, item_version); |
| 56 | // borland fails silently w/o full namespace |
| 57 | ar >> boost::serialization::make_nvp("item", t.reference()); |
| 58 | typename Container::iterator result = |
| 59 | s.insert(hint, boost::move(t.reference())); |
| 60 | const type * new_address = & (* result); |
| 61 | ar.reset_object_address(new_address, & t.reference()); |
| 62 | hint = result; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | template<class Archive, class Key, class Compare, class Allocator > |
| 67 | inline void save( |
| 68 | Archive & ar, |
| 69 | const std::set<Key, Compare, Allocator> &t, |
| 70 | const unsigned int /* file_version */ |
| 71 | ){ |
| 72 | boost::serialization::stl::save_collection< |
| 73 | Archive, std::set<Key, Compare, Allocator> |
| 74 | >(ar, t); |
| 75 | } |
| 76 | |
| 77 | template<class Archive, class Key, class Compare, class Allocator > |
| 78 | inline void load( |
| 79 | Archive & ar, |
| 80 | std::set<Key, Compare, Allocator> &t, |
| 81 | const unsigned int /* file_version */ |
| 82 | ){ |
| 83 | load_set_collection(ar, t); |
| 84 | } |
| 85 | |
| 86 | // split non-intrusive serialization function member into separate |
| 87 | // non intrusive save/load member functions |
| 88 | template<class Archive, class Key, class Compare, class Allocator > |
| 89 | inline void serialize( |
| 90 | Archive & ar, |
| 91 | std::set<Key, Compare, Allocator> & t, |
| 92 | const unsigned int file_version |
| 93 | ){ |
| 94 | boost::serialization::split_free(ar, t, file_version); |
| 95 | } |
| 96 | |
| 97 | // multiset |
| 98 | template<class Archive, class Key, class Compare, class Allocator > |
| 99 | inline void save( |
| 100 | Archive & ar, |
| 101 | const std::multiset<Key, Compare, Allocator> &t, |
| 102 | const unsigned int /* file_version */ |
| 103 | ){ |
| 104 | boost::serialization::stl::save_collection< |
| 105 | Archive, |
| 106 | std::multiset<Key, Compare, Allocator> |
| 107 | >(ar, t); |
| 108 | } |
| 109 | |
| 110 | template<class Archive, class Key, class Compare, class Allocator > |
| 111 | inline void load( |
| 112 | Archive & ar, |
| 113 | std::multiset<Key, Compare, Allocator> &t, |
| 114 | const unsigned int /* file_version */ |
| 115 | ){ |
| 116 | load_set_collection(ar, t); |
| 117 | } |
| 118 | |
| 119 | // split non-intrusive serialization function member into separate |
| 120 | // non intrusive save/load member functions |
| 121 | template<class Archive, class Key, class Compare, class Allocator > |
| 122 | inline void serialize( |
| 123 | Archive & ar, |
| 124 | std::multiset<Key, Compare, Allocator> & t, |
| 125 | const unsigned int file_version |
| 126 | ){ |
| 127 | boost::serialization::split_free(ar, t, file_version); |
| 128 | } |
| 129 | |
| 130 | } // namespace serialization |
| 131 | } // namespace boost |
| 132 | |
| 133 | #include <boost/serialization/collection_traits.hpp> |
| 134 | |
| 135 | BOOST_SERIALIZATION_COLLECTION_TRAITS(std::set) |
| 136 | BOOST_SERIALIZATION_COLLECTION_TRAITS(std::multiset) |
| 137 | |
| 138 | #endif // BOOST_SERIALIZATION_SET_HPP |