collections_save_imp.hpp 2.5 KB

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