DiaDes  0.1
DIAgnosis of Discrete-Event System
unordered_collections_save_imp.hh
Go to the documentation of this file.
1 #ifndef BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP
2 #define BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP
3 
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
6 # pragma once
7 #endif
8 
10 // hash_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 
33 // implementation of serialization for STL containers
34 //
35 
36 template<class Archive, class Container>
37 inline void save_unordered_collection(Archive & ar, const Container &s)
38 {
39  collection_size_type count(s.size());
40  const collection_size_type bucket_count(s.bucket_count());
41  const item_version_type item_version(
42  version<BOOST_DEDUCED_TYPENAME Container::value_type>::value
43  );
44 
45  #if 0
46  /* should only be necessary to create archives of previous versions
47  * which is not currently supported. So for now comment this out
48  */
49  boost::archive::library_version_type library_version(
50  ar.get_library_version()
51  );
52  // retrieve number of elements
53  ar << BOOST_SERIALIZATION_NVP(count);
54  ar << BOOST_SERIALIZATION_NVP(bucket_count);
55  if(boost::archive::library_version_type(3) < library_version){
56  // record number of elements
57  // make sure the target type is registered so we can retrieve
58  // the version when we load
59  ar << BOOST_SERIALIZATION_NVP(item_version);
60  }
61  #else
62  ar << BOOST_SERIALIZATION_NVP(count);
63  ar << BOOST_SERIALIZATION_NVP(bucket_count);
64  ar << BOOST_SERIALIZATION_NVP(item_version);
65  #endif
66 
67  BOOST_DEDUCED_TYPENAME Container::const_iterator it = s.begin();
68  while(count-- > 0){
69  // note borland emits a no-op without the explicit namespace
70  boost::serialization::save_construct_data_adl(
71  ar,
72  &(*it),
73  boost::serialization::version<
74  BOOST_DEDUCED_TYPENAME Container::value_type
75  >::value
76  );
77  ar << boost::serialization::make_nvp("item", *it++);
78  }
79 }
80 
81 } // namespace stl
82 } // namespace serialization
83 } // namespace boost
84 
85 #endif //BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP
void save_unordered_collection(Archive &ar, const Container &s)