QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
qx_boost_class_export.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** https://www.qxorm.com/
4** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
5**
6** This file is part of the QxOrm library
7**
8** This software is provided 'as-is', without any express or implied
9** warranty. In no event will the authors be held liable for any
10** damages arising from the use of this software
11**
12** Commercial Usage
13** Licensees holding valid commercial QxOrm licenses may use this file in
14** accordance with the commercial license agreement provided with the
15** Software or, alternatively, in accordance with the terms contained in
16** a written agreement between you and Lionel Marty
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3.0 as published by the Free Software
21** Foundation and appearing in the file 'license.gpl3.txt' included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU General Public License version 3.0 requirements will be
24** met : http://www.gnu.org/copyleft/gpl.html
25**
26** If you are unsure which license is appropriate for your use, or
27** if you have questions regarding the use of this file, please contact :
28** contact@qxorm.com
29**
30****************************************************************************/
31
32#ifdef _QX_ENABLE_BOOST_SERIALIZATION
33#ifndef _QX_BOOST_SERIALIZATION_EXPORT_HPP_
34#define _QX_BOOST_SERIALIZATION_EXPORT_HPP_
35
36#ifdef _MSC_VER
37#pragma once
38#endif
39
40#include <QxCommon/QxConfig.h>
41
42#if _QX_USE_MODIFY_BOOST_SERIALIZATION_EXPORT_HPP
43
44#include <utility>
45#include <cstddef> // NULL
46
47#include <boost/config.hpp>
48#include <boost/preprocessor/stringize.hpp>
49
50#ifndef BOOST_SERIALIZATION_DEFAULT_TYPE_INFO
51 #include <boost/serialization/extended_type_info_typeid.hpp>
52#endif // BOOST_SERIALIZATION_DEFAULT_TYPE_INFO
53
54#include <boost/serialization/static_warning.hpp>
55#include <boost/serialization/type_info_implementation.hpp>
56#include <boost/serialization/assume_abstract.hpp>
57#include <boost/serialization/force_include.hpp>
58#include <boost/serialization/singleton.hpp>
59
60#include <boost/archive/detail/register_archive.hpp>
61#include <boost/mpl/assert.hpp>
62#include <boost/mpl/and.hpp>
63#include <boost/mpl/not.hpp>
64#include <boost/mpl/bool.hpp>
65
66#include <iostream>
67
68namespace boost {
69namespace archive {
70namespace detail {
71
72class basic_pointer_iserializer;
73class basic_pointer_oserializer;
74
75template<class Archive, class T>
76class pointer_iserializer;
77template<class Archive, class T>
78class pointer_oserializer;
79
80template <class Archive, class Serializable>
81struct export_impl
82{
83 static const basic_pointer_iserializer &
84 enable_load(mpl::true_){
85 return boost::serialization::singleton<
86 pointer_iserializer<Archive, Serializable>
87 >::get_const_instance();
88 }
89
90 static const basic_pointer_oserializer &
91 enable_save(mpl::true_){
92 return boost::serialization::singleton<
93 pointer_oserializer<Archive, Serializable>
94 >::get_const_instance();
95 }
96 inline static void enable_load(mpl::false_) {}
97 inline static void enable_save(mpl::false_) {}
98};
99
100// On many platforms, naming a specialization of this template is
101// enough to cause its argument to be instantiated.
102template <void(*)()>
103struct instantiate_function {};
104
105template <class Archive, class Serializable>
106struct ptr_serialization_support
107{
108# if defined(BOOST_MSVC)
109 virtual BOOST_DLLEXPORT void instantiate() QX_USED;
110# elif defined(__BORLANDC__)
111 static BOOST_DLLEXPORT void instantiate() QX_USED;
112 enum { x = sizeof(instantiate(),3) };
113# else
114 static BOOST_DLLEXPORT void instantiate() QX_USED;
115 typedef instantiate_function<
116 &ptr_serialization_support::instantiate
117 > x;
118# endif
119};
120
121template <class Archive, class Serializable>
122BOOST_DLLEXPORT void
123ptr_serialization_support<Archive,Serializable>::instantiate()
124{
125 export_impl<Archive,Serializable>::enable_save(
126 #if ! defined(__BORLANDC__)
127 BOOST_DEDUCED_TYPENAME
128 #endif
129 Archive::is_saving()
130 );
131
132 export_impl<Archive,Serializable>::enable_load(
133 #if ! defined(__BORLANDC__)
134 BOOST_DEDUCED_TYPENAME
135 #endif
136 Archive::is_loading()
137 );
138}
139
140template<class T>
141struct guid_initializer
142{
143 const guid_initializer & export_guid(char const* /* key */, mpl::false_){
144 // generates the statically-initialized objects whose constructors
145 // register the information allowing serialization of T objects
146 // through pointers to their base classes.
147 instantiate_ptr_serialization((T*)0, 0, adl_tag());
148 return *this;
149 }
150 const guid_initializer & export_guid(char const* /*key*/, mpl::true_){
151 return *this;
152 }
153 const guid_initializer & export_guid(char const* key){
154 BOOST_STATIC_WARNING(boost::is_polymorphic<T>::value);
155 assert(NULL != key);
156 boost::serialization::singleton<
157 BOOST_DEDUCED_TYPENAME
158 boost::serialization::type_info_implementation<T>::type
159 >::get_mutable_instance().key_register(key);
160 // note: exporting an abstract base class will have no effect
161 // and cannot be used to instantitiate serialization code
162 // (one might be using this in a DLL to instantiate code)
163 //BOOST_STATIC_WARNING(! boost::serialization::is_abstract<T>::value);
164 return export_guid(key, boost::serialization::is_abstract<T>());
165 }
166};
167
168} // namespace detail
169} // namespace archive
170} // namespace boost
171
172#define BOOST_CLASS_EXPORT_GUID(T, K) \
173namespace \
174{ \
175 ::boost::archive::detail::guid_initializer< T > const & \
176 boost_serialization_guid_initializer_##T \
177 = ::boost::serialization::singleton< \
178 ::boost::archive::detail::guid_initializer< T > \
179 >::get_mutable_instance().export_guid(K); \
180}
181
182// check for unnecessary export. T isn't polymorphic so there is no
183// need to export it.
184#define BOOST_CLASS_EXPORT_CHECK(T) \
185 BOOST_STATIC_WARNING( \
186 boost::is_polymorphic<U>::value \
187 ); \
188
189
190// the default exportable class identifier is the class name
191// the default list of archives types for which code id generated
192// are the originally included with this serialization system
193#define BOOST_CLASS_EXPORT(T) \
194 BOOST_CLASS_EXPORT_GUID( \
195 T, \
196 BOOST_PP_STRINGIZE(T) \
197 ) \
198
199
200#endif // _QX_USE_MODIFY_BOOST_SERIALIZATION_EXPORT_HPP
201#endif // _QX_BOOST_SERIALIZATION_EXPORT_HPP_
202#endif // _QX_ENABLE_BOOST_SERIALIZATION
List of parameters to compile and build QxOrm library.
#define QX_USED
Definition QxMacro.h:244