Brian Silverman | 8867871 | 2018-08-04 23:56:48 -0700 | [diff] [blame^] | 1 | #ifndef BOOST_SERIALIZATION_COMPLEX_HPP |
| 2 | #define BOOST_SERIALIZATION_COMPLEX_HPP |
| 3 | |
| 4 | // MS compatible compilers support #pragma once |
| 5 | #if defined(_MSC_VER) |
| 6 | # pragma once |
| 7 | #endif |
| 8 | |
| 9 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
| 10 | // serialization/utility.hpp: |
| 11 | // serialization for stl utility templates |
| 12 | |
| 13 | // (C) Copyright 2007 Matthias Troyer . |
| 14 | // Use, modification and distribution is subject to the Boost Software |
| 15 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 16 | // http://www.boost.org/LICENSE_1_0.txt) |
| 17 | |
| 18 | // See http://www.boost.org for updates, documentation, and revision history. |
| 19 | |
| 20 | #include <complex> |
| 21 | #include <boost/config.hpp> |
| 22 | |
| 23 | #include <boost/serialization/nvp.hpp> |
| 24 | #include <boost/serialization/is_bitwise_serializable.hpp> |
| 25 | #include <boost/serialization/split_free.hpp> |
| 26 | |
| 27 | namespace boost { |
| 28 | namespace serialization { |
| 29 | |
| 30 | template<class Archive, class T> |
| 31 | inline void serialize( |
| 32 | Archive & ar, |
| 33 | std::complex< T > & t, |
| 34 | const unsigned int file_version |
| 35 | ){ |
| 36 | boost::serialization::split_free(ar, t, file_version); |
| 37 | } |
| 38 | |
| 39 | template<class Archive, class T> |
| 40 | inline void save( |
| 41 | Archive & ar, |
| 42 | std::complex< T > const & t, |
| 43 | const unsigned int /* file_version */ |
| 44 | ){ |
| 45 | const T re = t.real(); |
| 46 | const T im = t.imag(); |
| 47 | ar << boost::serialization::make_nvp("real", re); |
| 48 | ar << boost::serialization::make_nvp("imag", im); |
| 49 | } |
| 50 | |
| 51 | template<class Archive, class T> |
| 52 | inline void load( |
| 53 | Archive & ar, |
| 54 | std::complex< T >& t, |
| 55 | const unsigned int /* file_version */ |
| 56 | ){ |
| 57 | T re; |
| 58 | T im; |
| 59 | ar >> boost::serialization::make_nvp("real", re); |
| 60 | ar >> boost::serialization::make_nvp("imag", im); |
| 61 | t = std::complex< T >(re,im); |
| 62 | } |
| 63 | |
| 64 | // specialization of serialization traits for complex |
| 65 | template <class T> |
| 66 | struct is_bitwise_serializable<std::complex< T > > |
| 67 | : public is_bitwise_serializable< T > {}; |
| 68 | |
| 69 | template <class T> |
| 70 | struct implementation_level<std::complex< T > > |
| 71 | : mpl::int_<object_serializable> {} ; |
| 72 | |
| 73 | // treat complex just like builtin arithmetic types for tracking |
| 74 | template <class T> |
| 75 | struct tracking_level<std::complex< T > > |
| 76 | : mpl::int_<track_never> {} ; |
| 77 | |
| 78 | } // serialization |
| 79 | } // namespace boost |
| 80 | |
| 81 | #endif // BOOST_SERIALIZATION_COMPLEX_HPP |