collections_save_imp.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP
  2. #define BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // 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/core/addressof.hpp>
  17. #include <boost/serialization/nvp.hpp>
  18. #include <boost/serialization/serialization.hpp>
  19. #include <boost/serialization/version.hpp>
  20. #include <boost/serialization/collection_size_type.hpp>
  21. #include <boost/serialization/item_version_type.hpp>
  22. namespace boost{
  23. namespace serialization {
  24. namespace stl {
  25. //////////////////////////////////////////////////////////////////////
  26. // implementation of serialization for STL containers
  27. //
  28. template<class Archive, class Container>
  29. inline void save_collection(
  30. Archive & ar,
  31. const Container &s,
  32. collection_size_type count)
  33. {
  34. ar << BOOST_SERIALIZATION_NVP(count);
  35. // record number of elements
  36. const item_version_type item_version(
  37. version<typename Container::value_type>::value
  38. );
  39. ar << BOOST_SERIALIZATION_NVP(item_version);
  40. typename Container::const_iterator it = s.begin();
  41. while(count-- > 0){
  42. // note borland emits a no-op without the explicit namespace
  43. boost::serialization::save_construct_data_adl(
  44. ar,
  45. boost::addressof(*it),
  46. item_version
  47. );
  48. ar << boost::serialization::make_nvp("item", *it++);
  49. }
  50. }
  51. template<class Archive, class Container>
  52. inline void save_collection(Archive & ar, const Container &s)
  53. {
  54. // record number of elements
  55. collection_size_type count(s.size());
  56. save_collection(ar, s, count);
  57. }
  58. } // namespace stl
  59. } // namespace serialization
  60. } // namespace boost
  61. #endif //BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP