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) 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 21 namespace boost{ 22 namespace serialization { 23 namespace detail { 24 25 // reserve space on stack for an object of type T without actually 26 // construction such an object 27 template<typename T > 28 struct stack_allocate 29 { addressboost::serialization::detail::stack_allocate30 T * address() { 31 return static_cast<T*>(storage_.address()); 32 } referenceboost::serialization::detail::stack_allocate33 T & reference() { 34 return * address(); 35 } 36 private: 37 typedef typename boost::aligned_storage< 38 sizeof(T), 39 boost::alignment_of<T>::value 40 > type; 41 type storage_; 42 }; 43 44 // construct element on the stack 45 template<class Archive, class T> 46 struct stack_construct : public stack_allocate<T> 47 { stack_constructboost::serialization::detail::stack_construct48 stack_construct(Archive & ar, const unsigned int version){ 49 // note borland emits a no-op without the explicit namespace 50 boost::serialization::load_construct_data_adl( 51 ar, 52 this->address(), 53 version 54 ); 55 } ~stack_constructboost::serialization::detail::stack_construct56 ~stack_construct(){ 57 this->address()->~T(); // undo load_construct_data above 58 } 59 }; 60 61 } // detail 62 } // serializaition 63 } // boost 64 65 #endif // BOOST_SERIALIZATION_DETAIL_STACH_CONSTRUCTOR_HPP 66