Chris@16
|
1 #ifndef BOOST_SERIALIZATION_DEQUE_HPP
|
Chris@16
|
2 #define BOOST_SERIALIZATION_DEQUE_HPP
|
Chris@16
|
3
|
Chris@16
|
4 // MS compatible compilers support #pragma once
|
Chris@101
|
5 #if defined(_MSC_VER)
|
Chris@16
|
6 # pragma once
|
Chris@16
|
7 #endif
|
Chris@16
|
8
|
Chris@16
|
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
Chris@16
|
10 // deque.hpp
|
Chris@16
|
11
|
Chris@16
|
12 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
Chris@16
|
13 // Use, modification and distribution is subject to the Boost Software
|
Chris@16
|
14 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
15 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
16
|
Chris@16
|
17 // See http://www.boost.org for updates, documentation, and revision history.
|
Chris@16
|
18
|
Chris@16
|
19 #include <deque>
|
Chris@16
|
20
|
Chris@16
|
21 #include <boost/config.hpp>
|
Chris@16
|
22
|
Chris@16
|
23 #include <boost/serialization/collections_save_imp.hpp>
|
Chris@101
|
24 #include <boost/serialization/detail/stack_constructor.hpp>
|
Chris@101
|
25 #include <boost/serialization/detail/is_default_constructible.hpp>
|
Chris@16
|
26 #include <boost/serialization/split_free.hpp>
|
Chris@16
|
27
|
Chris@16
|
28 namespace boost {
|
Chris@16
|
29 namespace serialization {
|
Chris@16
|
30
|
Chris@16
|
31 template<class Archive, class U, class Allocator>
|
Chris@16
|
32 inline void save(
|
Chris@16
|
33 Archive & ar,
|
Chris@16
|
34 const std::deque<U, Allocator> &t,
|
Chris@16
|
35 const unsigned int /* file_version */
|
Chris@16
|
36 ){
|
Chris@16
|
37 boost::serialization::stl::save_collection<
|
Chris@16
|
38 Archive, std::deque<U, Allocator>
|
Chris@16
|
39 >(ar, t);
|
Chris@16
|
40 }
|
Chris@16
|
41
|
Chris@16
|
42 template<class Archive, class U, class Allocator>
|
Chris@16
|
43 inline void load(
|
Chris@16
|
44 Archive & ar,
|
Chris@16
|
45 std::deque<U, Allocator> &t,
|
Chris@16
|
46 const unsigned int /*file_version*/
|
Chris@16
|
47 ){
|
Chris@101
|
48 const boost::archive::library_version_type library_version(
|
Chris@101
|
49 ar.get_library_version()
|
Chris@101
|
50 );
|
Chris@101
|
51 // retrieve number of elements
|
Chris@101
|
52 item_version_type item_version(0);
|
Chris@101
|
53 collection_size_type count;
|
Chris@101
|
54 ar >> BOOST_SERIALIZATION_NVP(count);
|
Chris@101
|
55 if(boost::archive::library_version_type(3) < library_version){
|
Chris@101
|
56 ar >> BOOST_SERIALIZATION_NVP(item_version);
|
Chris@101
|
57 }
|
Chris@101
|
58 if(detail::is_default_constructible<U>()){
|
Chris@101
|
59 t.resize(count);
|
Chris@101
|
60 typename std::deque<U, Allocator>::iterator hint;
|
Chris@101
|
61 hint = t.begin();
|
Chris@101
|
62 while(count-- > 0){
|
Chris@101
|
63 ar >> boost::serialization::make_nvp("item", *hint++);
|
Chris@101
|
64 }
|
Chris@101
|
65 }
|
Chris@101
|
66 else{
|
Chris@101
|
67 t.clear();
|
Chris@101
|
68 while(count-- > 0){
|
Chris@101
|
69 detail::stack_construct<Archive, U> u(ar, item_version);
|
Chris@101
|
70 ar >> boost::serialization::make_nvp("item", u.reference());
|
Chris@101
|
71 t.push_back(u.reference());
|
Chris@101
|
72 ar.reset_object_address(& t.back() , & u.reference());
|
Chris@101
|
73 }
|
Chris@101
|
74 }
|
Chris@16
|
75 }
|
Chris@16
|
76
|
Chris@16
|
77 // split non-intrusive serialization function member into separate
|
Chris@16
|
78 // non intrusive save/load member functions
|
Chris@16
|
79 template<class Archive, class U, class Allocator>
|
Chris@16
|
80 inline void serialize(
|
Chris@16
|
81 Archive & ar,
|
Chris@16
|
82 std::deque<U, Allocator> &t,
|
Chris@16
|
83 const unsigned int file_version
|
Chris@16
|
84 ){
|
Chris@16
|
85 boost::serialization::split_free(ar, t, file_version);
|
Chris@16
|
86 }
|
Chris@16
|
87
|
Chris@16
|
88 } // namespace serialization
|
Chris@16
|
89 } // namespace boost
|
Chris@16
|
90
|
Chris@16
|
91 #include <boost/serialization/collection_traits.hpp>
|
Chris@16
|
92
|
Chris@16
|
93 BOOST_SERIALIZATION_COLLECTION_TRAITS(std::deque)
|
Chris@16
|
94
|
Chris@16
|
95 #endif // BOOST_SERIALIZATION_DEQUE_HPP
|