1 #ifndef BOOST_SERIALIZATION_HASH_COLLECTIONS_SAVE_IMP_HPP
2 #define BOOST_SERIALIZATION_HASH_COLLECTIONS_SAVE_IMP_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 // hash_collections_save_imp.hpp: serialization for stl collections
11
12 // (C) Copyright 2002 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 // helper function templates for serialization of collections
20
21 #include <boost/config.hpp>
22 #include <boost/serialization/nvp.hpp>
23 #include <boost/serialization/serialization.hpp>
24 #include <boost/serialization/collection_size_type.hpp>
25 #include <boost/serialization/item_version_type.hpp>
26
27 namespace boost{
28 namespace serialization {
29 namespace stl {
30
31 //////////////////////////////////////////////////////////////////////
32 // implementation of serialization for STL containers
33 //
34
35 template<class Archive, class Container>
save_hash_collection(Archive & ar,const Container & s)36 inline void save_hash_collection(Archive & ar, const Container &s)
37 {
38 collection_size_type count(s.size());
39 const collection_size_type bucket_count(s.bucket_count());
40 const item_version_type item_version(
41 version<typename Container::value_type>::value
42 );
43
44 #if 0
45 /* should only be necessary to create archives of previous versions
46 * which is not currently supported. So for now comment this out
47 */
48 boost::serialization::library_version_type library_version(
49 ar.get_library_version()
50 );
51 // retrieve number of elements
52 if(boost::serialization::library_version_type(6) != library_version){
53 ar << BOOST_SERIALIZATION_NVP(count);
54 ar << BOOST_SERIALIZATION_NVP(bucket_count);
55 }
56 else{
57 // note: fixup for error in version 6. collection size was
58 // changed to size_t BUT for hashed collections it was implemented
59 // as an unsigned int. This should be a problem only on win64 machines
60 // but I'll leave it for everyone just in case.
61 const unsigned int c = count;
62 const unsigned int bc = bucket_count;
63 ar << BOOST_SERIALIZATION_NVP(c);
64 ar << BOOST_SERIALIZATION_NVP(bc);
65 }
66 if(boost::serialization::library_version_type(3) < library_version){
67 // record number of elements
68 // make sure the target type is registered so we can retrieve
69 // the version when we load
70 ar << BOOST_SERIALIZATION_NVP(item_version);
71 }
72 #else
73 ar << BOOST_SERIALIZATION_NVP(count);
74 ar << BOOST_SERIALIZATION_NVP(bucket_count);
75 ar << BOOST_SERIALIZATION_NVP(item_version);
76 #endif
77
78 typename Container::const_iterator it = s.begin();
79 while(count-- > 0){
80 // note borland emits a no-op without the explicit namespace
81 boost::serialization::save_construct_data_adl(
82 ar,
83 &(*it),
84 boost::serialization::version<
85 typename Container::value_type
86 >::value
87 );
88 ar << boost::serialization::make_nvp("item", *it++);
89 }
90 }
91
92 } // namespace stl
93 } // namespace serialization
94 } // namespace boost
95
96 #endif //BOOST_SERIALIZATION_HASH_COLLECTIONS_SAVE_IMP_HPP
97