valarray.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef BOOST_SERIALIZATION_VALARAY_HPP
  2. #define BOOST_SERIALIZATION_VALARAY_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. // 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/core/addressof.hpp>
  17. #include <boost/serialization/collections_save_imp.hpp>
  18. #include <boost/serialization/collections_load_imp.hpp>
  19. #include <boost/serialization/split_free.hpp>
  20. #include <boost/serialization/collection_size_type.hpp>
  21. #include <boost/serialization/array_wrapper.hpp>
  22. // function specializations must be defined in the appropriate
  23. // namespace - boost::serialization
  24. #if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
  25. #define STD _STLP_STD
  26. #else
  27. #define STD std
  28. #endif
  29. namespace boost {
  30. namespace serialization {
  31. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  32. // valarray< T >
  33. template<class Archive, class U>
  34. void save( Archive & ar, const STD::valarray<U> &t, const unsigned int /*file_version*/ )
  35. {
  36. const collection_size_type count(t.size());
  37. ar << BOOST_SERIALIZATION_NVP(count);
  38. if (t.size()){
  39. // explicit template arguments to pass intel C++ compiler
  40. ar << serialization::make_array<const U, collection_size_type>(
  41. static_cast<const U *>( boost::addressof(t[0]) ),
  42. count
  43. );
  44. }
  45. }
  46. template<class Archive, class U>
  47. void load( Archive & ar, STD::valarray<U> &t, const unsigned int /*file_version*/ )
  48. {
  49. collection_size_type count;
  50. ar >> BOOST_SERIALIZATION_NVP(count);
  51. t.resize(count);
  52. if (t.size()){
  53. // explicit template arguments to pass intel C++ compiler
  54. ar >> serialization::make_array<U, collection_size_type>(
  55. static_cast<U *>( boost::addressof(t[0]) ),
  56. count
  57. );
  58. }
  59. }
  60. // split non-intrusive serialization function member into separate
  61. // non intrusive save/load member functions
  62. template<class Archive, class U>
  63. inline void serialize( Archive & ar, STD::valarray<U> & t, const unsigned int file_version)
  64. {
  65. boost::serialization::split_free(ar, t, file_version);
  66. }
  67. } } // end namespace boost::serialization
  68. #include <boost/serialization/collection_traits.hpp>
  69. BOOST_SERIALIZATION_COLLECTION_TRAITS(STD::valarray)
  70. #undef STD
  71. #endif // BOOST_SERIALIZATION_VALARAY_HPP