Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / serialization / collections_save_imp.hpp
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/serialization/nvp.hpp>
23 #include <boost/serialization/serialization.hpp>
24 #include <boost/serialization/version.hpp>
25 #include <boost/serialization/collection_size_type.hpp>
26 #include <boost/serialization/item_version_type.hpp>
27
28 namespace boost{
29 namespace serialization {
30 namespace stl {
31
32 //////////////////////////////////////////////////////////////////////
33 // implementation of serialization for STL containers
34 //
35
36 template<class Archive, class Container>
37 inline void save_collection(
38     Archive & ar,
39     const Container &s,
40     collection_size_type count)
41 {
42     ar << BOOST_SERIALIZATION_NVP(count);
43     // record number of elements
44     const item_version_type item_version(
45         version<typename Container::value_type>::value
46     );
47     #if 0
48         boost::archive::library_version_type library_version(
49             ar.get_library_version()
50         );
51         if(boost::archive::library_version_type(3) < library_version){
52             ar << BOOST_SERIALIZATION_NVP(item_version);
53         }
54     #else
55         ar << BOOST_SERIALIZATION_NVP(item_version);
56     #endif
57
58     typename Container::const_iterator it = s.begin();
59     while(count-- > 0){
60         // note borland emits a no-op without the explicit namespace
61         boost::serialization::save_construct_data_adl(
62             ar, 
63             &(*it), 
64             item_version
65         );
66         ar << boost::serialization::make_nvp("item", *it++);
67     }
68 }
69
70 template<class Archive, class Container>
71 inline void save_collection(Archive & ar, const Container &s)
72 {
73     // record number of elements
74     collection_size_type count(s.size());
75     save_collection(ar, s, count);
76 }
77
78 } // namespace stl 
79 } // namespace serialization
80 } // namespace boost
81
82 #endif //BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP