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/python/detail/type_traits.hpp>
12 # include <boost/python/tag.hpp>
13
14 namespace boost { namespace python { namespace detail {
15
16 template<class T> class borrowed
17 {
18 typedef T type;
19 };
20
21 template<typename T>
22 struct is_borrowed_ptr
23 {
24 BOOST_STATIC_CONSTANT(bool, value = false);
25 };
26
27 # if !defined(__MWERKS__) || __MWERKS__ > 0x3000
28 template<typename T>
29 struct is_borrowed_ptr<borrowed<T>*>
30 {
31 BOOST_STATIC_CONSTANT(bool, value = true);
32 };
33
34 template<typename T>
35 struct is_borrowed_ptr<borrowed<T> const*>
36 {
37 BOOST_STATIC_CONSTANT(bool, value = true);
38 };
39
40 template<typename T>
41 struct is_borrowed_ptr<borrowed<T> volatile*>
42 {
43 BOOST_STATIC_CONSTANT(bool, value = true);
44 };
45
46 template<typename T>
47 struct is_borrowed_ptr<borrowed<T> const volatile*>
48 {
49 BOOST_STATIC_CONSTANT(bool, value = true);
50 };
51 # else
52 template<typename T>
53 struct is_borrowed
54 {
55 BOOST_STATIC_CONSTANT(bool, value = false);
56 };
57 template<typename T>
58 struct is_borrowed<borrowed<T> >
59 {
60 BOOST_STATIC_CONSTANT(bool, value = true);
61 };
62 template<typename T>
63 struct is_borrowed_ptr<T*>
64 : is_borrowed<typename remove_cv<T>::type>
65 {
66 };
67 # endif
68
69
70 }
71
72 template <class T>
get_managed_object(detail::borrowed<T> const volatile * p,tag_t)73 inline T* get_managed_object(detail::borrowed<T> const volatile* p, tag_t)
74 {
75 return (T*)p;
76 }
77
78 }} // namespace boost::python::detail
79
80 #endif // #ifndef BORROWED_PTR_DWA20020601_HPP
81