QxOrm  1.4.9
C++ Object Relational Mapping library
qx_boost_class_export.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** https://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/preprocessor/stringize.hpp>
00049 
00050 #ifndef BOOST_SERIALIZATION_DEFAULT_TYPE_INFO   
00051     #include <boost/serialization/extended_type_info_typeid.hpp>   
00052 #endif // BOOST_SERIALIZATION_DEFAULT_TYPE_INFO
00053 
00054 #include <boost/serialization/static_warning.hpp>
00055 #include <boost/serialization/type_info_implementation.hpp>
00056 #include <boost/serialization/assume_abstract.hpp>
00057 #include <boost/serialization/force_include.hpp>
00058 #include <boost/serialization/singleton.hpp>
00059 
00060 #include <boost/archive/detail/register_archive.hpp>
00061 #include <boost/mpl/assert.hpp>
00062 #include <boost/mpl/and.hpp>
00063 #include <boost/mpl/not.hpp>
00064 #include <boost/mpl/bool.hpp>
00065 
00066 #include <iostream>
00067 
00068 namespace boost {
00069 namespace archive {
00070 namespace detail {
00071 
00072 class basic_pointer_iserializer;
00073 class basic_pointer_oserializer;
00074 
00075 template<class Archive, class T>
00076 class pointer_iserializer;
00077 template<class Archive, class T>
00078 class pointer_oserializer;
00079 
00080 template <class Archive, class Serializable>
00081 struct export_impl
00082 {
00083     static const basic_pointer_iserializer &
00084     enable_load(mpl::true_){
00085         return boost::serialization::singleton<
00086             pointer_iserializer<Archive, Serializable> 
00087         >::get_const_instance();
00088     }
00089 
00090     static const basic_pointer_oserializer &
00091     enable_save(mpl::true_){
00092         return boost::serialization::singleton<
00093             pointer_oserializer<Archive, Serializable> 
00094         >::get_const_instance();
00095     }
00096     inline static void enable_load(mpl::false_) {}
00097     inline static void enable_save(mpl::false_) {}
00098 };
00099 
00100 // On many platforms, naming a specialization of this template is
00101 // enough to cause its argument to be instantiated.
00102 template <void(*)()>
00103 struct instantiate_function {};
00104 
00105 template <class Archive, class Serializable>
00106 struct ptr_serialization_support
00107 {
00108 # if defined(BOOST_MSVC)
00109     virtual BOOST_DLLEXPORT void instantiate() QX_USED;
00110 # elif defined(__BORLANDC__)   
00111     static BOOST_DLLEXPORT void instantiate() QX_USED;
00112     enum { x = sizeof(instantiate(),3) };
00113 # else
00114     static BOOST_DLLEXPORT void instantiate() QX_USED;
00115     typedef instantiate_function<
00116         &ptr_serialization_support::instantiate
00117     > x;
00118 # endif
00119 };
00120 
00121 template <class Archive, class Serializable>
00122 BOOST_DLLEXPORT void 
00123 ptr_serialization_support<Archive,Serializable>::instantiate()
00124 {
00125     export_impl<Archive,Serializable>::enable_save(
00126         #if ! defined(__BORLANDC__)
00127         BOOST_DEDUCED_TYPENAME 
00128         #endif
00129         Archive::is_saving()
00130     );
00131 
00132     export_impl<Archive,Serializable>::enable_load(
00133         #if ! defined(__BORLANDC__)
00134         BOOST_DEDUCED_TYPENAME 
00135         #endif
00136         Archive::is_loading()
00137     );
00138 }
00139 
00140 template<class T>
00141 struct guid_initializer
00142 {  
00143     const guid_initializer & export_guid(char const* /* key */, mpl::false_){
00144         // generates the statically-initialized objects whose constructors
00145         // register the information allowing serialization of T objects
00146         // through pointers to their base classes.
00147         instantiate_ptr_serialization((T*)0, 0, adl_tag());
00148         return *this;
00149     }
00150     const guid_initializer & export_guid(char const* /*key*/, mpl::true_){
00151         return *this;
00152     }
00153     const guid_initializer & export_guid(char const* key){
00154         BOOST_STATIC_WARNING(boost::is_polymorphic<T>::value);
00155         assert(NULL != key);
00156         boost::serialization::singleton<
00157             BOOST_DEDUCED_TYPENAME 
00158             boost::serialization::type_info_implementation<T>::type
00159         >::get_mutable_instance().key_register(key);
00160         // note: exporting an abstract base class will have no effect
00161         // and cannot be used to instantitiate serialization code
00162         // (one might be using this in a DLL to instantiate code)
00163         //BOOST_STATIC_WARNING(! boost::serialization::is_abstract<T>::value);
00164         return export_guid(key, boost::serialization::is_abstract<T>());
00165     }
00166 };
00167 
00168 } // namespace detail
00169 } // namespace archive
00170 } // namespace boost
00171 
00172 #define BOOST_CLASS_EXPORT_GUID(T, K)                                               \
00173 namespace                                                                           \
00174 {                                                                                   \
00175     ::boost::archive::detail::guid_initializer< T > const &                         \
00176         boost_serialization_guid_initializer_##T                                    \
00177         = ::boost::serialization::singleton<                                        \
00178             ::boost::archive::detail::guid_initializer< T >                         \
00179           >::get_mutable_instance().export_guid(K);                                 \
00180 }
00181 
00182 // check for unnecessary export.  T isn't polymorphic so there is no
00183 // need to export it.
00184 #define BOOST_CLASS_EXPORT_CHECK(T)                              \
00185     BOOST_STATIC_WARNING(                                        \
00186         boost::is_polymorphic<U>::value                          \
00187     );                                                           \
00188     
00189 
00190 // the default exportable class identifier is the class name
00191 // the default list of archives types for which code id generated
00192 // are the originally included with this serialization system
00193 #define BOOST_CLASS_EXPORT(T)                   \
00194     BOOST_CLASS_EXPORT_GUID(                    \
00195         T,                                      \
00196         BOOST_PP_STRINGIZE(T)                   \
00197     )                                           \
00198     
00199 
00200 #endif // _QX_USE_MODIFY_BOOST_SERIALIZATION_EXPORT_HPP
00201 #endif // _QX_BOOST_SERIALIZATION_EXPORT_HPP_
00202 #endif // _QX_ENABLE_BOOST_SERIALIZATION