]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
f67539c2 | 12 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
7c673cae FG |
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> | |
20effc67 | 28 | #include <boost/serialization/library_version_type.hpp> |
7c673cae FG |
29 | |
30 | namespace boost{ | |
31 | namespace serialization { | |
32 | namespace stl { | |
33 | ||
34 | ////////////////////////////////////////////////////////////////////// | |
35 | // implementation of serialization for STL containers | |
36 | // | |
37 | ||
38 | template<class Archive, class Container> | |
39 | inline void save_unordered_collection(Archive & ar, const Container &s) | |
40 | { | |
41 | collection_size_type count(s.size()); | |
42 | const collection_size_type bucket_count(s.bucket_count()); | |
43 | const item_version_type item_version( | |
44 | version<typename Container::value_type>::value | |
45 | ); | |
46 | ||
47 | #if 0 | |
48 | /* should only be necessary to create archives of previous versions | |
49 | * which is not currently supported. So for now comment this out | |
50 | */ | |
20effc67 | 51 | boost::serialization::library_version_type library_version( |
7c673cae FG |
52 | ar.get_library_version() |
53 | ); | |
54 | // retrieve number of elements | |
55 | ar << BOOST_SERIALIZATION_NVP(count); | |
56 | ar << BOOST_SERIALIZATION_NVP(bucket_count); | |
20effc67 | 57 | if(boost::serialization::library_version_type(3) < library_version){ |
7c673cae FG |
58 | // record number of elements |
59 | // make sure the target type is registered so we can retrieve | |
60 | // the version when we load | |
61 | ar << BOOST_SERIALIZATION_NVP(item_version); | |
62 | } | |
63 | #else | |
64 | ar << BOOST_SERIALIZATION_NVP(count); | |
65 | ar << BOOST_SERIALIZATION_NVP(bucket_count); | |
66 | ar << BOOST_SERIALIZATION_NVP(item_version); | |
67 | #endif | |
68 | ||
69 | typename Container::const_iterator it = s.begin(); | |
70 | while(count-- > 0){ | |
71 | // note borland emits a no-op without the explicit namespace | |
72 | boost::serialization::save_construct_data_adl( | |
f67539c2 TL |
73 | ar, |
74 | &(*it), | |
7c673cae FG |
75 | boost::serialization::version< |
76 | typename Container::value_type | |
77 | >::value | |
78 | ); | |
79 | ar << boost::serialization::make_nvp("item", *it++); | |
80 | } | |
81 | } | |
82 | ||
f67539c2 | 83 | } // namespace stl |
7c673cae FG |
84 | } // namespace serialization |
85 | } // namespace boost | |
86 | ||
87 | #endif //BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP |