| 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 | |
|---|
| 25 | namespace boost{ |
|---|
| 26 | namespace serialization { |
|---|
| 27 | namespace detail { |
|---|
| 28 | |
|---|
| 29 | // reserve space on stack for an object of type T without actually |
|---|
| 30 | // construction such an object |
|---|
| 31 | template<typename T > |
|---|
| 32 | struct stack_allocate |
|---|
| 33 | { |
|---|
| 34 | T * address() { |
|---|
| 35 | return static_cast<T*>(storage_.address()); |
|---|
| 36 | } |
|---|
| 37 | T & reference() { |
|---|
| 38 | return * address(); |
|---|
| 39 | } |
|---|
| 40 | private: |
|---|
| 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 |
|---|
| 53 | template<class Archive, class T> |
|---|
| 54 | struct stack_construct : public stack_allocate<T> |
|---|
| 55 | { |
|---|
| 56 | stack_construct(Archive & ar, const unsigned int version){ |
|---|
| 57 | // note borland emits a no-op without the explicit namespace |
|---|
| 58 | boost::serialization::load_construct_data_adl( |
|---|
| 59 | ar, |
|---|
| 60 | this->address(), |
|---|
| 61 | version |
|---|
| 62 | ); |
|---|
| 63 | } |
|---|
| 64 | ~stack_construct(){ |
|---|
| 65 | this->address()->~T(); // undo load_construct_data above |
|---|
| 66 | } |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | } // detail |
|---|
| 70 | } // serializaition |
|---|
| 71 | } // boost |
|---|
| 72 | |
|---|
| 73 | #endif // BOOST_SERIALIZATION_DETAIL_STACH_CONSTRUCTOR_HPP |
|---|