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)
  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/collection_size_type.hpp>
  19. #include <boost/serialization/item_version_type.hpp>
  20. #include <boost/serialization/library_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. collection_size_type count;
  31. collection_size_type bucket_count;
  32. boost::serialization::item_version_type item_version(0);
  33. boost::serialization::library_version_type library_version(
  34. ar.get_library_version()
  35. );
  36. // retrieve number of elements
  37. if(boost::serialization::library_version_type(6) != library_version){
  38. ar >> BOOST_SERIALIZATION_NVP(count);
  39. ar >> BOOST_SERIALIZATION_NVP(bucket_count);
  40. }
  41. else{
  42. // note: fixup for error in version 6. collection size was
  43. // changed to size_t BUT for hashed collections it was implemented
  44. // as an unsigned int. This should be a problem only on win64 machines
  45. // but I'll leave it for everyone just in case.
  46. unsigned int c;
  47. unsigned int bc;
  48. ar >> BOOST_SERIALIZATION_NVP(c);
  49. count = c;
  50. ar >> BOOST_SERIALIZATION_NVP(bc);
  51. bucket_count = bc;
  52. }
  53. if(boost::serialization::library_version_type(3) < library_version){
  54. ar >> BOOST_SERIALIZATION_NVP(item_version);
  55. }
  56. s.clear();
  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