unordered_collections_load_imp.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_LOAD_IMP_HPP
  2. #define BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_LOAD_IMP_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. # pragma warning (disable : 4786) // too long name, harmless warning
  7. #endif
  8. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  9. // unordered_collections_load_imp.hpp: serialization for loading stl collections
  10. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  11. // (C) Copyright 2014 Jim Bell
  12. // Use, modification and distribution is subject to the Boost Software
  13. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. // See http://www.boost.org for updates, documentation, and revision history.
  16. // helper function templates for serialization of collections
  17. #include <boost/assert.hpp>
  18. #include <cstddef> // size_t
  19. #include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
  20. #if defined(BOOST_NO_STDC_NAMESPACE)
  21. namespace std{
  22. using ::size_t;
  23. } // namespace std
  24. #endif
  25. #include <boost/detail/workaround.hpp>
  26. #include <boost/archive/detail/basic_iarchive.hpp>
  27. #include <boost/serialization/access.hpp>
  28. #include <boost/serialization/nvp.hpp>
  29. #include <boost/serialization/collection_size_type.hpp>
  30. #include <boost/serialization/item_version_type.hpp>
  31. namespace boost{
  32. namespace serialization {
  33. namespace stl {
  34. //////////////////////////////////////////////////////////////////////
  35. // implementation of serialization for STL containers
  36. //
  37. template<class Archive, class Container, class InputFunction>
  38. inline void load_unordered_collection(Archive & ar, Container &s)
  39. {
  40. collection_size_type count;
  41. collection_size_type bucket_count;
  42. boost::serialization::item_version_type item_version(0);
  43. boost::archive::library_version_type library_version(
  44. ar.get_library_version()
  45. );
  46. // retrieve number of elements
  47. ar >> BOOST_SERIALIZATION_NVP(count);
  48. ar >> BOOST_SERIALIZATION_NVP(bucket_count);
  49. if(boost::archive::library_version_type(3) < library_version){
  50. ar >> BOOST_SERIALIZATION_NVP(item_version);
  51. }
  52. s.clear();
  53. s.rehash(bucket_count);
  54. InputFunction ifunc;
  55. while(count-- > 0){
  56. ifunc(ar, s, item_version);
  57. }
  58. }
  59. } // namespace stl
  60. } // namespace serialization
  61. } // namespace boost
  62. #endif //BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_LOAD_IMP_HPP