File indexing completed on 2025-01-18 09:30:52
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_FLYWEIGHT_DETAIL_ARCHIVE_CONSTRUCTED_HPP
0010 #define BOOST_FLYWEIGHT_DETAIL_ARCHIVE_CONSTRUCTED_HPP
0011
0012 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
0013 #pragma once
0014 #endif
0015
0016 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
0017 #include <boost/core/no_exceptions_support.hpp>
0018 #include <boost/noncopyable.hpp>
0019 #include <boost/core/serialization.hpp>
0020 #include <boost/type_traits/aligned_storage.hpp>
0021 #include <boost/type_traits/alignment_of.hpp>
0022
0023 namespace boost{
0024
0025 namespace flyweights{
0026
0027 namespace detail{
0028
0029
0030
0031 template<typename T>
0032 struct archive_constructed:private noncopyable
0033 {
0034 template<class Archive>
0035 archive_constructed(Archive& ar,const unsigned int version)
0036 {
0037 core::load_construct_data_adl(ar,&get(),version);
0038 BOOST_TRY{
0039 ar>>get();
0040 }
0041 BOOST_CATCH(...){
0042 (&get())->~T();
0043 BOOST_RETHROW;
0044 }
0045 BOOST_CATCH_END
0046 }
0047
0048 template<class Archive>
0049 archive_constructed(const char* name,Archive& ar,const unsigned int version)
0050 {
0051 core::load_construct_data_adl(ar,&get(),version);
0052 BOOST_TRY{
0053 ar>>serialization::make_nvp(name,get());
0054 }
0055 BOOST_CATCH(...){
0056 (&get())->~T();
0057 BOOST_RETHROW;
0058 }
0059 BOOST_CATCH_END
0060 }
0061
0062 ~archive_constructed()
0063 {
0064 (&get())->~T();
0065 }
0066
0067 T& get(){return *static_cast<T*>(static_cast<void*>(&space));}
0068
0069 private:
0070 typename aligned_storage<sizeof(T),alignment_of<T>::value>::type space;
0071 };
0072
0073 }
0074
0075 }
0076
0077 }
0078
0079 #endif