]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
1 | #ifndef BOOST_SERIALIZATION_DETAIL_STACK_CONSTRUCTOR_HPP |
2 | #define BOOST_SERIALIZATION_DETAIL_STACK_CONSTRUCTOR_HPP | |
7c673cae FG |
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 | // stack_constructor.hpp: serialization for loading stl collections | |
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 | ||
19 | #include <boost/aligned_storage.hpp> | |
20 | #include <boost/serialization/serialization.hpp> | |
21 | ||
22 | namespace boost{ | |
23 | namespace serialization { | |
24 | namespace detail { | |
25 | ||
26 | // reserve space on stack for an object of type T without actually | |
27 | // construction such an object | |
28 | template<typename T > | |
29 | struct stack_allocate | |
30 | { | |
31 | T * address() { | |
32 | return static_cast<T*>(storage_.address()); | |
33 | } | |
34 | T & reference() { | |
35 | return * address(); | |
36 | } | |
37 | private: | |
38 | typedef typename boost::aligned_storage< | |
39 | sizeof(T), | |
40 | boost::alignment_of<T>::value | |
41 | > type; | |
42 | type storage_; | |
43 | }; | |
44 | ||
45 | // construct element on the stack | |
46 | template<class Archive, class T> | |
47 | struct stack_construct : public stack_allocate<T> | |
48 | { | |
49 | stack_construct(Archive & ar, const unsigned int version){ | |
50 | // note borland emits a no-op without the explicit namespace | |
51 | boost::serialization::load_construct_data_adl( | |
52 | ar, | |
53 | this->address(), | |
54 | version | |
55 | ); | |
56 | } | |
57 | ~stack_construct(){ | |
58 | this->address()->~T(); // undo load_construct_data above | |
59 | } | |
60 | }; | |
61 | ||
62 | } // detail | |
63 | } // serializaition | |
64 | } // boost | |
65 | ||
66 | #endif // BOOST_SERIALIZATION_DETAIL_STACH_CONSTRUCTOR_HPP |