1 | #ifndef BORROWED_PTR_DWA20020601_HPP
|
---|
2 | # define BORROWED_PTR_DWA20020601_HPP
|
---|
3 | // Copyright David Abrahams 2002.
|
---|
4 | // Distributed under the Boost Software License, Version 1.0. (See
|
---|
5 | // accompanying file LICENSE_1_0.txt or copy at
|
---|
6 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
7 |
|
---|
8 | # include <boost/config.hpp>
|
---|
9 | # include <boost/type.hpp>
|
---|
10 | # include <boost/mpl/if.hpp>
|
---|
11 | # include <boost/type_traits/object_traits.hpp>
|
---|
12 | # include <boost/type_traits/cv_traits.hpp>
|
---|
13 | # include <boost/python/tag.hpp>
|
---|
14 |
|
---|
15 | namespace boost { namespace python { namespace detail {
|
---|
16 |
|
---|
17 | template<class T> class borrowed
|
---|
18 | {
|
---|
19 | typedef T type;
|
---|
20 | };
|
---|
21 |
|
---|
22 | # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
23 | template<typename T>
|
---|
24 | struct is_borrowed_ptr
|
---|
25 | {
|
---|
26 | BOOST_STATIC_CONSTANT(bool, value = false);
|
---|
27 | };
|
---|
28 |
|
---|
29 | # if !defined(__MWERKS__) || __MWERKS__ > 0x3000
|
---|
30 | template<typename T>
|
---|
31 | struct is_borrowed_ptr<borrowed<T>*>
|
---|
32 | {
|
---|
33 | BOOST_STATIC_CONSTANT(bool, value = true);
|
---|
34 | };
|
---|
35 |
|
---|
36 | template<typename T>
|
---|
37 | struct is_borrowed_ptr<borrowed<T> const*>
|
---|
38 | {
|
---|
39 | BOOST_STATIC_CONSTANT(bool, value = true);
|
---|
40 | };
|
---|
41 |
|
---|
42 | template<typename T>
|
---|
43 | struct is_borrowed_ptr<borrowed<T> volatile*>
|
---|
44 | {
|
---|
45 | BOOST_STATIC_CONSTANT(bool, value = true);
|
---|
46 | };
|
---|
47 |
|
---|
48 | template<typename T>
|
---|
49 | struct is_borrowed_ptr<borrowed<T> const volatile*>
|
---|
50 | {
|
---|
51 | BOOST_STATIC_CONSTANT(bool, value = true);
|
---|
52 | };
|
---|
53 | # else
|
---|
54 | template<typename T>
|
---|
55 | struct is_borrowed
|
---|
56 | {
|
---|
57 | BOOST_STATIC_CONSTANT(bool, value = false);
|
---|
58 | };
|
---|
59 | template<typename T>
|
---|
60 | struct is_borrowed<borrowed<T> >
|
---|
61 | {
|
---|
62 | BOOST_STATIC_CONSTANT(bool, value = true);
|
---|
63 | };
|
---|
64 | template<typename T>
|
---|
65 | struct is_borrowed_ptr<T*>
|
---|
66 | : is_borrowed<typename remove_cv<T>::type>
|
---|
67 | {
|
---|
68 | };
|
---|
69 | # endif
|
---|
70 |
|
---|
71 | # else // no partial specialization
|
---|
72 |
|
---|
73 | typedef char (&yes_borrowed_ptr_t)[1];
|
---|
74 | typedef char (&no_borrowed_ptr_t)[2];
|
---|
75 |
|
---|
76 | no_borrowed_ptr_t is_borrowed_ptr_test(...);
|
---|
77 |
|
---|
78 | template <class T>
|
---|
79 | typename mpl::if_c<
|
---|
80 | is_pointer<T>::value
|
---|
81 | , T
|
---|
82 | , int
|
---|
83 | >::type
|
---|
84 | is_borrowed_ptr_test1(boost::type<T>);
|
---|
85 |
|
---|
86 | template<typename T>
|
---|
87 | yes_borrowed_ptr_t is_borrowed_ptr_test(borrowed<T> const volatile*);
|
---|
88 |
|
---|
89 | template<typename T>
|
---|
90 | class is_borrowed_ptr
|
---|
91 | {
|
---|
92 | public:
|
---|
93 | BOOST_STATIC_CONSTANT(
|
---|
94 | bool, value = (
|
---|
95 | sizeof(detail::is_borrowed_ptr_test(is_borrowed_ptr_test1(boost::type<T>())))
|
---|
96 | == sizeof(detail::yes_borrowed_ptr_t)));
|
---|
97 | };
|
---|
98 |
|
---|
99 | # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
---|
100 |
|
---|
101 | }
|
---|
102 |
|
---|
103 | template <class T>
|
---|
104 | inline T* get_managed_object(detail::borrowed<T> const volatile* p, tag_t)
|
---|
105 | {
|
---|
106 | return (T*)p;
|
---|
107 | }
|
---|
108 |
|
---|
109 | }} // namespace boost::python::detail
|
---|
110 |
|
---|
111 | #endif // #ifndef BORROWED_PTR_DWA20020601_HPP
|
---|