uLib-0.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Export.h
Go to the documentation of this file.
1 /*//////////////////////////////////////////////////////////////////////////////
2 // CMT Cosmic Muon Tomography project //////////////////////////////////////////
4 
5  Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
6  All rights reserved
7 
8  Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
9 
10  ------------------------------------------------------------------
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 3.0 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library.
23 
25 
26 
27 
28 #ifndef U_CORE_EXPORT_H
29 #define U_CORE_EXPORT_H
30 
31 #include <utility>
32 #include <cstddef> // NULL
33 #include <iostream>
34 
35 #include <boost/config.hpp>
36 #include <boost/static_assert.hpp>
37 #include <boost/preprocessor/stringize.hpp>
38 #include <boost/type_traits/is_polymorphic.hpp>
39 
40 #include <boost/mpl/assert.hpp>
41 #include <boost/mpl/and.hpp>
42 #include <boost/mpl/not.hpp>
43 #include <boost/mpl/bool.hpp>
44 
45 #include <boost/serialization/extended_type_info.hpp> // for guid_defined only
46 #include <boost/serialization/static_warning.hpp>
47 #include <boost/serialization/assume_abstract.hpp>
48 #include <boost/serialization/force_include.hpp>
49 #include <boost/serialization/singleton.hpp>
50 
51 #include <boost/archive/detail/register_archive.hpp>
52 
53 
54 #include "Core/Archives.h"
55 
59 
60 
61 
62 namespace uLib {
63 namespace Archive {
64 namespace detail {
65 namespace extra_detail {
66 
67 template<class T>
68 struct guid_initializer
69 {
70  void export_guid(mpl::false_) const {
71  // generates the statically-initialized objects whose constructors
72  // register the information allowing serialization of T objects
73  // through pointers to their base classes.
74  boost::archive::detail::
75  instantiate_ptr_serialization((T*)0, 0,
76  uLib::Archive::detail::adl_tag());
77  }
78  void export_guid(mpl::true_) const {
79  }
80  guid_initializer const & export_guid() const {
81  BOOST_STATIC_WARNING(boost::is_polymorphic< T >::value);
82  // note: exporting an abstract base class will have no effect
83  // and cannot be used to instantitiate serialization code
84  // (one might be using this in a DLL to instantiate code)
85  //BOOST_STATIC_WARNING(! boost::serialization::is_abstract< T >::value);
86  export_guid(boost::serialization::is_abstract< T >());
87  return *this;
88  }
89 };
90 
91 template<typename T>
92 struct init_guid;
93 
94 } // anonymous
95 } // namespace detail
96 } // namespace Archive
97 } // namespace uLib
98 
99 
100 
101 #define ULIB_CLASS_EXPORT_IMPLEMENT(T) \
102  namespace uLib { \
103  namespace Archive { \
104  namespace detail { \
105  namespace extra_detail { \
106  template<> \
107  struct init_guid< T > { \
108  static guid_initializer< T > const & g; \
109  }; \
110  guid_initializer< T > const & init_guid< T >::g = \
111  ::boost::serialization::singleton< \
112  guid_initializer< T > \
113  >::get_mutable_instance().export_guid(); \
114  }}}} \
115 /**/
116 
117 #endif // EXPORT_H