hash_collections_load_imp.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef BOOST_SERIALIZATION_HASH_COLLECTIONS_LOAD_IMP_HPP
  2. #define BOOST_SERIALIZATION_HASH_COLLECTIONS_LOAD_IMP_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER)
  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. // hash_collections_load_imp.hpp: serialization for loading stl collections
  10. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  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 hashed collections
  16. #include <boost/config.hpp>
  17. #include <boost/serialization/nvp.hpp>
  18. #include <boost/serialization/library_version_type.hpp>
  19. namespace boost{
  20. namespace serialization {
  21. namespace stl {
  22. //////////////////////////////////////////////////////////////////////
  23. // implementation of serialization for STL containers
  24. //
  25. template<class Archive, class Container, class InputFunction>
  26. inline void load_hash_collection(Archive & ar, Container &s)
  27. {
  28. collection_size_type count;
  29. collection_size_type bucket_count;
  30. boost::serialization::item_version_type item_version(0);
  31. boost::serialization::library_version_type library_version(
  32. ar.get_library_version()
  33. );
  34. // retrieve number of elements
  35. if(boost::serialization::library_version_type(6) != library_version){
  36. ar >> BOOST_SERIALIZATION_NVP(count);
  37. ar >> BOOST_SERIALIZATION_NVP(bucket_count);
  38. }
  39. else{
  40. // note: fixup for error in version 6. collection size was
  41. // changed to size_t BUT for hashed collections it was implemented
  42. // as an unsigned int. This should be a problem only on win64 machines
  43. // but I'll leave it for everyone just in case.
  44. unsigned int c;
  45. unsigned int bc;
  46. ar >> BOOST_SERIALIZATION_NVP(c);
  47. count = c;
  48. ar >> BOOST_SERIALIZATION_NVP(bc);
  49. bucket_count = bc;
  50. }
  51. if(boost::serialization::library_version_type(3) < library_version){
  52. ar >> BOOST_SERIALIZATION_NVP(item_version);
  53. }
  54. s.clear();
  55. #if ! defined(__MWERKS__)
  56. s.resize(bucket_count);
  57. #endif
  58. InputFunction ifunc;
  59. while(count-- > 0){
  60. ifunc(ar, s, item_version);
  61. }
  62. }
  63. } // namespace stl
  64. } // namespace serialization
  65. } // namespace boost
  66. #endif //BOOST_SERIALIZATION_HASH_COLLECTIONS_LOAD_IMP_HPP