Chris@16
|
1 #ifndef BOOST_SERIALIZATION_DETAIL_STACH_CONSTRUCTOR_HPP
|
Chris@16
|
2 #define BOOST_SERIALIZATION_DETAIL_STACH_CONSTRUCTOR_HPP
|
Chris@16
|
3
|
Chris@16
|
4 // MS compatible compilers support #pragma once
|
Chris@101
|
5 #if defined(_MSC_VER)
|
Chris@16
|
6 # pragma once
|
Chris@16
|
7 #endif
|
Chris@16
|
8
|
Chris@16
|
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
Chris@101
|
10 // stack_constructor.hpp: serialization for loading stl collections
|
Chris@16
|
11
|
Chris@16
|
12 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
Chris@16
|
13 // Use, modification and distribution is subject to the Boost Software
|
Chris@16
|
14 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
15 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
16
|
Chris@16
|
17 // See http://www.boost.org for updates, documentation, and revision history.
|
Chris@16
|
18
|
Chris@16
|
19 #include <boost/aligned_storage.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 namespace boost{
|
Chris@16
|
22 namespace serialization {
|
Chris@16
|
23 namespace detail {
|
Chris@16
|
24
|
Chris@16
|
25 // reserve space on stack for an object of type T without actually
|
Chris@16
|
26 // construction such an object
|
Chris@16
|
27 template<typename T >
|
Chris@16
|
28 struct stack_allocate
|
Chris@16
|
29 {
|
Chris@16
|
30 T * address() {
|
Chris@16
|
31 return static_cast<T*>(storage_.address());
|
Chris@16
|
32 }
|
Chris@16
|
33 T & reference() {
|
Chris@16
|
34 return * address();
|
Chris@16
|
35 }
|
Chris@16
|
36 private:
|
Chris@101
|
37 typedef typename boost::aligned_storage<
|
Chris@16
|
38 sizeof(T),
|
Chris@16
|
39 #if BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x560))
|
Chris@16
|
40 8
|
Chris@16
|
41 #else
|
Chris@16
|
42 boost::alignment_of<T>::value
|
Chris@16
|
43 #endif
|
Chris@16
|
44 > type;
|
Chris@16
|
45 type storage_;
|
Chris@16
|
46 };
|
Chris@16
|
47
|
Chris@16
|
48 // construct element on the stack
|
Chris@16
|
49 template<class Archive, class T>
|
Chris@16
|
50 struct stack_construct : public stack_allocate<T>
|
Chris@16
|
51 {
|
Chris@16
|
52 stack_construct(Archive & ar, const unsigned int version){
|
Chris@16
|
53 // note borland emits a no-op without the explicit namespace
|
Chris@16
|
54 boost::serialization::load_construct_data_adl(
|
Chris@16
|
55 ar,
|
Chris@16
|
56 this->address(),
|
Chris@16
|
57 version
|
Chris@16
|
58 );
|
Chris@16
|
59 }
|
Chris@16
|
60 ~stack_construct(){
|
Chris@16
|
61 this->address()->~T(); // undo load_construct_data above
|
Chris@16
|
62 }
|
Chris@16
|
63 };
|
Chris@16
|
64
|
Chris@16
|
65 } // detail
|
Chris@16
|
66 } // serializaition
|
Chris@16
|
67 } // boost
|
Chris@16
|
68
|
Chris@16
|
69 #endif // BOOST_SERIALIZATION_DETAIL_STACH_CONSTRUCTOR_HPP
|