1 #ifndef BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP
2 #define BOOST_SERIALIZATION_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 // 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/core/addressof.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>
28 
29 namespace boost{
30 namespace serialization {
31 namespace stl {
32 
33 //////////////////////////////////////////////////////////////////////
34 // implementation of serialization for STL containers
35 //
36 
37 template<class Archive, class Container>
save_collection(Archive & ar,const Container & s,collection_size_type count)38 inline void save_collection(
39     Archive & ar,
40     const Container &s,
41     collection_size_type count)
42 {
43     ar << BOOST_SERIALIZATION_NVP(count);
44     // record number of elements
45     const item_version_type item_version(
46         version<typename Container::value_type>::value
47     );
48 
49     ar << BOOST_SERIALIZATION_NVP(item_version);
50 
51     typename Container::const_iterator it = s.begin();
52     while(count-- > 0){
53         // note borland emits a no-op without the explicit namespace
54         boost::serialization::save_construct_data_adl(
55             ar,
56             boost::addressof(*it),
57             item_version
58         );
59         ar << boost::serialization::make_nvp("item", *it++);
60     }
61 }
62 
63 template<class Archive, class Container>
save_collection(Archive & ar,const Container & s)64 inline void save_collection(Archive & ar, const Container &s)
65 {
66     // record number of elements
67     collection_size_type count(s.size());
68     save_collection(ar, s, count);
69 }
70 
71 } // namespace stl
72 } // namespace serialization
73 } // namespace boost
74 
75 #endif //BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP
76