collections_save_imp.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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) && (_MSC_VER >= 1020)
  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/serialization/nvp.hpp>
  17. #include <boost/serialization/serialization.hpp>
  18. #include <boost/serialization/version.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>
  28. inline void save_collection(Archive & ar, const Container &s)
  29. {
  30. // record number of elements
  31. collection_size_type count(s.size());
  32. const item_version_type item_version(
  33. version<BOOST_DEDUCED_TYPENAME Container::value_type>::value
  34. );
  35. ar << BOOST_SERIALIZATION_NVP(count);
  36. #if 0
  37. boost::archive::library_version_type library_version(
  38. ar.get_library_version()
  39. );
  40. if(boost::archive::library_version_type(3) < library_version){
  41. ar << BOOST_SERIALIZATION_NVP(item_version);
  42. }
  43. #else
  44. ar << BOOST_SERIALIZATION_NVP(item_version);
  45. #endif
  46. BOOST_DEDUCED_TYPENAME Container::const_iterator it = s.begin();
  47. while(count-- > 0){
  48. // note borland emits a no-op without the explicit namespace
  49. boost::serialization::save_construct_data_adl(
  50. ar,
  51. &(*it),
  52. item_version
  53. );
  54. ar << boost::serialization::make_nvp("item", *it++);
  55. }
  56. }
  57. } // namespace stl
  58. } // namespace serialization
  59. } // namespace boost
  60. #endif //BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP