Ticket #5265: unordered_collections_load_imp.hpp

File unordered_collections_load_imp.hpp, 2.2 KB (added by Jim Bell <jim@…>, 12 years ago)

boost/serialization/unordered_collections_load_imp.hpp

Line 
1#ifndef BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_LOAD_IMP_HPP
2#define BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_LOAD_IMP_HPP
3
4// MS compatible compilers support #pragma once
5#if defined(_MSC_VER) && (_MSC_VER >= 1020)
6# pragma once
7# pragma warning (disable : 4786) // too long name, harmless warning
8#endif
9
10/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
11// unordered_collections_load_imp.hpp: serialization for loading stl collections
12
13// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
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#include <boost/config.hpp>
22#include <boost/archive/detail/basic_iarchive.hpp>
23#include <boost/serialization/nvp.hpp>
24#include <boost/serialization/collection_size_type.hpp>
25#include <boost/serialization/item_version_type.hpp>
26
27namespace boost{
28namespace serialization {
29namespace stl {
30
31//////////////////////////////////////////////////////////////////////
32// implementation of serialization for STL containers
33//
34template<class Archive, class Container, class InputFunction>
35inline void load_unordered_collection(Archive & ar, Container &s)
36{
37 s.clear();
38 collection_size_type count;
39 collection_size_type bucket_count;
40 boost::serialization::item_version_type item_version(0);
41 boost::archive::library_version_type library_version(
42 ar.get_library_version()
43 );
44 // retrieve number of elements
45 ar >> BOOST_SERIALIZATION_NVP(count);
46 ar >> BOOST_SERIALIZATION_NVP(bucket_count);
47 if(boost::archive::library_version_type(3) < library_version){
48 ar >> BOOST_SERIALIZATION_NVP(item_version);
49 }
50 s.rehash(bucket_count);
51 InputFunction ifunc;
52 while(count-- > 0){
53 ifunc(ar, s, item_version);
54 }
55}
56
57} // namespace stl
58} // namespace serialization
59} // namespace boost
60
61#endif //BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_LOAD_IMP_HPP