1 | /* Copyright 2003-2005 Joaquín M López Muñoz. |
---|
2 | * Distributed under the Boost Software License, Version 1.0. |
---|
3 | * (See accompanying file LICENSE_1_0.txt or copy at |
---|
4 | * http://www.boost.org/LICENSE_1_0.txt) |
---|
5 | * |
---|
6 | * See http://www.boost.org/libs/multi_index for library home page. |
---|
7 | */ |
---|
8 | |
---|
9 | #ifndef BOOST_MULTI_INDEX_DETAIL_ARCHIVE_CONSTRUCTED_HPP |
---|
10 | #define BOOST_MULTI_INDEX_DETAIL_ARCHIVE_CONSTRUCTED_HPP |
---|
11 | |
---|
12 | #if defined(_MSC_VER)&&(_MSC_VER>=1200) |
---|
13 | #pragma once |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ |
---|
17 | #include <boost/aligned_storage.hpp> |
---|
18 | #include <boost/detail/no_exceptions_support.hpp> |
---|
19 | #include <boost/noncopyable.hpp> |
---|
20 | #include <boost/serialization/serialization.hpp> |
---|
21 | |
---|
22 | namespace boost{ |
---|
23 | |
---|
24 | namespace multi_index{ |
---|
25 | |
---|
26 | namespace detail{ |
---|
27 | |
---|
28 | /* constructs a stack-based object from a serialization archive */ |
---|
29 | |
---|
30 | template<typename T> |
---|
31 | struct archive_constructed:private noncopyable |
---|
32 | { |
---|
33 | template<class Archive> |
---|
34 | archive_constructed(Archive& ar,const unsigned int version) |
---|
35 | { |
---|
36 | serialization::load_construct_data_adl(ar,&get(),version); |
---|
37 | BOOST_TRY{ |
---|
38 | ar>>get(); |
---|
39 | } |
---|
40 | BOOST_CATCH(...){ |
---|
41 | (&get())->~T(); |
---|
42 | BOOST_RETHROW; |
---|
43 | } |
---|
44 | BOOST_CATCH_END |
---|
45 | } |
---|
46 | |
---|
47 | template<class Archive> |
---|
48 | archive_constructed(const char* name,Archive& ar,const unsigned int version) |
---|
49 | { |
---|
50 | serialization::load_construct_data_adl(ar,&get(),version); |
---|
51 | BOOST_TRY{ |
---|
52 | ar>>serialization::make_nvp(name,get()); |
---|
53 | } |
---|
54 | BOOST_CATCH(...){ |
---|
55 | (&get())->~T(); |
---|
56 | BOOST_RETHROW; |
---|
57 | } |
---|
58 | BOOST_CATCH_END |
---|
59 | } |
---|
60 | |
---|
61 | ~archive_constructed() |
---|
62 | { |
---|
63 | (&get())->~T(); |
---|
64 | } |
---|
65 | |
---|
66 | T& get(){return *static_cast<T*>(space.address());} |
---|
67 | |
---|
68 | private: |
---|
69 | aligned_storage<sizeof(T)> space; |
---|
70 | }; |
---|
71 | |
---|
72 | } /* namespace multi_index::detail */ |
---|
73 | |
---|
74 | } /* namespace multi_index */ |
---|
75 | |
---|
76 | } /* namespace boost */ |
---|
77 | |
---|
78 | #endif |
---|