hash_collections_save_imp.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef BOOST_SERIALIZATION_HASH_COLLECTIONS_SAVE_IMP_HPP
  2. #define BOOST_SERIALIZATION_HASH_COLLECTIONS_SAVE_IMP_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // hash_collections_save_imp.hpp: serialization for stl collections
  9. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  10. // Use, modification and distribution is subject to the Boost Software
  11. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. // See http://www.boost.org for updates, documentation, and revision history.
  14. // helper function templates for serialization of collections
  15. #include <boost/config.hpp>
  16. #include <boost/serialization/nvp.hpp>
  17. #include <boost/serialization/serialization.hpp>
  18. #include <boost/serialization/version.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>
  26. inline void save_hash_collection(Archive & ar, const Container &s)
  27. {
  28. // record number of elements
  29. unsigned int count = s.size();
  30. ar << BOOST_SERIALIZATION_NVP(count);
  31. // make sure the target type is registered so we can retrieve
  32. // the version when we load
  33. if(3 < ar.get_library_version()){
  34. const unsigned int bucket_count = s.bucket_count();
  35. ar << BOOST_SERIALIZATION_NVP(bucket_count);
  36. const unsigned int item_version = version<BOOST_DEDUCED_TYPENAME Container::value_type>::value;
  37. ar << BOOST_SERIALIZATION_NVP(item_version);
  38. }
  39. BOOST_DEDUCED_TYPENAME Container::const_iterator it = s.begin();
  40. while(count-- > 0){
  41. // note borland emits a no-op without the explicit namespace
  42. boost::serialization::save_construct_data_adl(
  43. ar,
  44. &(*it),
  45. boost::serialization::version<
  46. BOOST_DEDUCED_TYPENAME Container::value_type
  47. >::value
  48. );
  49. ar << boost::serialization::make_nvp("item", *it++);
  50. }
  51. }
  52. } // namespace stl
  53. } // namespace serialization
  54. } // namespace boost
  55. #endif //BOOST_SERIALIZATION_HASH_COLLECTIONS_SAVE_IMP_HPP