![]() |
QxOrm
1.4.3
C++ Object Relational Mapping library
|
00001 /**************************************************************************** 00002 ** 00003 ** http://www.qxorm.com/ 00004 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com) 00005 ** 00006 ** This file is part of the QxOrm library 00007 ** 00008 ** This software is provided 'as-is', without any express or implied 00009 ** warranty. In no event will the authors be held liable for any 00010 ** damages arising from the use of this software 00011 ** 00012 ** Commercial Usage 00013 ** Licensees holding valid commercial QxOrm licenses may use this file in 00014 ** accordance with the commercial license agreement provided with the 00015 ** Software or, alternatively, in accordance with the terms contained in 00016 ** a written agreement between you and Lionel Marty 00017 ** 00018 ** GNU General Public License Usage 00019 ** Alternatively, this file may be used under the terms of the GNU 00020 ** General Public License version 3.0 as published by the Free Software 00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the 00022 ** packaging of this file. Please review the following information to 00023 ** ensure the GNU General Public License version 3.0 requirements will be 00024 ** met : http://www.gnu.org/copyleft/gpl.html 00025 ** 00026 ** If you are unsure which license is appropriate for your use, or 00027 ** if you have questions regarding the use of this file, please contact : 00028 ** contact@qxorm.com 00029 ** 00030 ****************************************************************************/ 00031 00032 #ifdef _QX_ENABLE_BOOST_SERIALIZATION 00033 #ifndef _QX_BOOST_SERIALIZATION_EXPORT_HPP_ 00034 #define _QX_BOOST_SERIALIZATION_EXPORT_HPP_ 00035 00036 #ifdef _MSC_VER 00037 #pragma once 00038 #endif 00039 00040 #include <QxCommon/QxConfig.h> 00041 00042 #if _QX_USE_MODIFY_BOOST_SERIALIZATION_EXPORT_HPP 00043 00044 #include <utility> 00045 #include <cstddef> // NULL 00046 00047 #include <boost/config.hpp> 00048 #include <boost/static_assert.hpp> 00049 #include <boost/preprocessor/stringize.hpp> 00050 #include <boost/type_traits/is_polymorphic.hpp> 00051 00052 #ifndef BOOST_SERIALIZATION_DEFAULT_TYPE_INFO 00053 #include <boost/serialization/extended_type_info_typeid.hpp> 00054 #endif // BOOST_SERIALIZATION_DEFAULT_TYPE_INFO 00055 00056 #include <boost/serialization/static_warning.hpp> 00057 #include <boost/serialization/type_info_implementation.hpp> 00058 #include <boost/serialization/assume_abstract.hpp> 00059 #include <boost/serialization/force_include.hpp> 00060 #include <boost/serialization/singleton.hpp> 00061 00062 #include <boost/archive/detail/register_archive.hpp> 00063 #include <boost/mpl/assert.hpp> 00064 #include <boost/mpl/and.hpp> 00065 #include <boost/mpl/not.hpp> 00066 #include <boost/mpl/bool.hpp> 00067 00068 #include <iostream> 00069 00070 namespace boost { 00071 namespace archive { 00072 namespace detail { 00073 00074 class basic_pointer_iserializer; 00075 class basic_pointer_oserializer; 00076 00077 template<class Archive, class T> 00078 class pointer_iserializer; 00079 template<class Archive, class T> 00080 class pointer_oserializer; 00081 00082 template <class Archive, class Serializable> 00083 struct export_impl 00084 { 00085 static const basic_pointer_iserializer & 00086 enable_load(mpl::true_){ 00087 return boost::serialization::singleton< 00088 pointer_iserializer<Archive, Serializable> 00089 >::get_const_instance(); 00090 } 00091 00092 static const basic_pointer_oserializer & 00093 enable_save(mpl::true_){ 00094 return boost::serialization::singleton< 00095 pointer_oserializer<Archive, Serializable> 00096 >::get_const_instance(); 00097 } 00098 inline static void enable_load(mpl::false_) {} 00099 inline static void enable_save(mpl::false_) {} 00100 }; 00101 00102 // On many platforms, naming a specialization of this template is 00103 // enough to cause its argument to be instantiated. 00104 template <void(*)()> 00105 struct instantiate_function {}; 00106 00107 template <class Archive, class Serializable> 00108 struct ptr_serialization_support 00109 { 00110 # if defined(BOOST_MSVC) 00111 virtual BOOST_DLLEXPORT void instantiate() BOOST_USED; 00112 # elif defined(__BORLANDC__) 00113 static BOOST_DLLEXPORT void instantiate() BOOST_USED; 00114 enum { x = sizeof(instantiate(),3) }; 00115 # else 00116 static BOOST_DLLEXPORT void instantiate() BOOST_USED; 00117 typedef instantiate_function< 00118 &ptr_serialization_support::instantiate 00119 > x; 00120 # endif 00121 }; 00122 00123 template <class Archive, class Serializable> 00124 BOOST_DLLEXPORT void 00125 ptr_serialization_support<Archive,Serializable>::instantiate() 00126 { 00127 export_impl<Archive,Serializable>::enable_save( 00128 #if ! defined(__BORLANDC__) 00129 BOOST_DEDUCED_TYPENAME 00130 #endif 00131 Archive::is_saving() 00132 ); 00133 00134 export_impl<Archive,Serializable>::enable_load( 00135 #if ! defined(__BORLANDC__) 00136 BOOST_DEDUCED_TYPENAME 00137 #endif 00138 Archive::is_loading() 00139 ); 00140 } 00141 00142 template<class T> 00143 struct guid_initializer 00144 { 00145 const guid_initializer & export_guid(char const* /* key */, mpl::false_){ 00146 // generates the statically-initialized objects whose constructors 00147 // register the information allowing serialization of T objects 00148 // through pointers to their base classes. 00149 instantiate_ptr_serialization((T*)0, 0, adl_tag()); 00150 return *this; 00151 } 00152 const guid_initializer & export_guid(char const* /*key*/, mpl::true_){ 00153 return *this; 00154 } 00155 const guid_initializer & export_guid(char const* key){ 00156 BOOST_STATIC_WARNING(boost::is_polymorphic<T>::value); 00157 assert(NULL != key); 00158 boost::serialization::singleton< 00159 BOOST_DEDUCED_TYPENAME 00160 boost::serialization::type_info_implementation<T>::type 00161 >::get_mutable_instance().key_register(key); 00162 // note: exporting an abstract base class will have no effect 00163 // and cannot be used to instantitiate serialization code 00164 // (one might be using this in a DLL to instantiate code) 00165 //BOOST_STATIC_WARNING(! boost::serialization::is_abstract<T>::value); 00166 return export_guid(key, boost::serialization::is_abstract<T>()); 00167 } 00168 }; 00169 00170 } // namespace detail 00171 } // namespace archive 00172 } // namespace boost 00173 00174 #define BOOST_CLASS_EXPORT_GUID(T, K) \ 00175 namespace \ 00176 { \ 00177 ::boost::archive::detail::guid_initializer< T > const & \ 00178 boost_serialization_guid_initializer_##T \ 00179 = ::boost::serialization::singleton< \ 00180 ::boost::archive::detail::guid_initializer< T > \ 00181 >::get_mutable_instance().export_guid(K); \ 00182 } 00183 00184 // check for unnecessary export. T isn't polymorphic so there is no 00185 // need to export it. 00186 #define BOOST_CLASS_EXPORT_CHECK(T) \ 00187 BOOST_STATIC_WARNING( \ 00188 boost::is_polymorphic<U>::value \ 00189 ); \ 00190 00191 00192 // the default exportable class identifier is the class name 00193 // the default list of archives types for which code id generated 00194 // are the originally included with this serialization system 00195 #define BOOST_CLASS_EXPORT(T) \ 00196 BOOST_CLASS_EXPORT_GUID( \ 00197 T, \ 00198 BOOST_PP_STRINGIZE(T) \ 00199 ) \ 00200 00201 00202 #endif // _QX_USE_MODIFY_BOOST_SERIALIZATION_EXPORT_HPP 00203 #endif // _QX_BOOST_SERIALIZATION_EXPORT_HPP_ 00204 #endif // _QX_ENABLE_BOOST_SERIALIZATION