SerializationExportWrapper.hpp

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00030 #define COVERAGE_IGNORE
00031 
00032 
00072 #include <boost/version.hpp>
00073 
00074 
00076 // Make sure includes happen in the correct place.  This has to go before
00077 // the SERIALIZATIONEXPORTWRAPPER_HPP_ guard, since we need it to be seen
00078 // by both .hpp and .cpp files.
00079 
00080 #if BOOST_VERSION < 103600
00081 // Boost 1.34 and older - export goes in headers
00082 #ifndef CHASTE_SERIALIZATION_CPP
00083 #include <boost/serialization/export.hpp>
00084 #endif // CHASTE_SERIALIZATION_CPP
00085 
00086 #elif BOOST_VERSION < 104100
00087 // Boost 1.36-1.40 - export goes in .cpp, along with archive includes
00088 #ifdef CHASTE_SERIALIZATION_CPP
00089 #include "CheckpointArchiveTypes.hpp"
00090 #include <boost/serialization/export.hpp>
00091 #endif // CHASTE_SERIALIZATION_CPP
00092 
00093 #else
00094 // Boost 1.41 and newer - export goes in both, with archive includes in .cpp
00095 #include <boost/serialization/extended_type_info.hpp> // We get compile errors without this...
00096 #include <boost/serialization/export.hpp>
00097 #ifdef CHASTE_SERIALIZATION_CPP
00098 #include "CheckpointArchiveTypes.hpp"
00099 #endif // CHASTE_SERIALIZATION_CPP
00100 
00101 #endif
00102 // Done includes
00103 
00104 
00106 #if BOOST_VERSION >= 104100 && defined(CHASTE_SERIALIZATION_CPP)
00107 // .cpp file needs to use BOOST_CLASS_EXPORT_IMPLEMENT, so we need
00108 // to redefine the macros from the .hpp file.  Hence this can't go
00109 // in the include guard.
00110 
00111 #undef CHASTE_CLASS_EXPORT_TEMPLATED
00112 
00117 #define CHASTE_CLASS_EXPORT_TEMPLATED(T, S)    \
00118    BOOST_CLASS_EXPORT_IMPLEMENT(T)
00119 
00120 #undef CHASTE_CLASS_EXPORT_INTERNAL
00121 
00125 #define CHASTE_CLASS_EXPORT_INTERNAL(T)        \
00126    BOOST_CLASS_EXPORT_IMPLEMENT(T)
00127 
00128 #endif // BOOST_VERSION >= 104100 && defined(CHASTE_SERIALIZATION_CPP)
00129 
00130 
00132 
00133 #ifndef SERIALIZATIONEXPORTWRAPPER_HPP_
00134 #define SERIALIZATIONEXPORTWRAPPER_HPP_
00135 // Code in the next block is only compiled when the .hpp is first seen
00136 
00138 
00139 #include <boost/preprocessor/cat.hpp>
00140 #include <boost/preprocessor/stringize.hpp>
00141 
00142 
00143 // Handle broken BOOST_CLASS_EXPORT in Boost 1.36 & 1.37
00144 #if BOOST_VERSION >= 103600 && BOOST_VERSION < 103800
00145 
00153 #define CHASTE_CLASS_EXPORT_GUID(T, K, S)                                           \
00154 namespace                                                                           \
00155 {                                                                                   \
00156     ::boost::archive::detail::guid_initializer< T > const &                         \
00157         BOOST_PP_CAT(BOOST_PP_CAT(boost_serialization_guid_initializer_, __LINE__), S)               \
00158         = ::boost::serialization::singleton<                                        \
00159             ::boost::archive::detail::guid_initializer< T >                         \
00160           >::get_mutable_instance().export_guid(K);                                 \
00161 }
00162 
00168 #define CHASTE_CLASS_EXPORT_TEMPLATED(T, S)    \
00169     CHASTE_CLASS_EXPORT_GUID(                  \
00170         T,                                     \
00171         BOOST_PP_STRINGIZE(T), S               \
00172     )                                          \
00173 
00174 
00178 #define CHASTE_CLASS_EXPORT_INTERNAL(T)        \
00179    CHASTE_CLASS_EXPORT_TEMPLATED(T, T)
00180 
00181 
00182 // The interface changes yet again in Boost 1.41, and we need something in both .hpp and .cpp...
00183 #elif BOOST_VERSION >= 104100
00184 // .hpp file needs to use BOOST_CLASS_EXPORT_KEY
00185 
00191 #define CHASTE_CLASS_EXPORT_TEMPLATED(T, S)   \
00192    BOOST_CLASS_EXPORT_KEY(T)
00193 
00198 #define CHASTE_CLASS_EXPORT_INTERNAL(T)       \
00199    BOOST_CLASS_EXPORT_KEY(T)
00200 
00201 
00202 #else // BOOST_VERSION < 103600 || (BOOST_VERSION >= 103800 && BOOST_VERSION < 104100)
00203 //Do exactly as we did before (so that archives created with 1.33 don't have to be re-generated)
00204 
00210 #define CHASTE_CLASS_EXPORT_TEMPLATED(T, S)    \
00211    BOOST_CLASS_EXPORT(T)
00212 
00217 #define CHASTE_CLASS_EXPORT_INTERNAL(T)        \
00218    BOOST_CLASS_EXPORT(T)
00219 
00220 #endif // BOOST_VERSION >= 103600 && BOOST_VERSION < 103800
00221 
00222 
00223 
00224 template<class> struct pack;
00231 template<class T> struct pack<void (T)> {
00232     typedef T type; 
00233 };
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 
00288 
00289 // End of include guard - code below here is executed in both .hpp and .cpp
00290 #endif // SERIALIZATIONEXPORTWRAPPER_HPP_
00292 
00293 
00294 // Since CHASTE_CLASS_EXPORT_TEMPLATED and CHASTE_CLASS_EXPORT_INTERNAL are re-defined for the .cpp file
00295 // in some Boost versions, the following macros will also need re-defining.
00296 
00297 #ifdef EXPORT_TEMPLATE_CLASS3_INTERNAL
00298 // Avoid re-definition when called from a .cpp file
00299 #undef EXPORT_TEMPLATE_CLASS3_INTERNAL
00300 #undef EXPORT_TEMPLATE_CLASS2_INTERNAL
00301 #undef EXPORT_TEMPLATE_CLASS1_INTERNAL
00302 #undef EXPORT_TEMPLATE_CLASS_ALL_DIMS_INTERNAL
00303 #undef EXPORT_TEMPLATE_CLASS_SAME_DIMS_INTERNAL
00304 #endif // EXPORT_TEMPLATE_CLASS3_INTERNAL
00305 
00306 // Macros for templated classes
00307 
00316 #define EXPORT_TEMPLATE_CLASS3_INTERNAL(CLASS, E, S, P) \
00317     CHASTE_CLASS_EXPORT_TEMPLATED( CHASTE_PACK_3(CLASS, E, S, P), CHASTE_EXPORT_KEY_3(CLASS, E, S, P) )
00318 
00326 #define EXPORT_TEMPLATE_CLASS2_INTERNAL(CLASS, E, S) \
00327     CHASTE_CLASS_EXPORT_TEMPLATED( CHASTE_PACK_2(CLASS, E, S), CHASTE_EXPORT_KEY_2(CLASS, E, S) )
00328 
00335 #define EXPORT_TEMPLATE_CLASS1_INTERNAL(CLASS, D) \
00336     CHASTE_CLASS_EXPORT_TEMPLATED( CHASTE_PACK_1(CLASS, D), CHASTE_EXPORT_KEY_1(CLASS, D) )
00337 
00344 #define EXPORT_TEMPLATE_CLASS_ALL_DIMS_INTERNAL(CLASS) \
00345     EXPORT_TEMPLATE_CLASS2(CLASS, 1, 1) \
00346     EXPORT_TEMPLATE_CLASS2(CLASS, 1, 2) \
00347     EXPORT_TEMPLATE_CLASS2(CLASS, 1, 3) \
00348     EXPORT_TEMPLATE_CLASS2(CLASS, 2, 2) \
00349     EXPORT_TEMPLATE_CLASS2(CLASS, 2, 3) \
00350     EXPORT_TEMPLATE_CLASS2(CLASS, 3, 3)
00351 
00358 #define EXPORT_TEMPLATE_CLASS_SAME_DIMS_INTERNAL(CLASS) \
00359     EXPORT_TEMPLATE_CLASS1(CLASS, 1) \
00360     EXPORT_TEMPLATE_CLASS1(CLASS, 2) \
00361     EXPORT_TEMPLATE_CLASS1(CLASS, 3)
00362 
00363 
00364 
00365 // Now define the macros that users actually call.
00366 // Again this goes outside the include guard, so it is seen by both .hpp and .cpp files.
00367 
00368 // However, we don't want to define things twice, so...
00369 #if !defined(CHASTE_CLASS_EXPORT) || defined(CHASTE_SERIALIZATION_CPP)
00370 #ifdef CHASTE_SERIALIZATION_CPP
00371 // Remove the definitions from when we were included via an .hpp file
00372 #undef CHASTE_CLASS_EXPORT
00373 #undef EXPORT_TEMPLATE_CLASS_SAME_DIMS
00374 #undef EXPORT_TEMPLATE_CLASS_ALL_DIMS
00375 #undef EXPORT_TEMPLATE_CLASS1
00376 #undef EXPORT_TEMPLATE_CLASS2
00377 #undef EXPORT_TEMPLATE_CLASS3
00378 #endif // CHASTE_SERIALIZATION_CPP
00379 
00380 
00381 #if (BOOST_VERSION < 103600  && ! defined(CHASTE_SERIALIZATION_CPP)) || \
00382     (BOOST_VERSION >= 103600 && defined(CHASTE_SERIALIZATION_CPP)) || \
00383     (BOOST_VERSION >= 104100)
00384 // Boost 1.34 and older - export goes in headers
00385 // Boost 1.36 and newer - export goes in .cpp
00386 // Boost 1.41 and newer - key goes in .hpp, implement goes in .cpp
00387 
00392 #define CHASTE_CLASS_EXPORT(T)                 CHASTE_CLASS_EXPORT_INTERNAL(T)
00393 
00398 #define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS) EXPORT_TEMPLATE_CLASS_SAME_DIMS_INTERNAL(CLASS)
00399 
00404 #define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)  EXPORT_TEMPLATE_CLASS_ALL_DIMS_INTERNAL(CLASS)
00405 
00410 #define EXPORT_TEMPLATE_CLASS1(CLASS, D)       EXPORT_TEMPLATE_CLASS1_INTERNAL(CLASS, D)
00411 
00417 #define EXPORT_TEMPLATE_CLASS2(CLASS, E, S)    EXPORT_TEMPLATE_CLASS2_INTERNAL(CLASS, E, S)
00418 
00425 #define EXPORT_TEMPLATE_CLASS3(CLASS, E, S, P) EXPORT_TEMPLATE_CLASS3_INTERNAL(CLASS, E, S, P)
00426 
00427 #else
00428 
00433 #define CHASTE_CLASS_EXPORT(T)
00434 
00438 #define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
00439 
00443 #define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
00444 
00449 #define EXPORT_TEMPLATE_CLASS1(CLASS, D)
00450 
00456 #define EXPORT_TEMPLATE_CLASS2(CLASS, E, S)
00457 
00464 #define EXPORT_TEMPLATE_CLASS3(CLASS, E, S, P)
00465 
00466 #endif // Long if!
00467 #endif // !defined(CHASTE_CLASS_EXPORT) || defined(CHASTE_SERIALIZATION_CPP)
00468 
00469 
00470 
00471 #undef COVERAGE_IGNORE

Generated on Mon Apr 18 11:35:28 2011 for Chaste by  doxygen 1.5.5