Chris@16
|
1 #ifndef PTR_DWA20020601_HPP
|
Chris@16
|
2 # define PTR_DWA20020601_HPP
|
Chris@16
|
3
|
Chris@16
|
4 # include <boost/python/detail/prefix.hpp>
|
Chris@16
|
5 // Copyright David Abrahams 2002.
|
Chris@16
|
6 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
7 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
8 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 //
|
Chris@16
|
10 // Based on boost/ref.hpp, thus:
|
Chris@16
|
11 // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
Chris@16
|
12 // Copyright (C) 2001 Peter Dimov
|
Chris@16
|
13
|
Chris@16
|
14 # if _MSC_VER+0 >= 1020
|
Chris@16
|
15 # pragma once
|
Chris@16
|
16 # endif
|
Chris@16
|
17
|
Chris@16
|
18 # include <boost/config.hpp>
|
Chris@16
|
19 # include <boost/mpl/bool.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 namespace boost { namespace python {
|
Chris@16
|
22
|
Chris@16
|
23 template<class Ptr> class pointer_wrapper
|
Chris@16
|
24 {
|
Chris@16
|
25 public:
|
Chris@16
|
26 typedef Ptr type;
|
Chris@16
|
27
|
Chris@16
|
28 explicit pointer_wrapper(Ptr x): p_(x) {}
|
Chris@16
|
29 operator Ptr() const { return p_; }
|
Chris@16
|
30 Ptr get() const { return p_; }
|
Chris@16
|
31 private:
|
Chris@16
|
32 Ptr p_;
|
Chris@16
|
33 };
|
Chris@16
|
34
|
Chris@16
|
35 template<class T>
|
Chris@16
|
36 inline pointer_wrapper<T> ptr(T t)
|
Chris@16
|
37 {
|
Chris@16
|
38 return pointer_wrapper<T>(t);
|
Chris@16
|
39 }
|
Chris@16
|
40
|
Chris@16
|
41 # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
Chris@16
|
42 template<typename T>
|
Chris@16
|
43 class is_pointer_wrapper
|
Chris@16
|
44 : public mpl::false_
|
Chris@16
|
45 {
|
Chris@16
|
46 };
|
Chris@16
|
47
|
Chris@16
|
48 template<typename T>
|
Chris@16
|
49 class is_pointer_wrapper<pointer_wrapper<T> >
|
Chris@16
|
50 : public mpl::true_
|
Chris@16
|
51 {
|
Chris@16
|
52 };
|
Chris@16
|
53
|
Chris@16
|
54 template<typename T>
|
Chris@16
|
55 class unwrap_pointer
|
Chris@16
|
56 {
|
Chris@16
|
57 public:
|
Chris@16
|
58 typedef T type;
|
Chris@16
|
59 };
|
Chris@16
|
60
|
Chris@16
|
61 template<typename T>
|
Chris@16
|
62 class unwrap_pointer<pointer_wrapper<T> >
|
Chris@16
|
63 {
|
Chris@16
|
64 public:
|
Chris@16
|
65 typedef T type;
|
Chris@16
|
66 };
|
Chris@16
|
67 # else // no partial specialization
|
Chris@16
|
68
|
Chris@16
|
69 }} // namespace boost::python
|
Chris@16
|
70
|
Chris@16
|
71 #include <boost/type.hpp>
|
Chris@16
|
72
|
Chris@16
|
73 namespace boost { namespace python {
|
Chris@16
|
74
|
Chris@16
|
75 namespace detail
|
Chris@16
|
76 {
|
Chris@16
|
77 typedef char (&yes_pointer_wrapper_t)[1];
|
Chris@16
|
78 typedef char (&no_pointer_wrapper_t)[2];
|
Chris@16
|
79
|
Chris@16
|
80 no_pointer_wrapper_t is_pointer_wrapper_test(...);
|
Chris@16
|
81
|
Chris@16
|
82 template<typename T>
|
Chris@16
|
83 yes_pointer_wrapper_t is_pointer_wrapper_test(boost::type< pointer_wrapper<T> >);
|
Chris@16
|
84
|
Chris@16
|
85 template<bool wrapped>
|
Chris@16
|
86 struct pointer_unwrapper
|
Chris@16
|
87 {
|
Chris@16
|
88 template <class T>
|
Chris@16
|
89 struct apply
|
Chris@16
|
90 {
|
Chris@16
|
91 typedef T type;
|
Chris@16
|
92 };
|
Chris@16
|
93 };
|
Chris@16
|
94
|
Chris@16
|
95 template<>
|
Chris@16
|
96 struct pointer_unwrapper<true>
|
Chris@16
|
97 {
|
Chris@16
|
98 template <class T>
|
Chris@16
|
99 struct apply
|
Chris@16
|
100 {
|
Chris@16
|
101 typedef typename T::type type;
|
Chris@16
|
102 };
|
Chris@16
|
103 };
|
Chris@16
|
104 }
|
Chris@16
|
105
|
Chris@16
|
106 template<typename T>
|
Chris@16
|
107 class is_pointer_wrapper
|
Chris@16
|
108 {
|
Chris@16
|
109 public:
|
Chris@16
|
110 BOOST_STATIC_CONSTANT(
|
Chris@16
|
111 bool, value = (
|
Chris@16
|
112 sizeof(detail::is_pointer_wrapper_test(boost::type<T>()))
|
Chris@16
|
113 == sizeof(detail::yes_pointer_wrapper_t)));
|
Chris@16
|
114 typedef mpl::bool_<value> type;
|
Chris@16
|
115 };
|
Chris@16
|
116
|
Chris@16
|
117 template <typename T>
|
Chris@16
|
118 class unwrap_pointer
|
Chris@16
|
119 : public detail::pointer_unwrapper<
|
Chris@16
|
120 is_pointer_wrapper<T>::value
|
Chris@16
|
121 >::template apply<T>
|
Chris@16
|
122 {};
|
Chris@16
|
123
|
Chris@16
|
124 # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
Chris@16
|
125
|
Chris@16
|
126 }} // namespace boost::python
|
Chris@16
|
127
|
Chris@16
|
128 #endif // #ifndef PTR_DWA20020601_HPP
|