]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #ifndef BOOST_SERIALIZATION_FORWARD_LIST_HPP |
2 | #define BOOST_SERIALIZATION_FORWARD_LIST_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 | // forward_list.hpp | |
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 | #include <forward_list> | |
20 | #include <iterator> // distance | |
21 | ||
22 | #include <boost/config.hpp> | |
23 | #ifdef BOOST_NO_CXX11_HDR_FORWARD_LIST | |
24 | #error "not supported for versions earlier than c++11 | |
25 | #endif | |
26 | ||
27 | #include <boost/serialization/collections_save_imp.hpp> | |
28 | #include <boost/serialization/collections_load_imp.hpp> | |
29 | #include <boost/archive/detail/basic_iarchive.hpp> | |
30 | #include <boost/serialization/nvp.hpp> | |
31 | #include <boost/serialization/collection_size_type.hpp> | |
32 | #include <boost/serialization/item_version_type.hpp> | |
33 | #include <boost/serialization/split_free.hpp> | |
34 | #include <boost/serialization/detail/stack_constructor.hpp> | |
35 | #include <boost/serialization/detail/is_default_constructible.hpp> | |
36 | ||
37 | namespace boost { | |
38 | namespace serialization { | |
39 | ||
40 | template<class Archive, class U, class Allocator> | |
41 | inline void save( | |
42 | Archive & ar, | |
43 | const std::forward_list<U, Allocator> &t, | |
44 | const unsigned int /*file_version*/ | |
45 | ){ | |
46 | const collection_size_type count(std::distance(t.cbegin(), t.cend())); | |
47 | boost::serialization::stl::save_collection< | |
48 | Archive, | |
49 | std::forward_list<U, Allocator> | |
50 | >(ar, t, count); | |
51 | } | |
52 | ||
53 | namespace stl { | |
54 | ||
55 | template< | |
56 | class Archive, | |
57 | class T, | |
58 | class Allocator | |
59 | > | |
60 | typename boost::disable_if< | |
61 | typename detail::is_default_constructible< | |
62 | typename std::forward_list<T, Allocator>::value_type | |
63 | >, | |
64 | void | |
65 | >::type | |
66 | collection_load_impl( | |
67 | Archive & ar, | |
68 | std::forward_list<T, Allocator> &t, | |
69 | collection_size_type count, | |
70 | item_version_type item_version | |
71 | ){ | |
72 | t.clear(); | |
73 | boost::serialization::detail::stack_construct<Archive, T> u(ar, item_version); | |
74 | ar >> boost::serialization::make_nvp("item", u.reference()); | |
75 | t.emplace_front(u.reference()); | |
76 | typename std::forward_list<T, Allocator>::iterator last; | |
77 | last = t.begin(); | |
78 | ar.reset_object_address(&(*t.begin()) , & u.reference()); | |
79 | while(--count > 0){ | |
80 | detail::stack_construct<Archive, T> u(ar, item_version); | |
81 | ar >> boost::serialization::make_nvp("item", u.reference()); | |
82 | last = t.emplace_after(last, u.reference()); | |
83 | ar.reset_object_address(&(*last) , & u.reference()); | |
84 | } | |
85 | } | |
86 | ||
87 | } // stl | |
88 | ||
89 | template<class Archive, class U, class Allocator> | |
90 | inline void load( | |
91 | Archive & ar, | |
92 | std::forward_list<U, Allocator> &t, | |
93 | const unsigned int /*file_version*/ | |
94 | ){ | |
95 | const boost::archive::library_version_type library_version( | |
96 | ar.get_library_version() | |
97 | ); | |
98 | // retrieve number of elements | |
99 | item_version_type item_version(0); | |
100 | collection_size_type count; | |
101 | ar >> BOOST_SERIALIZATION_NVP(count); | |
102 | if(boost::archive::library_version_type(3) < library_version){ | |
103 | ar >> BOOST_SERIALIZATION_NVP(item_version); | |
104 | } | |
105 | stl::collection_load_impl(ar, t, count, item_version); | |
106 | } | |
107 | ||
108 | // split non-intrusive serialization function member into separate | |
109 | // non intrusive save/load member functions | |
110 | template<class Archive, class U, class Allocator> | |
111 | inline void serialize( | |
112 | Archive & ar, | |
113 | std::forward_list<U, Allocator> &t, | |
114 | const unsigned int file_version | |
115 | ){ | |
116 | boost::serialization::split_free(ar, t, file_version); | |
117 | } | |
118 | ||
119 | } // serialization | |
120 | } // namespace boost | |
121 | ||
122 | #include <boost/serialization/collection_traits.hpp> | |
123 | ||
124 | BOOST_SERIALIZATION_COLLECTION_TRAITS(std::forward_list) | |
125 | ||
126 | #endif // BOOST_SERIALIZATION_FORWARD_LIST_HPP |