unordered_collections_save_imp.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP
  2. #define BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // hash_collections_save_imp.hpp: serialization for stl collections
  9. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  10. // (C) Copyright 2014 Jim Bell
  11. // Use, modification and distribution is subject to the Boost Software
  12. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. // See http://www.boost.org for updates, documentation, and revision history.
  15. // helper function templates for serialization of collections
  16. #include <boost/config.hpp>
  17. #include <boost/serialization/nvp.hpp>
  18. #include <boost/serialization/serialization.hpp>
  19. #include <boost/serialization/version.hpp>
  20. #include <boost/serialization/collection_size_type.hpp>
  21. #include <boost/serialization/item_version_type.hpp>
  22. #include <boost/serialization/library_version_type.hpp>
  23. namespace boost{
  24. namespace serialization {
  25. namespace stl {
  26. //////////////////////////////////////////////////////////////////////
  27. // implementation of serialization for STL containers
  28. //
  29. template<class Archive, class Container>
  30. inline void save_unordered_collection(Archive & ar, const Container &s)
  31. {
  32. collection_size_type count(s.size());
  33. const collection_size_type bucket_count(s.bucket_count());
  34. const item_version_type item_version(
  35. version<typename Container::value_type>::value
  36. );
  37. #if 0
  38. /* should only be necessary to create archives of previous versions
  39. * which is not currently supported. So for now comment this out
  40. */
  41. boost::serialization::library_version_type library_version(
  42. ar.get_library_version()
  43. );
  44. // retrieve number of elements
  45. ar << BOOST_SERIALIZATION_NVP(count);
  46. ar << BOOST_SERIALIZATION_NVP(bucket_count);
  47. if(boost::serialization::library_version_type(3) < library_version){
  48. // record number of elements
  49. // make sure the target type is registered so we can retrieve
  50. // the version when we load
  51. ar << BOOST_SERIALIZATION_NVP(item_version);
  52. }
  53. #else
  54. ar << BOOST_SERIALIZATION_NVP(count);
  55. ar << BOOST_SERIALIZATION_NVP(bucket_count);
  56. ar << BOOST_SERIALIZATION_NVP(item_version);
  57. #endif
  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. boost::serialization::version<
  65. typename Container::value_type
  66. >::value
  67. );
  68. ar << boost::serialization::make_nvp("item", *it++);
  69. }
  70. }
  71. } // namespace stl
  72. } // namespace serialization
  73. } // namespace boost
  74. #endif //BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_SAVE_IMP_HPP