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