unordered_collections_load_imp.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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/serialization/access.hpp>
  27. #include <boost/serialization/nvp.hpp>
  28. #include <boost/serialization/collection_size_type.hpp>
  29. #include <boost/serialization/item_version_type.hpp>
  30. #include <boost/serialization/library_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::serialization::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::serialization::library_version_type(3) < library_version){
  50. ar >> BOOST_SERIALIZATION_NVP(item_version);
  51. }
  52. s.clear();
  53. // rehash() will pre-allocate the appropriate number of buckets
  54. // given the number of items to be inserted. Therefore it is
  55. // unneccesary to use bucket_count here, especially when bucket_count
  56. // may be much larger than what is neccessary for 'count' items.
  57. //
  58. s.rehash(count);
  59. InputFunction ifunc;
  60. while(count-- > 0){
  61. ifunc(ar, s, item_version);
  62. }
  63. }
  64. } // namespace stl
  65. } // namespace serialization
  66. } // namespace boost
  67. #endif //BOOST_SERIALIZATION_UNORDERED_COLLECTIONS_LOAD_IMP_HPP