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