Chris@16
|
1 // Copyright David Abrahams 2002.
|
Chris@16
|
2 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
3 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
4 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5 #ifndef REFERENT_STORAGE_DWA200278_HPP
|
Chris@16
|
6 # define REFERENT_STORAGE_DWA200278_HPP
|
Chris@16
|
7 # include <boost/mpl/if.hpp>
|
Chris@16
|
8 # include <cstddef>
|
Chris@16
|
9
|
Chris@16
|
10 namespace boost { namespace python { namespace detail {
|
Chris@16
|
11
|
Chris@16
|
12 struct alignment_dummy;
|
Chris@16
|
13 typedef void (*function_ptr)();
|
Chris@16
|
14 typedef int (alignment_dummy::*member_ptr);
|
Chris@16
|
15 typedef int (alignment_dummy::*member_function_ptr)();
|
Chris@16
|
16
|
Chris@16
|
17 # define BOOST_PYTHON_ALIGNER(T, n) \
|
Chris@16
|
18 typename mpl::if_c< \
|
Chris@16
|
19 sizeof(T) <= size, T, char>::type t##n
|
Chris@16
|
20
|
Chris@16
|
21 // Storage for size bytes, aligned to all fundamental types no larger than size
|
Chris@16
|
22 template <std::size_t size>
|
Chris@16
|
23 union aligned_storage
|
Chris@16
|
24 {
|
Chris@16
|
25 BOOST_PYTHON_ALIGNER(char, 0);
|
Chris@16
|
26 BOOST_PYTHON_ALIGNER(short, 1);
|
Chris@16
|
27 BOOST_PYTHON_ALIGNER(int, 2);
|
Chris@16
|
28 BOOST_PYTHON_ALIGNER(long, 3);
|
Chris@16
|
29 BOOST_PYTHON_ALIGNER(float, 4);
|
Chris@16
|
30 BOOST_PYTHON_ALIGNER(double, 5);
|
Chris@16
|
31 BOOST_PYTHON_ALIGNER(long double, 6);
|
Chris@16
|
32 BOOST_PYTHON_ALIGNER(void*, 7);
|
Chris@16
|
33 BOOST_PYTHON_ALIGNER(function_ptr, 8);
|
Chris@16
|
34 BOOST_PYTHON_ALIGNER(member_ptr, 9);
|
Chris@16
|
35 BOOST_PYTHON_ALIGNER(member_function_ptr, 10);
|
Chris@16
|
36 char bytes[size];
|
Chris@16
|
37 };
|
Chris@16
|
38
|
Chris@16
|
39 # undef BOOST_PYTHON_ALIGNER
|
Chris@16
|
40
|
Chris@16
|
41 // Compute the size of T's referent. We wouldn't need this at all,
|
Chris@16
|
42 // but sizeof() is broken in CodeWarriors <= 8.0
|
Chris@16
|
43 template <class T> struct referent_size;
|
Chris@16
|
44
|
Chris@16
|
45 # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
Chris@16
|
46
|
Chris@16
|
47 template <class T>
|
Chris@16
|
48 struct referent_size<T&>
|
Chris@16
|
49 {
|
Chris@16
|
50 BOOST_STATIC_CONSTANT(
|
Chris@16
|
51 std::size_t, value = sizeof(T));
|
Chris@16
|
52 };
|
Chris@16
|
53
|
Chris@16
|
54 # else
|
Chris@16
|
55
|
Chris@16
|
56 template <class T> struct referent_size
|
Chris@16
|
57 {
|
Chris@16
|
58 static T f();
|
Chris@16
|
59 BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(f()));
|
Chris@16
|
60 };
|
Chris@16
|
61
|
Chris@16
|
62 # endif
|
Chris@16
|
63
|
Chris@16
|
64 // A metafunction returning a POD type which can store U, where T ==
|
Chris@16
|
65 // U&. If T is not a reference type, returns a POD which can store T.
|
Chris@16
|
66 template <class T>
|
Chris@16
|
67 struct referent_storage
|
Chris@16
|
68 {
|
Chris@16
|
69 typedef aligned_storage<
|
Chris@16
|
70 ::boost::python::detail::referent_size<T>::value
|
Chris@16
|
71 > type;
|
Chris@16
|
72 };
|
Chris@16
|
73
|
Chris@16
|
74 }}} // namespace boost::python::detail
|
Chris@16
|
75
|
Chris@16
|
76 #endif // REFERENT_STORAGE_DWA200278_HPP
|