1#ifndef BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP
2#define BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_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/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10// hash_collections_save_imp.hpp: serialization for stl collections
11
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)
17
18// See http://www.boost.org for updates, documentation, and revision history.
19
20// helper function templates for serialization of collections
21
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>
28
29namespace boost{
30namespace serialization {
31namespace stl {
32
33//////////////////////////////////////////////////////////////////////
34// implementation of serialization for STL containers
35//
36
37template<class Archive, class Container>
38inline void save_unordered_collection(Archive & ar, const Container &s)
39{
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
44 );
45
46 #if 0
47 /* should only be necessary to create archives of previous versions
48 * which is not currently supported. So for now comment this out
49 */
50 boost::archive::library_version_type library_version(
51 ar.get_library_version()
52 );
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);
61 }
62 #else
63 ar << BOOST_SERIALIZATION_NVP(count);
64 ar << BOOST_SERIALIZATION_NVP(bucket_count);
65 ar << BOOST_SERIALIZATION_NVP(item_version);
66 #endif
67
68 typename Container::const_iterator it = s.begin();
69 while(count-- > 0){
70 // note borland emits a no-op without the explicit namespace
71 boost::serialization::save_construct_data_adl(
72 ar,
73 &(*it),
74 boost::serialization::version<
75 typename Container::value_type
76 >::value
77 );
78 ar << boost::serialization::make_nvp("item", *it++);
79 }
80}
81
82} // namespace stl
83} // namespace serialization
84} // namespace boost
85
86#endif //BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP
87

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