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

Revision 857, 2.5 KB checked in by igarcia, 19 years ago (diff)
Line 
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
15namespace boost { namespace python { namespace detail {
16
17template<class T> class borrowed
18{
19    typedef T type;
20};
21
22# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
23template<typename T>
24struct is_borrowed_ptr
25{
26    BOOST_STATIC_CONSTANT(bool, value = false);
27};
28
29#  if !defined(__MWERKS__) || __MWERKS__ > 0x3000
30template<typename T>
31struct is_borrowed_ptr<borrowed<T>*>
32{
33    BOOST_STATIC_CONSTANT(bool, value = true);
34};
35
36template<typename T>
37struct is_borrowed_ptr<borrowed<T> const*>
38{
39    BOOST_STATIC_CONSTANT(bool, value = true);
40};
41
42template<typename T>
43struct is_borrowed_ptr<borrowed<T> volatile*>
44{
45    BOOST_STATIC_CONSTANT(bool, value = true);
46};
47
48template<typename T>
49struct is_borrowed_ptr<borrowed<T> const volatile*>
50{
51    BOOST_STATIC_CONSTANT(bool, value = true);
52};
53#  else
54template<typename T>
55struct is_borrowed
56{
57    BOOST_STATIC_CONSTANT(bool, value = false);
58};
59template<typename T>
60struct is_borrowed<borrowed<T> >
61{
62    BOOST_STATIC_CONSTANT(bool, value = true);
63};
64template<typename T>
65struct is_borrowed_ptr<T*>
66    : is_borrowed<typename remove_cv<T>::type>
67{
68};
69#  endif
70
71# else // no partial specialization
72
73typedef char (&yes_borrowed_ptr_t)[1];
74typedef char (&no_borrowed_ptr_t)[2];
75
76no_borrowed_ptr_t is_borrowed_ptr_test(...);
77
78template <class T>
79typename mpl::if_c<
80    is_pointer<T>::value
81    , T
82    , int
83    >::type
84is_borrowed_ptr_test1(boost::type<T>);
85
86template<typename T>
87yes_borrowed_ptr_t is_borrowed_ptr_test(borrowed<T> const volatile*);
88
89template<typename T>
90class 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
103template <class T>
104inline 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
Note: See TracBrowser for help on using the repository browser.