hash_collections_load_imp.hpp 2.7 KB

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