complex.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef BOOST_SERIALIZATION_COMPLEX_HPP
  2. #define BOOST_SERIALIZATION_COMPLEX_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. // serialization/utility.hpp:
  9. // serialization for stl utility templates
  10. // (C) Copyright 2007 Matthias Troyer .
  11. // Use, modification and distribution is subject to the Boost Software
  12. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. // See http://www.boost.org for updates, documentation, and revision history.
  15. #include <complex>
  16. #include <boost/config.hpp>
  17. #include <boost/serialization/nvp.hpp>
  18. #include <boost/serialization/is_bitwise_serializable.hpp>
  19. #include <boost/serialization/split_free.hpp>
  20. namespace boost {
  21. namespace serialization {
  22. template<class Archive, class T>
  23. inline void serialize(
  24. Archive & ar,
  25. std::complex< T > & t,
  26. const unsigned int file_version
  27. ){
  28. boost::serialization::split_free(ar, t, file_version);
  29. }
  30. template<class Archive, class T>
  31. inline void save(
  32. Archive & ar,
  33. std::complex< T > const & t,
  34. const unsigned int /* file_version */
  35. ){
  36. const T re = t.real();
  37. const T im = t.imag();
  38. ar << boost::serialization::make_nvp("real", re);
  39. ar << boost::serialization::make_nvp("imag", im);
  40. }
  41. template<class Archive, class T>
  42. inline void load(
  43. Archive & ar,
  44. std::complex< T >& t,
  45. const unsigned int /* file_version */
  46. ){
  47. T re;
  48. T im;
  49. ar >> boost::serialization::make_nvp("real", re);
  50. ar >> boost::serialization::make_nvp("imag", im);
  51. t = std::complex< T >(re,im);
  52. }
  53. // specialization of serialization traits for complex
  54. template <class T>
  55. struct is_bitwise_serializable<std::complex< T > >
  56. : public is_bitwise_serializable< T > {};
  57. template <class T>
  58. struct implementation_level<std::complex< T > >
  59. : mpl::int_<object_serializable> {} ;
  60. // treat complex just like builtin arithmetic types for tracking
  61. template <class T>
  62. struct tracking_level<std::complex< T > >
  63. : mpl::int_<track_never> {} ;
  64. } // serialization
  65. } // namespace boost
  66. #endif // BOOST_SERIALIZATION_COMPLEX_HPP