collections_save_imp.hpp 2.5 KB

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