source: NonGTP/Boost/boost/python/detail/destroy.hpp @ 857

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