valarray.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef BOOST_SERIALIZATION_VALARAY_HPP
  2. #define BOOST_SERIALIZATION_VALARAY_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. // valarray.hpp: serialization for stl vector templates
  9. // (C) Copyright 2005 Matthias Troyer .
  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. #include <valarray>
  15. #include <boost/config.hpp>
  16. #include <boost/serialization/split_free.hpp>
  17. #include <boost/serialization/array.hpp>
  18. #include <boost/serialization/collection_size_type.hpp>
  19. #include <boost/serialization/detail/get_data.hpp>
  20. // function specializations must be defined in the appropriate
  21. // namespace - boost::serialization
  22. #if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
  23. #define STD _STLP_STD
  24. #else
  25. #define STD std
  26. #endif
  27. namespace boost { namespace serialization {
  28. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  29. // valarray<T>
  30. template<class Archive, class U>
  31. void save( Archive & ar, const STD::valarray<U> &t, const unsigned int /*file_version*/ )
  32. {
  33. const collection_size_type count(t.size());
  34. ar << BOOST_SERIALIZATION_NVP(count);
  35. if (t.size())
  36. ar << make_array(detail::get_data(t), t.size());
  37. }
  38. template<class Archive, class U>
  39. void load( Archive & ar, STD::valarray<U> &t, const unsigned int /*file_version*/ )
  40. {
  41. collection_size_type count;
  42. ar >> BOOST_SERIALIZATION_NVP(count);
  43. t.resize(count);
  44. if (t.size())
  45. ar >> make_array(detail::get_data(t), t.size());
  46. }
  47. // split non-intrusive serialization function member into separate
  48. // non intrusive save/load member functions
  49. template<class Archive, class U>
  50. inline void serialize( Archive & ar, STD::valarray<U> & t, const unsigned int file_version)
  51. {
  52. boost::serialization::split_free(ar, t, file_version);
  53. }
  54. } } // end namespace boost::serialization
  55. #include <boost/serialization/collection_traits.hpp>
  56. BOOST_SERIALIZATION_COLLECTION_TRAITS(STD::valarray)
  57. #undef STD
  58. #endif // BOOST_SERIALIZATION_VALARAY_HPP