1 | #ifndef BOOST_SERIALIZATION_UNIQUE_PTR_HPP |
2 | #define BOOST_SERIALIZATION_UNIQUE_PTR_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 | // unique_ptr.hpp: |
11 | |
12 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
13 | // Use, modification and distribution is subject to the Boost Software |
14 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
15 | // http://www.boost.org/LICENSE_1_0.txt) |
16 | |
17 | // See http://www.boost.org for updates, documentation, and revision history. |
18 | #include <memory> |
19 | #include <boost/serialization/split_free.hpp> |
20 | #include <boost/serialization/nvp.hpp> |
21 | |
22 | namespace boost { |
23 | namespace serialization { |
24 | |
25 | ///////////////////////////////////////////////////////////// |
26 | // implement serialization for unique_ptr< T > |
27 | // note: this must be added to the boost namespace in order to |
28 | // be called by the library |
29 | template<class Archive, class T> |
30 | inline void save( |
31 | Archive & ar, |
32 | const std::unique_ptr< T > &t, |
33 | const unsigned int file_version |
34 | ){ |
35 | // only the raw pointer has to be saved |
36 | // the ref count is rebuilt automatically on load |
37 | const T * const tx = t.get(); |
38 | ar << BOOST_SERIALIZATION_NVP(tx); |
39 | } |
40 | |
41 | template<class Archive, class T> |
42 | inline void load( |
43 | Archive & ar, |
44 | std::unique_ptr< T > &t, |
45 | const unsigned int file_version |
46 | ){ |
47 | T *tx; |
48 | ar >> BOOST_SERIALIZATION_NVP(tx); |
49 | // note that the reset automagically maintains the reference count |
50 | t.reset(tx); |
51 | } |
52 | |
53 | // split non-intrusive serialization function member into separate |
54 | // non intrusive save/load member functions |
55 | template<class Archive, class T> |
56 | inline void serialize( |
57 | Archive & ar, |
58 | std::unique_ptr< T > &t, |
59 | const unsigned int file_version |
60 | ){ |
61 | boost::serialization::split_free(ar, t, file_version); |
62 | } |
63 | |
64 | } // namespace serialization |
65 | } // namespace boost |
66 | |
67 | |
68 | #endif // BOOST_SERIALIZATION_UNIQUE_PTR_HPP |
69 | |