SerializationExportWrapper.hpp

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (c) 2005-2015, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00037 #define COVERAGE_IGNORE
00038 
00078 #include <boost/version.hpp>
00079 
00081 // Make sure includes happen in the correct place.  This has to go before
00082 // the SERIALIZATIONEXPORTWRAPPER_HPP_ guard, since we need it to be seen
00083 // by both .hpp and .cpp files.
00084 
00085 #if BOOST_VERSION < 103600
00086 // Boost 1.34 and older - export goes in headers
00087 #ifndef CHASTE_SERIALIZATION_CPP
00088 #include <boost/serialization/export.hpp>
00089 #endif // CHASTE_SERIALIZATION_CPP
00090 
00091 #elif BOOST_VERSION < 104100
00092 // Boost 1.36-1.40 - export goes in .cpp, along with archive includes
00093 #ifdef CHASTE_SERIALIZATION_CPP
00094 #include "CheckpointArchiveTypes.hpp"
00095 #include <boost/serialization/export.hpp>
00096 #endif // CHASTE_SERIALIZATION_CPP
00097 
00098 #else
00099 // Boost 1.41 and newer - export goes in both, with archive includes in .cpp
00100 #include <boost/serialization/extended_type_info.hpp> // We get compile errors without this...
00101 #include <boost/serialization/export.hpp>
00102 #ifdef CHASTE_SERIALIZATION_CPP
00103 #include "CheckpointArchiveTypes.hpp"
00104 #endif // CHASTE_SERIALIZATION_CPP
00105 
00106 #endif
00107 // Done includes
00108 
00110 #if BOOST_VERSION >= 104100 && defined(CHASTE_SERIALIZATION_CPP)
00111 // .cpp file needs to use BOOST_CLASS_EXPORT_IMPLEMENT, so we need
00112 // to redefine the macros from the .hpp file.  Hence this can't go
00113 // in the include guard.
00114 
00115 #undef CHASTE_CLASS_EXPORT_TEMPLATED
00116 
00121 #define CHASTE_CLASS_EXPORT_TEMPLATED(T, S)    \
00122    BOOST_CLASS_EXPORT_IMPLEMENT(T)
00123 
00124 #undef CHASTE_CLASS_EXPORT_INTERNAL
00125 
00129 #define CHASTE_CLASS_EXPORT_INTERNAL(T)        \
00130    BOOST_CLASS_EXPORT_IMPLEMENT(T)
00131 
00132 #endif // BOOST_VERSION >= 104100 && defined(CHASTE_SERIALIZATION_CPP)
00133 
00135 
00136 #ifndef SERIALIZATIONEXPORTWRAPPER_HPP_
00137 
00138 #define SERIALIZATIONEXPORTWRAPPER_HPP_
00139 
00140 // Code in the next block is only compiled when the .hpp is first seen
00141 
00143 
00144 #include <boost/preprocessor/cat.hpp>
00145 #include <boost/preprocessor/stringize.hpp>
00146 
00147 // Handle broken BOOST_CLASS_EXPORT in Boost 1.36 & 1.37
00148 #if BOOST_VERSION >= 103600 && BOOST_VERSION < 103800
00149 
00157 #define CHASTE_CLASS_EXPORT_GUID(T, K, S)                                           \
00158 namespace                                                                           \
00159 {                                                                                   \
00160     ::boost::archive::detail::guid_initializer< T > const &                         \
00161         BOOST_PP_CAT(BOOST_PP_CAT(boost_serialization_guid_initializer_, __LINE__), S)               \
00162         = ::boost::serialization::singleton<                                        \
00163             ::boost::archive::detail::guid_initializer< T >                         \
00164           >::get_mutable_instance().export_guid(K);                                 \
00165 }
00166 
00172 #define CHASTE_CLASS_EXPORT_TEMPLATED(T, S)    \
00173     CHASTE_CLASS_EXPORT_GUID(                  \
00174         T,                                     \
00175         BOOST_PP_STRINGIZE(T), S               \
00176     )                                          \
00177 
00178 
00182 #define CHASTE_CLASS_EXPORT_INTERNAL(T)        \
00183    CHASTE_CLASS_EXPORT_TEMPLATED(T, T)
00184 
00185 
00186 // The interface changes yet again in Boost 1.41, and we need something in both .hpp and .cpp...
00187 #elif BOOST_VERSION >= 104100
00188 // .hpp file needs to use BOOST_CLASS_EXPORT_KEY
00189 
00195 #define CHASTE_CLASS_EXPORT_TEMPLATED(T, S)   \
00196    BOOST_CLASS_EXPORT_KEY(T)
00197 
00202 #define CHASTE_CLASS_EXPORT_INTERNAL(T)       \
00203    BOOST_CLASS_EXPORT_KEY(T)
00204 
00205 #else // BOOST_VERSION < 103600 || (BOOST_VERSION >= 103800 && BOOST_VERSION < 104100)
00206 //Do exactly as we did before (so that archives created with 1.33 don't have to be re-generated)
00207 
00213 #define CHASTE_CLASS_EXPORT_TEMPLATED(T, S)    \
00214    BOOST_CLASS_EXPORT(T)
00215 
00220 #define CHASTE_CLASS_EXPORT_INTERNAL(T)        \
00221    BOOST_CLASS_EXPORT(T)
00222 
00223 #endif // BOOST_VERSION >= 103600 && BOOST_VERSION < 103800
00224 
00225 template<class> struct pack;
00232 template<class T> struct pack<void (T)> {
00233     typedef T type; 
00234 };
00235 
00241 #define CHASTE_EXPORT_KEY_1(CLASS, P1) \
00242     BOOST_PP_CAT(CLASS, P1)
00243 
00250 #define CHASTE_EXPORT_KEY_2(CLASS, P1, P2) \
00251     BOOST_PP_CAT(BOOST_PP_CAT(CLASS, P1), P2)
00252 
00260 #define CHASTE_EXPORT_KEY_3(CLASS, P1, P2, P3) \
00261     BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(CLASS, P1), P2), P3)
00262 
00268 #define CHASTE_PACK_1(CLASS, P1) pack<void (CLASS< P1 >)>::type
00269 
00276 #define CHASTE_PACK_2(CLASS, P1, P2) pack<void (CLASS< P1,P2 >)>::type
00277 
00285 #define CHASTE_PACK_3(CLASS, P1, P2, P3) pack<void (CLASS< P1,P2,P3 >)>::type
00286 
00287 // End of include guard - code below here is executed in both .hpp and .cpp
00288 #endif // SERIALIZATIONEXPORTWRAPPER_HPP_
00290 
00291 // Since CHASTE_CLASS_EXPORT_TEMPLATED and CHASTE_CLASS_EXPORT_INTERNAL are re-defined for the .cpp file
00292 // in some Boost versions, the following macros will also need re-defining.
00293 
00294 #ifdef EXPORT_TEMPLATE_CLASS3_INTERNAL
00295 // Avoid re-definition when called from a .cpp file
00296 #undef EXPORT_TEMPLATE_CLASS3_INTERNAL
00297 #undef EXPORT_TEMPLATE_CLASS2_INTERNAL
00298 #undef EXPORT_TEMPLATE_CLASS1_INTERNAL
00299 #undef EXPORT_TEMPLATE_CLASS_ALL_DIMS_INTERNAL
00300 #undef EXPORT_TEMPLATE_CLASS_SAME_DIMS_INTERNAL
00301 #endif // EXPORT_TEMPLATE_CLASS3_INTERNAL
00302 
00303 // Macros for templated classes
00304 
00313 #define EXPORT_TEMPLATE_CLASS3_INTERNAL(CLASS, E, S, P) \
00314     CHASTE_CLASS_EXPORT_TEMPLATED( CHASTE_PACK_3(CLASS, E, S, P), CHASTE_EXPORT_KEY_3(CLASS, E, S, P) )
00315 
00323 #define EXPORT_TEMPLATE_CLASS2_INTERNAL(CLASS, E, S) \
00324     CHASTE_CLASS_EXPORT_TEMPLATED( CHASTE_PACK_2(CLASS, E, S), CHASTE_EXPORT_KEY_2(CLASS, E, S) )
00325 
00332 #define EXPORT_TEMPLATE_CLASS1_INTERNAL(CLASS, D) \
00333     CHASTE_CLASS_EXPORT_TEMPLATED( CHASTE_PACK_1(CLASS, D), CHASTE_EXPORT_KEY_1(CLASS, D) )
00334 
00341 #define EXPORT_TEMPLATE_CLASS_ALL_DIMS_INTERNAL(CLASS) \
00342     EXPORT_TEMPLATE_CLASS2(CLASS, 1, 1) \
00343     EXPORT_TEMPLATE_CLASS2(CLASS, 1, 2) \
00344     EXPORT_TEMPLATE_CLASS2(CLASS, 1, 3) \
00345     EXPORT_TEMPLATE_CLASS2(CLASS, 2, 2) \
00346     EXPORT_TEMPLATE_CLASS2(CLASS, 2, 3) \
00347     EXPORT_TEMPLATE_CLASS2(CLASS, 3, 3)
00348 
00354 #define EXPORT_TEMPLATE_CLASS_SAME_DIMS_INTERNAL(CLASS) \
00355     EXPORT_TEMPLATE_CLASS1(CLASS, 1) \
00356     EXPORT_TEMPLATE_CLASS1(CLASS, 2) \
00357     EXPORT_TEMPLATE_CLASS1(CLASS, 3)
00358 
00359 // Now define the macros that users actually call.
00360 // Again this goes outside the include guard, so it is seen by both .hpp and .cpp files.
00361 
00362 // However, we don't want to define things twice, so...
00363 #if !defined(CHASTE_CLASS_EXPORT) || defined(CHASTE_SERIALIZATION_CPP)
00364 #ifdef CHASTE_SERIALIZATION_CPP
00365 // Remove the definitions from when we were included via an .hpp file
00366 #undef CHASTE_CLASS_EXPORT
00367 #undef EXPORT_TEMPLATE_CLASS_SAME_DIMS
00368 #undef EXPORT_TEMPLATE_CLASS_ALL_DIMS
00369 #undef EXPORT_TEMPLATE_CLASS1
00370 #undef EXPORT_TEMPLATE_CLASS2
00371 #undef EXPORT_TEMPLATE_CLASS3
00372 #endif // CHASTE_SERIALIZATION_CPP
00373 
00374 #if (BOOST_VERSION < 103600  && ! defined(CHASTE_SERIALIZATION_CPP)) || \
00375     (BOOST_VERSION >= 103600 && defined(CHASTE_SERIALIZATION_CPP)) || \
00376     (BOOST_VERSION >= 104100)
00377 // Boost 1.34 and older - export goes in headers
00378 // Boost 1.36 and newer - export goes in .cpp
00379 // Boost 1.41 and newer - key goes in .hpp, implement goes in .cpp
00380 
00385 #define CHASTE_CLASS_EXPORT(T)                 CHASTE_CLASS_EXPORT_INTERNAL(T)
00386 
00390 #define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS) EXPORT_TEMPLATE_CLASS_SAME_DIMS_INTERNAL(CLASS)
00391 
00396 #define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)  EXPORT_TEMPLATE_CLASS_ALL_DIMS_INTERNAL(CLASS)
00397 
00402 #define EXPORT_TEMPLATE_CLASS1(CLASS, D)       EXPORT_TEMPLATE_CLASS1_INTERNAL(CLASS, D)
00403 
00409 #define EXPORT_TEMPLATE_CLASS2(CLASS, E, S)    EXPORT_TEMPLATE_CLASS2_INTERNAL(CLASS, E, S)
00410 
00417 #define EXPORT_TEMPLATE_CLASS3(CLASS, E, S, P) EXPORT_TEMPLATE_CLASS3_INTERNAL(CLASS, E, S, P)
00418 
00419 #else
00420 
00425 #define CHASTE_CLASS_EXPORT(T)
00426 
00430 #define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
00431 
00435 #define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
00436 
00441 #define EXPORT_TEMPLATE_CLASS1(CLASS, D)
00442 
00448 #define EXPORT_TEMPLATE_CLASS2(CLASS, E, S)
00449 
00456 #define EXPORT_TEMPLATE_CLASS3(CLASS, E, S, P)
00457 
00458 #endif // Long if!
00459 #endif // !defined(CHASTE_CLASS_EXPORT) || defined(CHASTE_SERIALIZATION_CPP)
00460 
00461 #undef COVERAGE_IGNORE

Generated by  doxygen 1.6.2