epoc32/include/stdapis/boost/multi_index/detail/archive_constructed.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
     1 /* Copyright 2003-2005 Joaquín M López Muñoz.
     2  * Distributed under the Boost Software License, Version 1.0.
     3  * (See accompanying file LICENSE_1_0.txt or copy at
     4  * http://www.boost.org/LICENSE_1_0.txt)
     5  *
     6  * See http://www.boost.org/libs/multi_index for library home page.
     7  */
     8 
     9 #ifndef BOOST_MULTI_INDEX_DETAIL_ARCHIVE_CONSTRUCTED_HPP
    10 #define BOOST_MULTI_INDEX_DETAIL_ARCHIVE_CONSTRUCTED_HPP
    11 
    12 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
    13 #pragma once
    14 #endif
    15 
    16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
    17 #include <boost/detail/no_exceptions_support.hpp>
    18 #include <boost/noncopyable.hpp>
    19 #include <boost/serialization/serialization.hpp>
    20 #include <boost/type_traits/aligned_storage.hpp>
    21 #include <boost/type_traits/alignment_of.hpp> 
    22 
    23 namespace boost{
    24 
    25 namespace multi_index{
    26 
    27 namespace detail{
    28 
    29 /* constructs a stack-based object from a serialization archive */
    30 
    31 template<typename T>
    32 struct archive_constructed:private noncopyable
    33 {
    34   template<class Archive>
    35   archive_constructed(Archive& ar,const unsigned int version)
    36   {
    37     serialization::load_construct_data_adl(ar,&get(),version);
    38     BOOST_TRY{
    39       ar>>get();
    40     }
    41     BOOST_CATCH(...){
    42       (&get())->~T();
    43       BOOST_RETHROW;
    44     }
    45     BOOST_CATCH_END
    46   }
    47 
    48   template<class Archive>
    49   archive_constructed(const char* name,Archive& ar,const unsigned int version)
    50   {
    51     serialization::load_construct_data_adl(ar,&get(),version);
    52     BOOST_TRY{
    53       ar>>serialization::make_nvp(name,get());
    54     }
    55     BOOST_CATCH(...){
    56       (&get())->~T();
    57       BOOST_RETHROW;
    58     }
    59     BOOST_CATCH_END
    60   }
    61 
    62   ~archive_constructed()
    63   {
    64     (&get())->~T();
    65   }
    66 
    67   T& get(){return *static_cast<T*>(static_cast<void*>(&space));}
    68 
    69 private:
    70   typename aligned_storage<sizeof(T),alignment_of<T>::value>::type space;
    71 };
    72 
    73 } /* namespace multi_index::detail */
    74 
    75 } /* namespace multi_index */
    76 
    77 } /* namespace boost */
    78 
    79 #endif