Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
SerializationExportWrapper.hpp
Go to the documentation of this file.
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
37// LCOV_EXCL_START
38
79#include <boost/version.hpp>
80
82// Make sure includes happen in the correct place. This has to go before
83// the SERIALIZATIONEXPORTWRAPPER_HPP_ guard, since we need it to be seen
84// by both .hpp and .cpp files.
85
86#if BOOST_VERSION < 103600
87// Boost 1.34 and older - export goes in headers
88#ifndef CHASTE_SERIALIZATION_CPP
89#include <boost/serialization/export.hpp>
90#endif // CHASTE_SERIALIZATION_CPP
91
92#elif BOOST_VERSION < 104100
93// Boost 1.36-1.40 - export goes in .cpp, along with archive includes
94#ifdef CHASTE_SERIALIZATION_CPP
96#include <boost/serialization/export.hpp>
97#endif // CHASTE_SERIALIZATION_CPP
98
99#else
100// Boost 1.41 and newer - export goes in both, with archive includes in .cpp
101#include <boost/serialization/extended_type_info.hpp> // We get compile errors without this...
102#include <boost/serialization/export.hpp>
103#ifdef CHASTE_SERIALIZATION_CPP
105#endif // CHASTE_SERIALIZATION_CPP
106
107#endif
108// Done includes
109
111#if BOOST_VERSION >= 104100 && defined(CHASTE_SERIALIZATION_CPP)
112// .cpp file needs to use BOOST_CLASS_EXPORT_IMPLEMENT, so we need
113// to redefine the macros from the .hpp file. Hence this can't go
114// in the include guard.
115
116#undef CHASTE_CLASS_EXPORT_TEMPLATED
122#define CHASTE_CLASS_EXPORT_TEMPLATED(T, S) \
123 BOOST_CLASS_EXPORT_IMPLEMENT(T)
124
125#undef CHASTE_CLASS_EXPORT_INTERNAL
130#define CHASTE_CLASS_EXPORT_INTERNAL(T) \
131 BOOST_CLASS_EXPORT_IMPLEMENT(T)
132
133#endif // BOOST_VERSION >= 104100 && defined(CHASTE_SERIALIZATION_CPP)
134
136
137#ifndef SERIALIZATIONEXPORTWRAPPER_HPP_
139#define SERIALIZATIONEXPORTWRAPPER_HPP_
141// Code in the next block is only compiled when the .hpp is first seen
142
144
145#include <boost/preprocessor/cat.hpp>
146#include <boost/preprocessor/stringize.hpp>
147
148// The interface changes yet again in Boost 1.41, and we need something in both .hpp and .cpp...
149#if BOOST_VERSION >= 104100
150// .hpp file needs to use BOOST_CLASS_EXPORT_KEY
151
157#define CHASTE_CLASS_EXPORT_TEMPLATED(T, S) \
158 BOOST_CLASS_EXPORT_KEY(T)
159
164#define CHASTE_CLASS_EXPORT_INTERNAL(T) \
165 BOOST_CLASS_EXPORT_KEY(T)
166
167#else // BOOST_VERSION < 103600 || (BOOST_VERSION >= 103800 && BOOST_VERSION < 104100)
168//Do exactly as we did before (so that archives created with 1.33 don't have to be re-generated)
169
175#define CHASTE_CLASS_EXPORT_TEMPLATED(T, S) \
176 BOOST_CLASS_EXPORT(T)
177
182#define CHASTE_CLASS_EXPORT_INTERNAL(T) \
183 BOOST_CLASS_EXPORT(T)
184
185#endif // BOOST_VERSION >= 103600 && BOOST_VERSION < 103800
186
187template<class> struct pack;
194template<class T> struct pack<void (T)> {
195 typedef T type;
196};
197
203#define CHASTE_EXPORT_KEY_1(CLASS, P1) \
204 BOOST_PP_CAT(CLASS, P1)
205
212#define CHASTE_EXPORT_KEY_2(CLASS, P1, P2) \
213 BOOST_PP_CAT(BOOST_PP_CAT(CLASS, P1), P2)
214
222#define CHASTE_EXPORT_KEY_3(CLASS, P1, P2, P3) \
223 BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(CLASS, P1), P2), P3)
224
230#define CHASTE_PACK_1(CLASS, P1) pack<void (CLASS< P1 >)>::type
231
238#define CHASTE_PACK_2(CLASS, P1, P2) pack<void (CLASS< P1,P2 >)>::type
239
247#define CHASTE_PACK_3(CLASS, P1, P2, P3) pack<void (CLASS< P1,P2,P3 >)>::type
248
249// End of include guard - code below here is executed in both .hpp and .cpp
250#endif // SERIALIZATIONEXPORTWRAPPER_HPP_
252
253// Since CHASTE_CLASS_EXPORT_TEMPLATED and CHASTE_CLASS_EXPORT_INTERNAL are re-defined for the .cpp file
254// in some Boost versions, the following macros will also need re-defining.
255
256#ifdef EXPORT_TEMPLATE_CLASS3_INTERNAL
257// Avoid re-definition when called from a .cpp file
258#undef EXPORT_TEMPLATE_CLASS3_INTERNAL
259#undef EXPORT_TEMPLATE_CLASS2_INTERNAL
260#undef EXPORT_TEMPLATE_CLASS1_INTERNAL
261#undef EXPORT_TEMPLATE_CLASS_ALL_DIMS_INTERNAL
262#undef EXPORT_TEMPLATE_CLASS_SAME_DIMS_INTERNAL
263#endif // EXPORT_TEMPLATE_CLASS3_INTERNAL
264
265// Macros for templated classes
266
275#define EXPORT_TEMPLATE_CLASS3_INTERNAL(CLASS, E, S, P) \
276 CHASTE_CLASS_EXPORT_TEMPLATED( CHASTE_PACK_3(CLASS, E, S, P), CHASTE_EXPORT_KEY_3(CLASS, E, S, P) )
277
285#define EXPORT_TEMPLATE_CLASS2_INTERNAL(CLASS, E, S) \
286 CHASTE_CLASS_EXPORT_TEMPLATED( CHASTE_PACK_2(CLASS, E, S), CHASTE_EXPORT_KEY_2(CLASS, E, S) )
287
294#define EXPORT_TEMPLATE_CLASS1_INTERNAL(CLASS, D) \
295 CHASTE_CLASS_EXPORT_TEMPLATED( CHASTE_PACK_1(CLASS, D), CHASTE_EXPORT_KEY_1(CLASS, D) )
296
303#define EXPORT_TEMPLATE_CLASS_ALL_DIMS_INTERNAL(CLASS) \
304 EXPORT_TEMPLATE_CLASS2(CLASS, 1, 1) \
305 EXPORT_TEMPLATE_CLASS2(CLASS, 1, 2) \
306 EXPORT_TEMPLATE_CLASS2(CLASS, 1, 3) \
307 EXPORT_TEMPLATE_CLASS2(CLASS, 2, 2) \
308 EXPORT_TEMPLATE_CLASS2(CLASS, 2, 3) \
309 EXPORT_TEMPLATE_CLASS2(CLASS, 3, 3)
310
316#define EXPORT_TEMPLATE_CLASS_SAME_DIMS_INTERNAL(CLASS) \
317 EXPORT_TEMPLATE_CLASS1(CLASS, 1) \
318 EXPORT_TEMPLATE_CLASS1(CLASS, 2) \
319 EXPORT_TEMPLATE_CLASS1(CLASS, 3)
320
321// Now define the macros that users actually call.
322// Again this goes outside the include guard, so it is seen by both .hpp and .cpp files.
323
324// However, we don't want to define things twice, so...
325#if !defined(CHASTE_CLASS_EXPORT) || defined(CHASTE_SERIALIZATION_CPP)
326#ifdef CHASTE_SERIALIZATION_CPP
327// Remove the definitions from when we were included via an .hpp file
328#undef CHASTE_CLASS_EXPORT
329#undef EXPORT_TEMPLATE_CLASS_SAME_DIMS
330#undef EXPORT_TEMPLATE_CLASS_ALL_DIMS
331#undef EXPORT_TEMPLATE_CLASS1
332#undef EXPORT_TEMPLATE_CLASS2
333#undef EXPORT_TEMPLATE_CLASS3
334#endif // CHASTE_SERIALIZATION_CPP
335
336#if (BOOST_VERSION < 103600 && ! defined(CHASTE_SERIALIZATION_CPP)) || \
337 (BOOST_VERSION >= 103600 && defined(CHASTE_SERIALIZATION_CPP)) || \
338 (BOOST_VERSION >= 104100)
339// Boost 1.34 and older - export goes in headers
340// Boost 1.36 and newer - export goes in .cpp
341// Boost 1.41 and newer - key goes in .hpp, implement goes in .cpp
342
347#define CHASTE_CLASS_EXPORT(T) CHASTE_CLASS_EXPORT_INTERNAL(T)
352#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS) EXPORT_TEMPLATE_CLASS_SAME_DIMS_INTERNAL(CLASS)
358#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS) EXPORT_TEMPLATE_CLASS_ALL_DIMS_INTERNAL(CLASS)
364#define EXPORT_TEMPLATE_CLASS1(CLASS, D) EXPORT_TEMPLATE_CLASS1_INTERNAL(CLASS, D)
371#define EXPORT_TEMPLATE_CLASS2(CLASS, E, S) EXPORT_TEMPLATE_CLASS2_INTERNAL(CLASS, E, S)
379#define EXPORT_TEMPLATE_CLASS3(CLASS, E, S, P) EXPORT_TEMPLATE_CLASS3_INTERNAL(CLASS, E, S, P)
380
381#else
382
387#define CHASTE_CLASS_EXPORT(T)
392#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
397#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
403#define EXPORT_TEMPLATE_CLASS1(CLASS, D)
410#define EXPORT_TEMPLATE_CLASS2(CLASS, E, S)
418#define EXPORT_TEMPLATE_CLASS3(CLASS, E, S, P)
419
420#endif // Long if!
421#endif // !defined(CHASTE_CLASS_EXPORT) || defined(CHASTE_SERIALIZATION_CPP)
422
423// LCOV_EXCL_STOP