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