sl@0
|
1 |
// Copyright David Abrahams 2002.
|
sl@0
|
2 |
// Distributed under the Boost Software License, Version 1.0. (See
|
sl@0
|
3 |
// accompanying file LICENSE_1_0.txt or copy at
|
sl@0
|
4 |
// http://www.boost.org/LICENSE_1_0.txt)
|
sl@0
|
5 |
#ifndef DESTROY_DWA2002221_HPP
|
sl@0
|
6 |
# define DESTROY_DWA2002221_HPP
|
sl@0
|
7 |
|
sl@0
|
8 |
# include <boost/type_traits/is_array.hpp>
|
sl@0
|
9 |
# include <boost/detail/workaround.hpp>
|
sl@0
|
10 |
# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
|
sl@0
|
11 |
# include <boost/type_traits/is_enum.hpp>
|
sl@0
|
12 |
# endif
|
sl@0
|
13 |
namespace boost { namespace python { namespace detail {
|
sl@0
|
14 |
|
sl@0
|
15 |
template <
|
sl@0
|
16 |
bool array
|
sl@0
|
17 |
# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
|
sl@0
|
18 |
, bool enum_ // vc7 has a problem destroying enums
|
sl@0
|
19 |
# endif
|
sl@0
|
20 |
> struct value_destroyer;
|
sl@0
|
21 |
|
sl@0
|
22 |
template <>
|
sl@0
|
23 |
struct value_destroyer<
|
sl@0
|
24 |
false
|
sl@0
|
25 |
# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
|
sl@0
|
26 |
, false
|
sl@0
|
27 |
# endif
|
sl@0
|
28 |
>
|
sl@0
|
29 |
{
|
sl@0
|
30 |
template <class T>
|
sl@0
|
31 |
static void execute(T const volatile* p)
|
sl@0
|
32 |
{
|
sl@0
|
33 |
p->T::~T();
|
sl@0
|
34 |
}
|
sl@0
|
35 |
};
|
sl@0
|
36 |
|
sl@0
|
37 |
template <>
|
sl@0
|
38 |
struct value_destroyer<
|
sl@0
|
39 |
true
|
sl@0
|
40 |
# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
|
sl@0
|
41 |
, false
|
sl@0
|
42 |
# endif
|
sl@0
|
43 |
>
|
sl@0
|
44 |
{
|
sl@0
|
45 |
template <class A, class T>
|
sl@0
|
46 |
static void execute(A*, T const volatile* const first)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
for (T const volatile* p = first; p != first + sizeof(A)/sizeof(T); ++p)
|
sl@0
|
49 |
{
|
sl@0
|
50 |
value_destroyer<
|
sl@0
|
51 |
boost::is_array<T>::value
|
sl@0
|
52 |
# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
|
sl@0
|
53 |
, boost::is_enum<T>::value
|
sl@0
|
54 |
# endif
|
sl@0
|
55 |
>::execute(p);
|
sl@0
|
56 |
}
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
template <class T>
|
sl@0
|
60 |
static void execute(T const volatile* p)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
execute(p, *p);
|
sl@0
|
63 |
}
|
sl@0
|
64 |
};
|
sl@0
|
65 |
|
sl@0
|
66 |
# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
|
sl@0
|
67 |
template <>
|
sl@0
|
68 |
struct value_destroyer<true,true>
|
sl@0
|
69 |
{
|
sl@0
|
70 |
template <class T>
|
sl@0
|
71 |
static void execute(T const volatile*)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
}
|
sl@0
|
74 |
};
|
sl@0
|
75 |
|
sl@0
|
76 |
template <>
|
sl@0
|
77 |
struct value_destroyer<false,true>
|
sl@0
|
78 |
{
|
sl@0
|
79 |
template <class T>
|
sl@0
|
80 |
static void execute(T const volatile*)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
}
|
sl@0
|
83 |
};
|
sl@0
|
84 |
# endif
|
sl@0
|
85 |
template <class T>
|
sl@0
|
86 |
inline void destroy_referent_impl(void* p, T& (*)())
|
sl@0
|
87 |
{
|
sl@0
|
88 |
// note: cv-qualification needed for MSVC6
|
sl@0
|
89 |
// must come *before* T for metrowerks
|
sl@0
|
90 |
value_destroyer<
|
sl@0
|
91 |
(boost::is_array<T>::value)
|
sl@0
|
92 |
# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
|
sl@0
|
93 |
, (boost::is_enum<T>::value)
|
sl@0
|
94 |
# endif
|
sl@0
|
95 |
>::execute((const volatile T*)p);
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
template <class T>
|
sl@0
|
99 |
inline void destroy_referent(void* p, T(*)() = 0)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
destroy_referent_impl(p, (T(*)())0);
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
}}} // namespace boost::python::detail
|
sl@0
|
105 |
|
sl@0
|
106 |
#endif // DESTROY_DWA2002221_HPP
|