1 #ifndef BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP
2 #define BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // hash_collections_save_imp.hpp: serialization for stl collections
12 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
13 // (C) Copyright 2014 Jim Bell
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)
18 // See http://www.boost.org for updates, documentation, and revision history.
20 // helper function templates for serialization of collections
22 #include <boost/config.hpp>
23 #include <boost/serialization/nvp.hpp>
24 #include <boost/serialization/serialization.hpp>
25 #include <boost/serialization/version.hpp>
26 #include <boost/serialization/collection_size_type.hpp>
27 #include <boost/serialization/item_version_type.hpp>
30 namespace serialization {
33 //////////////////////////////////////////////////////////////////////
34 // implementation of serialization for STL containers
37 template<class Archive, class Container>
38 inline void save_unordered_collection(Archive & ar, const Container &s)
40 collection_size_type count(s.size());
41 const collection_size_type bucket_count(s.bucket_count());
42 const item_version_type item_version(
43 version<typename Container::value_type>::value
47 /* should only be necessary to create archives of previous versions
48 * which is not currently supported. So for now comment this out
50 boost::archive::library_version_type library_version(
51 ar.get_library_version()
53 // retrieve number of elements
54 ar << BOOST_SERIALIZATION_NVP(count);
55 ar << BOOST_SERIALIZATION_NVP(bucket_count);
56 if(boost::archive::library_version_type(3) < library_version){
57 // record number of elements
58 // make sure the target type is registered so we can retrieve
59 // the version when we load
60 ar << BOOST_SERIALIZATION_NVP(item_version);
63 ar << BOOST_SERIALIZATION_NVP(count);
64 ar << BOOST_SERIALIZATION_NVP(bucket_count);
65 ar << BOOST_SERIALIZATION_NVP(item_version);
68 typename Container::const_iterator it = s.begin();
70 // note borland emits a no-op without the explicit namespace
71 boost::serialization::save_construct_data_adl(
74 boost::serialization::version<
75 typename Container::value_type
78 ar << boost::serialization::make_nvp("item", *it++);
83 } // namespace serialization
86 #endif //BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP