source: NonGTP/Boost/boost/serialization/detail/stack_constructor.hpp @ 857

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